Module: xenomai-forge
Branch: next
Commit: 2550a70929c16b1b7905a5fc221ca5868320a664
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2550a70929c16b1b7905a5fc221ca5868320a664

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Sep  9 17:38:34 2014 +0200

cobalt/rtdm: allow omitting open/socket/close handlers

Although unusual, omitting open/socket/close handlers in drivers is
perfectly legitimate, and nothing justifies to keep them required.

---

 kernel/cobalt/rtdm/core.c   |   37 ++++++++++++++++++-------------------
 kernel/cobalt/rtdm/device.c |   16 ----------------
 2 files changed, 18 insertions(+), 35 deletions(-)

diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 18cf0c6..f84d8b0 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -56,7 +56,8 @@ static void cleanup_instance(struct rtdm_device *device,
 void __rt_dev_close(struct rtdm_fd *fd)
 {
        struct rtdm_dev_context *context = rtdm_fd_to_context(fd);
-       context->reserved.close(fd);
+       if (context->reserved.close)
+               context->reserved.close(fd);
        cleanup_instance(context->device, context);
 }
 
@@ -168,13 +169,13 @@ int __rt_dev_open(struct xnsys_ppd *p, int ufd, const 
char *path, int oflag)
 
        trace_cobalt_fd_open(current, &context->fd, ufd, oflag);
 
-       ret = device->ops.open(&context->fd, oflag);
-
-       if (!XENO_ASSERT(COBALT, !spltest()))
-               splnone();
-
-       if (ret < 0)
-               goto cleanup_out;
+       if (device->ops.open) {
+               ret = device->ops.open(&context->fd, oflag);
+               if (!XENO_ASSERT(COBALT, !spltest()))
+                       splnone();
+               if (ret < 0)
+                       goto cleanup_out;
+       }
 
        trace_cobalt_fd_created(&context->fd, ufd);
 
@@ -195,9 +196,8 @@ int __rt_dev_socket(struct xnsys_ppd *p, int ufd, int 
protocol_family,
        int ret;
 
        device = __rtdm_get_protocol_device(protocol_family, socket_type);
-       ret = -EAFNOSUPPORT;
-       if (!device)
-               goto err_out;
+       if (device == NULL)
+               return -EAFNOSUPPORT;
 
        ret = create_instance(p, ufd, device, &context);
        if (ret < 0)
@@ -206,13 +206,13 @@ int __rt_dev_socket(struct xnsys_ppd *p, int ufd, int 
protocol_family,
 
        trace_cobalt_fd_socket(current, &context->fd, ufd, protocol_family);
 
-       ret = device->ops.socket(&context->fd, protocol);
-
-       if (!XENO_ASSERT(COBALT, !spltest()))
-               splnone();
-
-       if (unlikely(ret < 0))
-               goto cleanup_out;
+       if (device->ops.socket) {
+               ret = device->ops.socket(&context->fd, protocol);
+               if (!XENO_ASSERT(COBALT, !spltest()))
+                       splnone();
+               if (ret < 0)
+                       goto cleanup_out;
+       }
 
        trace_cobalt_fd_created(&context->fd, ufd);
 
@@ -221,7 +221,6 @@ int __rt_dev_socket(struct xnsys_ppd *p, int ufd, int 
protocol_family,
 cleanup_out:
        cleanup_instance(device, context);
 
-err_out:
        return ret;
 }
 EXPORT_SYMBOL_GPL(__rt_dev_socket);
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 14e4492..d513685 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -195,20 +195,10 @@ int rtdm_dev_register(struct rtdm_device *device)
 
        switch (device->device_flags & RTDM_DEVICE_TYPE_MASK) {
        case RTDM_NAMED_DEVICE:
-               /* Sanity check: any open handler? */
-               if (device->ops.open == NULL) {
-                       printk(XENO_ERR "missing open handler for RTDM 
device\n");
-                       return -EINVAL;
-               }
                device->ops.socket = (typeof(device->ops.socket))enosys;
                break;
 
        case RTDM_PROTOCOL_DEVICE:
-               /* Sanity check: any socket handler? */
-               if (device->ops.socket == NULL) {
-                       printk(XENO_ERR "missing socket handler for RTDM 
device\n");
-                       return -EINVAL;
-               }
                device->ops.open = (typeof(device->ops.open))enosys;
                break;
 
@@ -216,12 +206,6 @@ int rtdm_dev_register(struct rtdm_device *device)
                return -EINVAL;
        }
 
-       /* Sanity check: driver-defined close handler?
-        * (Always required for forced cleanup) */
-       if (device->ops.close == NULL) {
-               printk(XENO_ERR "missing close handler for RTDM device\n");
-               return -EINVAL;
-       }
        device->reserved.close = device->ops.close;
        device->ops.close = __rt_dev_close;
        atomic_set(&device->reserved.refcount, 0);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to