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

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat May 17 20:33:30 2014 +0200

drivers/rtcan: adapt to RTDM API changes

---

 kernel/drivers/can/rtcan_module.c  |   29 +++---
 kernel/drivers/can/rtcan_raw.c     |  199 +++++++++++++++++-------------------
 kernel/drivers/can/rtcan_raw.h     |    3 +-
 kernel/drivers/can/rtcan_raw_dev.c |   19 ++--
 kernel/drivers/can/rtcan_socket.c  |    8 +-
 kernel/drivers/can/rtcan_socket.h  |   14 +--
 6 files changed, 126 insertions(+), 146 deletions(-)

diff --git a/kernel/drivers/can/rtcan_module.c 
b/kernel/drivers/can/rtcan_module.c
index 4e5b837..6c57515 100644
--- a/kernel/drivers/can/rtcan_module.c
+++ b/kernel/drivers/can/rtcan_module.c
@@ -169,7 +169,7 @@ static const struct file_operations rtcan_proc_devices_ops 
= {
 static int rtcan_read_proc_sockets(struct seq_file *p, void *data)
 {
     struct rtcan_socket *sock;
-    struct rtdm_dev_context *context;
+    struct rtdm_fd *fd;
     struct rtcan_device *dev;
     char name[IFNAMSIZ] = "not-bound";
     char rx_timeout[20], tx_timeout[20];
@@ -179,16 +179,16 @@ static int rtcan_read_proc_sockets(struct seq_file *p, 
void *data)
     if (down_interruptible(&rtcan_devices_nrt_lock))
        return -ERESTARTSYS;
 
-    /* fd Name___________ Filter ErrMask RX_Timeout TX_Timeout RX_BufFull TX_Lo
-     *  0 rtcan0               1 0x00010 1234567890 1234567890 1234567890 12345
+    /* Name___________ Filter ErrMask RX_Timeout TX_Timeout RX_BufFull TX_Lo
+     * rtcan0               1 0x00010 1234567890 1234567890 1234567890 12345
      */
-    seq_printf(p, "fd Name___________ Filter ErrMask RX_Timeout_ns "
+    seq_printf(p, "Name___________ Filter ErrMask RX_Timeout_ns "
                  "TX_Timeout_ns RX_BufFull TX_Lo\n");
 
     rtdm_lock_get_irqsave(&rtcan_recv_list_lock, lock_ctx);
 
     list_for_each_entry(sock, &rtcan_socket_list, socket_list) {
-       context = rtcan_socket_context(sock);
+       fd = rtcan_socket_to_fd(sock);
        if (rtcan_sock_is_bound(sock)) {
            ifindex = atomic_read(&sock->ifindex);
            if (ifindex) {
@@ -204,8 +204,8 @@ static int rtcan_read_proc_sockets(struct seq_file *p, void 
*data)
                               tx_timeout, sizeof(tx_timeout));
        rtcan_get_timeout_name(sock->rx_timeout,
                               rx_timeout, sizeof(rx_timeout));
-       seq_printf(p, "%2d %-15s %6d 0x%05x %13s %13s %10d %5d\n",
-                  context->fd, name, sock->flistlen, sock->err_mask,
+       seq_printf(p, "%-15s %6d 0x%05x %13s %13s %10d %5d\n",
+                  name, sock->flistlen, sock->err_mask,
                   rx_timeout, tx_timeout, sock->rx_buf_full,
                   rtcan_loopback_enabled(sock));
     }
@@ -286,23 +286,22 @@ static int rtcan_read_proc_filter(struct seq_file *p, 
void *data)
 {
     struct rtcan_device *dev = p->private;
     struct rtcan_recv *recv_listener = dev->recv_list;
-    struct rtdm_dev_context *context;
+    struct rtdm_fd *fd;
     rtdm_lockctx_t lock_ctx;
 
-    /*  fd __CAN_ID__ _CAN_Mask_ Inv MatchCount
-     *   3 0x12345678 0x12345678  no 1234567890
+    /*  __CAN_ID__ _CAN_Mask_ Inv MatchCount
+     *  0x12345678 0x12345678  no 1234567890
      */
 
-    seq_printf(p, "fd __CAN_ID__ _CAN_Mask_ Inv MatchCount\n");
+    seq_printf(p, "__CAN_ID__ _CAN_Mask_ Inv MatchCount\n");
 
     rtdm_lock_get_irqsave(&rtcan_recv_list_lock, lock_ctx);
 
     /* Loop over the reception list of the device */
     while (recv_listener != NULL) {
-       context = rtcan_socket_context(recv_listener->sock);
+       fd = rtcan_socket_to_fd(recv_listener->sock);
 
-       seq_printf(p, "%2d 0x%08x 0x%08x %s %10d\n",
-                  context->fd,
+       seq_printf(p, "0x%08x 0x%08x %s %10d\n",
                   recv_listener->can_filter.can_id,
                   recv_listener->can_filter.can_mask & ~CAN_INV_FILTER,
                   (recv_listener->can_filter.can_mask & CAN_INV_FILTER) ?
@@ -394,7 +393,7 @@ static int rtcan_proc_register(void)
     }
 
     proc_create("devices", S_IFREG | S_IRUGO | S_IWUSR, rtcan_proc_root,
-               &rtcan_proc_devices_ops);
+               &rtcan_proc_devices_ops);
     proc_create("version", S_IFREG | S_IRUGO | S_IWUSR, rtcan_proc_root,
                &rtcan_proc_version_ops);
     proc_create("sockets", S_IFREG | S_IRUGO | S_IWUSR, rtcan_proc_root,
diff --git a/kernel/drivers/can/rtcan_raw.c b/kernel/drivers/can/rtcan_raw.c
index d3cb88a..3864d0f 100644
--- a/kernel/drivers/can/rtcan_raw.c
+++ b/kernel/drivers/can/rtcan_raw.c
@@ -52,7 +52,7 @@
  * Set if socket wants to receive a high precision timestamp together with
  * CAN frames
  */
-#define RTCAN_GET_TIMESTAMP         RTDM_USER_CONTEXT_FLAG
+#define RTCAN_GET_TIMESTAMP         0
 
 
 MODULE_AUTHOR("RT-Socket-CAN Development Team");
@@ -80,12 +80,17 @@ static void rtcan_rcv_deliver(struct rtcan_recv 
*recv_listener,
     int size_free;
     size_t cpy_size, first_part_size;
     struct rtcan_rb_frame *frame = &skb->rb_frame;
-    struct rtcan_socket *sock = recv_listener->sock;
-    struct rtdm_dev_context *context = rtcan_socket_context(sock);
+    struct rtdm_fd *fd = rtdm_private_to_fd(recv_listener->sock);
+    struct rtcan_socket *sock;
+
+    if (rtdm_fd_lock(fd) < 0)
+       return;
+
+    sock = recv_listener->sock;
 
     cpy_size = skb->rb_frame_size;
     /* Check if socket wants to receive a timestamp */
-    if (test_bit(RTCAN_GET_TIMESTAMP, &context->context_flags)) {
+    if (test_bit(RTCAN_GET_TIMESTAMP, &sock->flags)) {
        cpy_size += RTCAN_TIMESTAMP_SIZE;
        frame->can_dlc |= RTCAN_HAS_TIMESTAMP;
     } else
@@ -122,9 +127,11 @@ static void rtcan_rcv_deliver(struct rtcan_recv 
*recv_listener,
     } else {
        /* Overflow of socket's ring buffer! */
        sock->rx_buf_full++;
-       RTCAN_RTDM_DBG("%s: socket buffer overflow (fd=%d), message 
discarded\n",
-                      rtcan_proto_raw_dev.driver_name, context->fd);
+       RTCAN_RTDM_DBG("%s: socket buffer overflow, message discarded\n",
+                      rtcan_proto_raw_dev.driver_name);
     }
+
+    rtdm_fd_unlock(fd);
 }
 
 
@@ -208,14 +215,13 @@ EXPORT_SYMBOL_GPL(rtcan_loopback);
 #endif /* CONFIG_XENO_DRIVERS_CAN_LOOPBACK */
 
 
-int rtcan_raw_socket(struct rtdm_dev_context *context,
-                    rtdm_user_info_t *user_info, int protocol)
+int rtcan_raw_socket(struct rtdm_fd *fd, int protocol)
 {
     /* Only protocol CAN_RAW is supported */
     if (protocol != CAN_RAW && protocol != 0)
        return -EPROTONOSUPPORT;
 
-    rtcan_socket_init(context);
+    rtcan_socket_init(fd);
 
     return 0;
 }
@@ -232,11 +238,9 @@ static inline void rtcan_raw_unbind(struct rtcan_socket 
*sock)
 }
 
 
-static int rtcan_raw_close(struct rtdm_dev_context *context,
-                          rtdm_user_info_t *user_info)
+static void rtcan_raw_close(struct rtdm_fd *fd)
 {
-    struct rtcan_socket *sock =
-       (struct rtcan_socket *)&context->dev_private;
+    struct rtcan_socket *sock = rtdm_fd_to_private(fd);
     rtdm_lockctx_t lock_ctx;
 
     /* Get lock for reception lists */
@@ -249,17 +253,14 @@ static int rtcan_raw_close(struct rtdm_dev_context 
*context,
     rtdm_lock_put_irqrestore(&rtcan_recv_list_lock, lock_ctx);
 
 
-    rtcan_socket_cleanup(context);
-
-    return 0;
+    rtcan_socket_cleanup(fd);
 }
 
 
-int rtcan_raw_bind(struct rtdm_dev_context *context,
+int rtcan_raw_bind(struct rtdm_fd *fd,
                   struct sockaddr_can *scan)
 {
-    struct rtcan_socket *sock =
-       (struct rtcan_socket *)&context->dev_private;
+    struct rtcan_socket *sock = rtdm_fd_to_private(fd);
     rtdm_lockctx_t lock_ctx;
     int ret = 0;
 
@@ -274,12 +275,6 @@ int rtcan_raw_bind(struct rtdm_dev_context *context,
     /* Get lock for reception lists */
     rtdm_lock_get_irqsave(&rtcan_recv_list_lock, lock_ctx);
 
-    /* Test if socket is about to be closed */
-    if (unlikely(test_bit(RTDM_CLOSING, &context->context_flags))) {
-       ret = -EBADF;
-       goto out;
-    }
-
     if ((ret = rtcan_raw_check_filter(sock, scan->can_ifindex,
                                      sock->flist)))
        goto out;
@@ -297,11 +292,10 @@ int rtcan_raw_bind(struct rtdm_dev_context *context,
 }
 
 
-static int rtcan_raw_setsockopt(struct rtdm_dev_context *context,
-                               rtdm_user_info_t *user_info,
+static int rtcan_raw_setsockopt(struct rtdm_fd *fd,
                                struct _rtdm_setsockopt_args *so)
 {
-    struct rtcan_socket *sock = (struct rtcan_socket *)&context->dev_private;
+    struct rtcan_socket *sock = rtdm_fd_to_private(fd);
     struct rtcan_filter_list *flist;
     int ifindex = atomic_read(&sock->ifindex);
     rtdm_lockctx_t lock_ctx;
@@ -326,9 +320,9 @@ static int rtcan_raw_setsockopt(struct rtdm_dev_context 
*context,
            flist = (struct rtcan_filter_list *)rtdm_malloc(so->optlen + 
sizeof(int));
            if (flist == NULL)
                return -ENOMEM;
-           if (user_info) {
-               if (!rtdm_read_user_ok(user_info, so->optval, so->optlen) ||
-                   rtdm_copy_from_user(user_info, flist->flist,
+           if (rtdm_fd_is_user(fd)) {
+               if (!rtdm_read_user_ok(fd, so->optval, so->optlen) ||
+                   rtdm_copy_from_user(fd, flist->flist,
                                        so->optval, so->optlen)) {
                    rtdm_free(flist);
                    return -EFAULT;
@@ -369,9 +363,9 @@ static int rtcan_raw_setsockopt(struct rtdm_dev_context 
*context,
        if (so->optlen != sizeof(can_err_mask_t))
            return -EINVAL;
 
-       if (user_info) {
-           if (!rtdm_read_user_ok(user_info, so->optval, so->optlen) ||
-               rtdm_copy_from_user(user_info, &err_mask, so->optval, 
so->optlen))
+       if (rtdm_fd_is_user(fd)) {
+           if (!rtdm_read_user_ok(fd, so->optval, so->optlen) ||
+               rtdm_copy_from_user(fd, &err_mask, so->optval, so->optlen))
                return -EFAULT;
        } else
            memcpy(&err_mask, so->optval, so->optlen);
@@ -388,9 +382,9 @@ static int rtcan_raw_setsockopt(struct rtdm_dev_context 
*context,
        if (so->optlen != sizeof(int))
            return -EINVAL;
 
-       if (user_info) {
-           if (!rtdm_read_user_ok(user_info, so->optval, so->optlen) ||
-               rtdm_copy_from_user(user_info, &val, so->optval, so->optlen))
+       if (rtdm_fd_is_user(fd)) {
+           if (!rtdm_read_user_ok(fd, so->optval, so->optlen) ||
+               rtdm_copy_from_user(fd, &val, so->optval, so->optlen))
                return -EFAULT;
        } else
            memcpy(&val, so->optval, so->optlen);
@@ -411,8 +405,7 @@ static int rtcan_raw_setsockopt(struct rtdm_dev_context 
*context,
 }
 
 
-int rtcan_raw_ioctl(struct rtdm_dev_context *context,
-                   rtdm_user_info_t *user_info,
+int rtcan_raw_ioctl(struct rtdm_fd *fd,
                    unsigned int request, void *arg)
 {
     int ret = 0;
@@ -422,11 +415,11 @@ int rtcan_raw_ioctl(struct rtdm_dev_context *context,
        struct _rtdm_setsockaddr_args *setaddr, setaddr_buf;
        struct sockaddr_can *sockaddr, sockaddr_buf;
 
-       if (user_info) {
+       if (rtdm_fd_is_user(fd)) {
            /* Copy argument structure from userspace */
-           if (!rtdm_read_user_ok(user_info, arg,
+           if (!rtdm_read_user_ok(fd, arg,
                                   sizeof(struct _rtdm_setsockaddr_args)) ||
-               rtdm_copy_from_user(user_info, &setaddr_buf, arg,
+               rtdm_copy_from_user(fd, &setaddr_buf, arg,
                                    sizeof(struct _rtdm_setsockaddr_args)))
                return -EFAULT;
 
@@ -437,9 +430,9 @@ int rtcan_raw_ioctl(struct rtdm_dev_context *context,
                return -EINVAL;
 
            /* Copy argument structure from userspace */
-           if (!rtdm_read_user_ok(user_info, arg,
+           if (!rtdm_read_user_ok(fd, arg,
                                   sizeof(struct sockaddr_can)) ||
-               rtdm_copy_from_user(user_info, &sockaddr_buf, setaddr->addr,
+               rtdm_copy_from_user(fd, &sockaddr_buf, setaddr->addr,
                                    sizeof(struct sockaddr_can)))
                return -EFAULT;
            sockaddr = &sockaddr_buf;
@@ -449,7 +442,7 @@ int rtcan_raw_ioctl(struct rtdm_dev_context *context,
        }
 
        /* Now, all required data are in kernel space */
-       ret = rtcan_raw_bind(context, sockaddr);
+       ret = rtcan_raw_bind(fd, sockaddr);
 
        break;
     }
@@ -458,10 +451,10 @@ int rtcan_raw_ioctl(struct rtdm_dev_context *context,
        struct _rtdm_setsockopt_args *setopt;
        struct _rtdm_setsockopt_args setopt_buf;
 
-       if (user_info) {
-           if (!rtdm_read_user_ok(user_info, arg,
+       if (rtdm_fd_is_user(fd)) {
+           if (!rtdm_read_user_ok(fd, arg,
                                   sizeof(struct _rtdm_setsockopt_args)) ||
-               rtdm_copy_from_user(user_info, &setopt_buf, arg,
+               rtdm_copy_from_user(fd, &setopt_buf, arg,
                                    sizeof(struct _rtdm_setsockopt_args)))
                return -EFAULT;
 
@@ -469,33 +462,33 @@ int rtcan_raw_ioctl(struct rtdm_dev_context *context,
        } else
            setopt = (struct _rtdm_setsockopt_args *)arg;
 
-       return rtcan_raw_setsockopt(context, user_info, setopt);
+       return rtcan_raw_setsockopt(fd, setopt);
     }
 
     case RTCAN_RTIOC_TAKE_TIMESTAMP: {
+       struct rtcan_socket *sock = rtdm_fd_to_private(fd);
        long timestamp_switch = (long)arg;
 
        if (timestamp_switch == RTCAN_TAKE_TIMESTAMPS)
-           set_bit(RTCAN_GET_TIMESTAMP, &context->context_flags);
+           set_bit(RTCAN_GET_TIMESTAMP, &sock->flags);
        else
-           clear_bit(RTCAN_GET_TIMESTAMP, &context->context_flags);
+           clear_bit(RTCAN_GET_TIMESTAMP, &sock->flags);
        break;
     }
 
     case RTCAN_RTIOC_RCV_TIMEOUT:
     case RTCAN_RTIOC_SND_TIMEOUT: {
        /* Do some work these requests have in common. */
-       struct rtcan_socket *sock =
-           (struct rtcan_socket *)&context->dev_private;
+       struct rtcan_socket *sock = rtdm_fd_to_private(fd);
 
        nanosecs_rel_t *timeout = (nanosecs_rel_t *)arg;
        nanosecs_rel_t timeo_buf;
 
-       if (user_info) {
+       if (rtdm_fd_is_user(fd)) {
            /* Copy 64 bit timeout value from userspace */
-           if (!rtdm_read_user_ok(user_info, arg,
+           if (!rtdm_read_user_ok(fd, arg,
                                   sizeof(nanosecs_rel_t)) ||
-               rtdm_copy_from_user(user_info, &timeo_buf,
+               rtdm_copy_from_user(fd, &timeo_buf,
                                    arg, sizeof(nanosecs_rel_t)))
                return -EFAULT;
 
@@ -512,7 +505,7 @@ int rtcan_raw_ioctl(struct rtdm_dev_context *context,
     }
 
     default:
-       ret = rtcan_raw_ioctl_dev(context, user_info, request, arg);
+       ret = rtcan_raw_ioctl_dev(fd, request, arg);
        break;
     }
 
@@ -539,12 +532,10 @@ int rtcan_raw_ioctl(struct rtdm_dev_context *context,
     recv_buf_index = (recv_buf_index + len) & (RTCAN_RXBUF_SIZE - 1);
 
 
-ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context *context,
-                         rtdm_user_info_t *user_info,
+ssize_t rtcan_raw_recvmsg(struct rtdm_fd *fd,
                          struct msghdr *msg, int flags)
 {
-    struct rtcan_socket *sock =
-       (struct rtcan_socket *)&context->dev_private;
+    struct rtcan_socket *sock = rtdm_fd_to_private(fd);
     struct sockaddr_can scan;
     nanosecs_rel_t timeout;
     struct iovec *iov = (struct iovec *)msg->msg_iov;
@@ -574,8 +565,8 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context *context,
        if (msg->msg_namelen < sizeof(struct sockaddr_can))
            return -EINVAL;
 
-       if (user_info) {
-           if (!rtdm_rw_user_ok(user_info, msg->msg_name, msg->msg_namelen))
+       if (rtdm_fd_is_user(fd)) {
+           if (!rtdm_rw_user_ok(fd, msg->msg_name, msg->msg_namelen))
                return -EFAULT;
        }
 
@@ -588,11 +579,11 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context 
*context,
     if (msg->msg_iovlen != 1)
        return -EMSGSIZE;
 
-    if (user_info) {
+    if (rtdm_fd_is_user(fd)) {
        /* Copy IO vector from userspace */
-       if (!rtdm_rw_user_ok(user_info, msg->msg_iov,
+       if (!rtdm_rw_user_ok(fd, msg->msg_iov,
                             sizeof(struct iovec)) ||
-           rtdm_copy_from_user(user_info, &iov_buf, msg->msg_iov,
+           rtdm_copy_from_user(fd, &iov_buf, msg->msg_iov,
                                sizeof(struct iovec)))
            return -EFAULT;
 
@@ -604,8 +595,8 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context *context,
        return -EMSGSIZE;
 
     /* Check buffer if in user space */
-    if (user_info) {
-       if (!rtdm_rw_user_ok(user_info, iov->iov_base, iov->iov_len))
+    if (rtdm_fd_is_user(fd)) {
+       if (!rtdm_rw_user_ok(fd, iov->iov_base, iov->iov_len))
            return -EFAULT;
     }
 
@@ -613,8 +604,8 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context *context,
        if (msg->msg_controllen < sizeof(nanosecs_abs_t))
            return -EINVAL;
 
-       if (user_info) {
-           if (!rtdm_rw_user_ok(user_info, msg->msg_control,
+       if (rtdm_fd_is_user(fd)) {
+           if (!rtdm_rw_user_ok(fd, msg->msg_control,
                                 msg->msg_controllen))
                return -EFAULT;
        }
@@ -716,12 +707,12 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context 
*context,
 
     /* Last duty: Copy all back to the caller's buffers. */
 
-    if (user_info) {
+    if (rtdm_fd_is_user(fd)) {
        /* Copy to user space */
 
        /* Copy socket address */
        if (msg->msg_namelen) {
-           if (rtdm_copy_to_user(user_info, msg->msg_name, &scan,
+           if (rtdm_copy_to_user(fd, msg->msg_name, &scan,
                                  sizeof(struct sockaddr_can)))
                return -EFAULT;
 
@@ -729,21 +720,21 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context 
*context,
        }
 
        /* Copy CAN frame */
-       if (rtdm_copy_to_user(user_info, iov->iov_base, &frame,
+       if (rtdm_copy_to_user(fd, iov->iov_base, &frame,
                              sizeof(can_frame_t)))
            return -EFAULT;
        /* Adjust iovec in the common way */
        iov->iov_base += sizeof(can_frame_t);
        iov->iov_len -= sizeof(can_frame_t);
        /* ... and copy it, too. */
-       if (rtdm_copy_to_user(user_info, msg->msg_iov, iov,
+       if (rtdm_copy_to_user(fd, msg->msg_iov, iov,
                              sizeof(struct iovec)))
            return -EFAULT;
 
        /* Copy timestamp if existent and wanted */
        if (msg->msg_controllen) {
            if (can_dlc & RTCAN_HAS_TIMESTAMP) {
-               if (rtdm_copy_to_user(user_info, msg->msg_control,
+               if (rtdm_copy_to_user(fd, msg->msg_control,
                                      &timestamp, RTCAN_TIMESTAMP_SIZE))
                    return -EFAULT;
 
@@ -782,12 +773,10 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_dev_context 
*context,
 }
 
 
-ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context *context,
-                         rtdm_user_info_t *user_info,
+ssize_t rtcan_raw_sendmsg(struct rtdm_fd *fd,
                          const struct msghdr *msg, int flags)
 {
-    struct rtcan_socket *sock =
-       (struct rtcan_socket *)&context->dev_private;
+    struct rtcan_socket *sock = rtdm_fd_to_private(fd);
     struct sockaddr_can *scan = (struct sockaddr_can *)msg->msg_name;
     struct sockaddr_can scan_buf;
     struct iovec *iov = (struct iovec *)msg->msg_iov;
@@ -834,11 +823,11 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context 
*context,
        if (msg->msg_namelen < sizeof(struct sockaddr_can))
            return -EINVAL;
 
-       if (user_info) {
+       if (rtdm_fd_is_user(fd)) {
            /* Copy socket address from userspace */
-           if (!rtdm_read_user_ok(user_info, msg->msg_name,
+           if (!rtdm_read_user_ok(fd, msg->msg_name,
                                   sizeof(struct sockaddr_can)) ||
-               rtdm_copy_from_user(user_info, &scan_buf, msg->msg_name,
+               rtdm_copy_from_user(fd, &scan_buf, msg->msg_name,
                                    sizeof(struct sockaddr_can)))
                return -EFAULT;
 
@@ -852,11 +841,11 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context 
*context,
        ifindex = scan->can_ifindex;
     }
 
-    if (user_info) {
+    if (rtdm_fd_is_user(fd)) {
        /* Copy IO vector from userspace */
-       if (!rtdm_rw_user_ok(user_info, msg->msg_iov,
+       if (!rtdm_rw_user_ok(fd, msg->msg_iov,
                             sizeof(struct iovec)) ||
-           rtdm_copy_from_user(user_info, &iov_buf, msg->msg_iov,
+           rtdm_copy_from_user(fd, &iov_buf, msg->msg_iov,
                                sizeof(struct iovec)))
            return -EFAULT;
 
@@ -869,11 +858,11 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context 
*context,
 
     frame = (can_frame_t *)iov->iov_base;
 
-    if (user_info) {
+    if (rtdm_fd_is_user(fd)) {
        /* Copy CAN frame from userspace */
-       if (!rtdm_read_user_ok(user_info, iov->iov_base,
+       if (!rtdm_read_user_ok(fd, iov->iov_base,
                               sizeof(can_frame_t)) ||
-           rtdm_copy_from_user(user_info, &frame_buf, iov->iov_base,
+           rtdm_copy_from_user(fd, &frame_buf, iov->iov_base,
                                sizeof(can_frame_t)))
            return -EFAULT;
 
@@ -884,8 +873,8 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context *context,
     iov->iov_base += sizeof(can_frame_t);
     iov->iov_len -= sizeof(can_frame_t);
     /* ... and copy it back to userspace if necessary */
-    if (user_info) {
-       if (rtdm_copy_to_user(user_info, msg->msg_iov, iov,
+    if (rtdm_fd_is_user(fd)) {
+       if (rtdm_copy_to_user(fd, msg->msg_iov, iov,
                              sizeof(struct iovec)))
            return -EFAULT;
     }
@@ -915,25 +904,19 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_dev_context 
*context,
      * atomic. Finally, the task must be deregistered again (also atomic). */
     cobalt_atomic_enter(s);
 
-    if (likely(!test_bit(RTDM_CLOSING, &context->context_flags))) {
-
-           list_add(&tx_wait.tx_wait_list, &sock->tx_wait_head);
-
-           /* Try to pass the guard in order to access the controller */
-           ret = rtdm_sem_timeddown(&dev->tx_sem, timeout, NULL);
+    list_add(&tx_wait.tx_wait_list, &sock->tx_wait_head);
 
-           /* Only dequeue task again if socket isn't being closed i.e. if
-            * this task was not unblocked within the close() function. */
-           if (likely(tx_wait.tx_wait_list.next != LIST_POISON1))
-               /* Dequeue this task from the TX wait queue */
-               list_del(&tx_wait.tx_wait_list);
-           else
-               /* The socket was closed. */
-               ret = -EBADF;
+    /* Try to pass the guard in order to access the controller */
+    ret = rtdm_sem_timeddown(&dev->tx_sem, timeout, NULL);
 
-    } else
+    /* Only dequeue task again if socket isn't being closed i.e. if
+     * this task was not unblocked within the close() function. */
+    if (likely(tx_wait.tx_wait_list.next != LIST_POISON1))
+       /* Dequeue this task from the TX wait queue */
+       list_del(&tx_wait.tx_wait_list);
+    else
        /* The socket was closed. */
-           ret = -EBADF;
+       ret = -EBADF;
 
     cobalt_atomic_leave(s);
 
@@ -1002,10 +985,10 @@ static struct rtdm_device rtcan_proto_raw_dev = {
     protocol_family:    PF_CAN,
     socket_type:        SOCK_RAW,
 
-    socket_nrt:         rtcan_raw_socket,
+    socket:            rtcan_raw_socket,
 
     ops: {
-       close_nrt:      rtcan_raw_close,
+       close:          rtcan_raw_close,
 
        ioctl_rt:       rtcan_raw_ioctl,
        ioctl_nrt:      rtcan_raw_ioctl,
diff --git a/kernel/drivers/can/rtcan_raw.h b/kernel/drivers/can/rtcan_raw.h
index 05a741e..cd1523e 100644
--- a/kernel/drivers/can/rtcan_raw.h
+++ b/kernel/drivers/can/rtcan_raw.h
@@ -22,8 +22,7 @@
 
 #ifdef __KERNEL__
 
-int rtcan_raw_ioctl_dev(struct rtdm_dev_context *context,
-                       rtdm_user_info_t *user_info, int request, void *arg);
+int rtcan_raw_ioctl_dev(struct rtdm_fd *fd, int request, void *arg);
 
 int rtcan_raw_check_filter(struct rtcan_socket *sock,
                           int ifindex, struct rtcan_filter_list *flist);
diff --git a/kernel/drivers/can/rtcan_raw_dev.c 
b/kernel/drivers/can/rtcan_raw_dev.c
index 179598a..999b593 100644
--- a/kernel/drivers/can/rtcan_raw_dev.c
+++ b/kernel/drivers/can/rtcan_raw_dev.c
@@ -366,8 +366,7 @@ static inline int rtcan_raw_ioctl_dev_set(struct 
rtcan_device *dev,
     return ret;
 }
 
-int rtcan_raw_ioctl_dev(struct rtdm_dev_context *context,
-                       rtdm_user_info_t *user_info, int request, void *arg)
+int rtcan_raw_ioctl_dev(struct rtdm_fd *fd, int request, void *arg)
 {
     int ret = 0;
     struct ifreq *ifr;
@@ -381,9 +380,9 @@ int rtcan_raw_ioctl_dev(struct rtdm_dev_context *context,
     case SIOCGCANBAUDRATE:
     case SIOCGCANCUSTOMBITTIME:
 
-       if (user_info) {
-           if (!rtdm_rw_user_ok(user_info, arg, sizeof(struct ifreq)) ||
-               rtdm_copy_from_user(user_info, &ifr_buf, arg,
+       if (rtdm_fd_is_user(fd)) {
+           if (!rtdm_rw_user_ok(fd, arg, sizeof(struct ifreq)) ||
+               rtdm_copy_from_user(fd, &ifr_buf, arg,
                                    sizeof(struct ifreq)))
                return -EFAULT;
 
@@ -396,10 +395,10 @@ int rtcan_raw_ioctl_dev(struct rtdm_dev_context *context,
        ret = rtcan_raw_ioctl_dev_get(dev, request, ifr);
        rtcan_dev_dereference(dev);
 
-       if (user_info && !ret) {
+       if (rtdm_fd_is_user(fd) && !ret) {
            /* Since we yet tested if user memory is rw safe,
               we can copy to user space directly */
-           if (rtdm_copy_to_user(user_info, arg, ifr,
+           if (rtdm_copy_to_user(fd, arg, ifr,
                                  sizeof(struct ifreq)))
                return -EFAULT;
        }
@@ -410,11 +409,11 @@ int rtcan_raw_ioctl_dev(struct rtdm_dev_context *context,
     case SIOCSCANBAUDRATE:
     case SIOCSCANCUSTOMBITTIME:
 
-       if (user_info) {
+       if (rtdm_fd_is_user(fd)) {
            /* Copy struct ifreq from userspace */
-           if (!rtdm_read_user_ok(user_info, arg,
+           if (!rtdm_read_user_ok(fd, arg,
                                   sizeof(struct ifreq)) ||
-               rtdm_copy_from_user(user_info, &ifr_buf, arg,
+               rtdm_copy_from_user(fd, &ifr_buf, arg,
                                    sizeof(struct ifreq)))
                return -EFAULT;
 
diff --git a/kernel/drivers/can/rtcan_socket.c 
b/kernel/drivers/can/rtcan_socket.c
index 141a8bf..6e6e79e 100644
--- a/kernel/drivers/can/rtcan_socket.c
+++ b/kernel/drivers/can/rtcan_socket.c
@@ -34,9 +34,9 @@
 
 LIST_HEAD(rtcan_socket_list);
 
-void rtcan_socket_init(struct rtdm_dev_context *context)
+void rtcan_socket_init(struct rtdm_fd *fd)
 {
-    struct rtcan_socket *sock = (struct rtcan_socket *)&context->dev_private;
+    struct rtcan_socket *sock = rtdm_fd_to_private(fd);
     rtdm_lockctx_t lock_ctx;
 
 
@@ -64,9 +64,9 @@ void rtcan_socket_init(struct rtdm_dev_context *context)
 }
 
 
-void rtcan_socket_cleanup(struct rtdm_dev_context *context)
+void rtcan_socket_cleanup(struct rtdm_fd *fd)
 {
-    struct rtcan_socket *sock = (struct rtcan_socket *)&context->dev_private;
+    struct rtcan_socket *sock = rtdm_fd_to_private(fd);
     struct tx_wait_queue *tx_waiting;
     rtdm_lockctx_t lock_ctx;
     int tx_list_empty;
diff --git a/kernel/drivers/can/rtcan_socket.h 
b/kernel/drivers/can/rtcan_socket.h
index 4daeb0b..cf4422a 100644
--- a/kernel/drivers/can/rtcan_socket.h
+++ b/kernel/drivers/can/rtcan_socket.h
@@ -126,6 +126,8 @@ struct rtcan_socket {
 
     struct list_head    socket_list;
 
+    unsigned long      flags;
+
     /* Transmission timeout in ns. Protected by rtcan_socket_lock
      * in all socket structures. */
     nanosecs_rel_t      tx_timeout;
@@ -184,15 +186,13 @@ struct rtcan_socket {
  *
  *  @param[in] sock Pointer to socket structure
  *
- *  @return Pointer to context of type struct rtdm_dev_context this socket
+ *  @return Pointer to a file descriptor of type struct rtdm_fd this socket
  *          belongs to
  */
 /* FIXME: to be replaced with container_of */
-static inline struct rtdm_dev_context *rtcan_socket_context(
-    struct rtcan_socket *sock)
+static inline struct rtdm_fd *rtcan_socket_to_fd(struct rtcan_socket *sock)
 {
-    return (struct rtdm_dev_context *)((void *)sock -
-       (void *)(&((struct rtdm_dev_context *)NULL)->dev_private));
+    return rtdm_private_to_fd(sock);
 }
 
 /* Spinlock protecting the ring buffers and the timeouts of all
@@ -200,8 +200,8 @@ static inline struct rtdm_dev_context *rtcan_socket_context(
 extern rtdm_lock_t rtcan_socket_lock;
 extern struct list_head rtcan_socket_list;
 
-extern void rtcan_socket_init(struct rtdm_dev_context *context);
-extern void rtcan_socket_cleanup(struct rtdm_dev_context *context);
+extern void rtcan_socket_init(struct rtdm_fd *fd);
+extern void rtcan_socket_cleanup(struct rtdm_fd *fd);
 
 
 #endif  /* __RTCAN_SOCKET_H_ */


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

Reply via email to