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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Sep 19 18:14:37 2014 +0200

cobalt/rtdm/fd: assume current context is target for all fd ops

Except in the only weird case of forcing a close on any random
kernel-originated connection through the procfs interface
(open_fildes), but this case is on its way out.

For the sake of mental sanity, we really want to assume that only the
current thread may affect its own file table, which is what this patch
enforces.

The rtdm_fd cleanup thread is a non-issue, as we are not supposed to
run any fd ops recursively on behalf of a ->close() handler anyway.

This change also fixes a rampant inconsistency where a Cobalt user
thread running some driver code would actually look up into the wrong
RTDM file table when using the rt_dev_* interface
(i.e. __xnsys_global_ppd would not be the right context in such a
case).

---

 include/cobalt/kernel/rtdm/fd.h   |   32 +++++++++----------
 include/cobalt/kernel/rtdm/rtdm.h |   12 +++----
 kernel/cobalt/posix/io.c          |   14 ++++-----
 kernel/cobalt/posix/mqueue.c      |   12 +++----
 kernel/cobalt/posix/timerfd.c     |    5 ++-
 kernel/cobalt/rtdm/core.c         |   22 +++++++------
 kernel/cobalt/rtdm/fd.c           |   63 ++++++++++++++++++-------------------
 kernel/cobalt/rtdm/proc.c         |    8 +++--
 8 files changed, 85 insertions(+), 83 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/fd.h b/include/cobalt/kernel/rtdm/fd.h
index 6b50cef..d4a97b2 100644
--- a/include/cobalt/kernel/rtdm/fd.h
+++ b/include/cobalt/kernel/rtdm/fd.h
@@ -296,7 +296,7 @@ struct rtdm_fd_ops {
 struct rtdm_fd {
        unsigned int magic;
        struct rtdm_fd_ops *ops;
-       struct xnsys_ppd *cont;
+       struct xnsys_ppd *owner;
        unsigned int refs;
        int minor;
        struct list_head cleanup;
@@ -306,7 +306,7 @@ struct rtdm_fd {
 
 static inline struct xnsys_ppd *rtdm_fd_owner(struct rtdm_fd *fd)
 {
-       return fd->cont;
+       return fd->owner;
 }
 
 static inline int rtdm_fd_minor(struct rtdm_fd *fd)
@@ -314,11 +314,10 @@ static inline int rtdm_fd_minor(struct rtdm_fd *fd)
        return fd->minor;
 }
 
-int rtdm_fd_enter(struct xnsys_ppd *p, struct rtdm_fd *rtdm_fd, int ufd,
+int rtdm_fd_enter(struct rtdm_fd *rtdm_fd, int ufd,
                  unsigned int magic, struct rtdm_fd_ops *ops);
 
-struct rtdm_fd *rtdm_fd_get(struct xnsys_ppd *p,
-                           int ufd, unsigned int magic);
+struct rtdm_fd *rtdm_fd_get(int ufd, unsigned int magic);
 
 int rtdm_fd_lock(struct rtdm_fd *fd);
 
@@ -326,24 +325,23 @@ void rtdm_fd_put(struct rtdm_fd *fd);
 
 void rtdm_fd_unlock(struct rtdm_fd *fd);
 
-int rtdm_fd_ioctl(struct xnsys_ppd *p, int ufd, unsigned int request, ...);
+int rtdm_fd_ioctl(int ufd, unsigned int request, ...);
 
-ssize_t rtdm_fd_read(struct xnsys_ppd *p, int ufd,
-                    void __user *buf, size_t size);
+ssize_t rtdm_fd_read(int ufd, void __user *buf, size_t size);
 
-ssize_t rtdm_fd_write(struct xnsys_ppd *p, int ufd,
-                     const void __user *buf, size_t size);
+ssize_t rtdm_fd_write(int ufd, const void __user *buf, size_t size);
 
-int rtdm_fd_close(struct xnsys_ppd *p, int ufd, unsigned int magic);
+int __rtdm_fd_close(struct xnsys_ppd *ppd,
+                   int ufd, unsigned int magic);
 
-ssize_t rtdm_fd_recvmsg(struct xnsys_ppd *p, int ufd,
-                       struct msghdr *msg, int flags);
+int rtdm_fd_close(int ufd, unsigned int magic);
 
-ssize_t rtdm_fd_sendmsg(struct xnsys_ppd *p, int ufd,
-                       const struct msghdr *msg, int flags);
+ssize_t rtdm_fd_recvmsg(int ufd, struct msghdr *msg, int flags);
 
-int rtdm_fd_mmap(struct xnsys_ppd *p, int ufd,
-                struct _rtdm_mmap_request *rma,
+ssize_t rtdm_fd_sendmsg(int ufd, const struct msghdr *msg,
+                       int flags);
+
+int rtdm_fd_mmap(int ufd, struct _rtdm_mmap_request *rma,
                 void * __user *u_addrp);
 
 int rtdm_fd_valid_p(int ufd);
diff --git a/include/cobalt/kernel/rtdm/rtdm.h 
b/include/cobalt/kernel/rtdm/rtdm.h
index 98f0d3a..b1ffab3 100644
--- a/include/cobalt/kernel/rtdm/rtdm.h
+++ b/include/cobalt/kernel/rtdm/rtdm.h
@@ -53,22 +53,22 @@ __rt_dev_ioctl_fallback(struct rtdm_fd *fd, unsigned 
request, void __user *arg);
        __rtdm_dev_ksocket(protocol_family, socket_type, protocol)
 
 #define rt_dev_close(fd)                                       \
-       rtdm_fd_close(&__xnsys_global_ppd, fd, RTDM_FD_MAGIC)
+       rtdm_fd_close(fd, RTDM_FD_MAGIC)
 
 #define rt_dev_ioctl(fd, request, ...)                         \
-       rtdm_fd_ioctl(&__xnsys_global_ppd, fd, request, __VA_ARGS__)
+       rtdm_fd_ioctl(fd, request, __VA_ARGS__)
 
 #define rt_dev_read(fd, buf, nbyte)                            \
-       rtdm_fd_read(&__xnsys_global_ppd, fd, buf, nbyte)
+       rtdm_fd_read(fd, buf, nbyte)
 
 #define rt_dev_write(fd, buf, nbyte)                           \
-       rtdm_fd_write(&__xnsys_global_ppd, fd, buf, nbyte)
+       rtdm_fd_write(fd, buf, nbyte)
 
 #define rt_dev_recvmsg(fd, msg, flags)                         \
-       rtdm_fd_recvmsg(&__xnsys_global_ppd, fd, msg, flags)
+       rtdm_fd_recvmsg(fd, msg, flags)
 
 #define rt_dev_sendmsg(fd, msg, flags)                         \
-       rtdm_fd_sendmsg(&__xnsys_global_ppd, fd, msg, flags)
+       rtdm_fd_sendmsg(fd, msg, flags)
 
 static inline
 ssize_t rt_dev_recvfrom(int fd, void *buf, size_t len, int flags,
diff --git a/kernel/cobalt/posix/io.c b/kernel/cobalt/posix/io.c
index 197d327..7880fbc 100644
--- a/kernel/cobalt/posix/io.c
+++ b/kernel/cobalt/posix/io.c
@@ -51,25 +51,25 @@ COBALT_SYSCALL(socket, lostage,
 
 COBALT_SYSCALL(close, lostage, int, (int fd))
 {
-       return rtdm_fd_close(cobalt_ppd_get(0), fd, XNFD_MAGIC_ANY);
+       return rtdm_fd_close(fd, XNFD_MAGIC_ANY);
 }
 
 COBALT_SYSCALL(ioctl, probing,
               int, (int fd, unsigned int request, void __user *arg))
 {
-       return rtdm_fd_ioctl(cobalt_ppd_get(0), fd, request, arg);
+       return rtdm_fd_ioctl(fd, request, arg);
 }
 
 COBALT_SYSCALL(read, probing,
               ssize_t, (int fd, void __user *buf, size_t size))
 {
-       return rtdm_fd_read(cobalt_ppd_get(0), fd, buf, size);
+       return rtdm_fd_read(fd, buf, size);
 }
 
 COBALT_SYSCALL(write, probing,
               ssize_t, (int fd, const void __user *buf, size_t size))
 {
-       return rtdm_fd_write(cobalt_ppd_get(0), fd, buf, size);
+       return rtdm_fd_write(fd, buf, size);
 }
 
 COBALT_SYSCALL(recvmsg, probing,
@@ -81,7 +81,7 @@ COBALT_SYSCALL(recvmsg, probing,
        if (__xn_copy_from_user(&m, umsg, sizeof(m)))
                return -EFAULT;
 
-       ret = rtdm_fd_recvmsg(cobalt_ppd_get(0), fd, &m, flags);
+       ret = rtdm_fd_recvmsg(fd, &m, flags);
        if (ret < 0)
                return ret;
 
@@ -99,7 +99,7 @@ COBALT_SYSCALL(sendmsg, probing,
        if (__xn_copy_from_user(&m, umsg, sizeof(m)))
                return -EFAULT;
 
-       return rtdm_fd_sendmsg(cobalt_ppd_get(0), fd, &m, flags);
+       return rtdm_fd_sendmsg(fd, &m, flags);
 }
 
 COBALT_SYSCALL(mmap, lostage,
@@ -113,7 +113,7 @@ COBALT_SYSCALL(mmap, lostage,
        if (__xn_copy_from_user(&rma, u_rma, sizeof(rma)))
                return -EFAULT;
 
-       ret = rtdm_fd_mmap(cobalt_ppd_get(0), fd, &rma, &u_addr);
+       ret = rtdm_fd_mmap(fd, &rma, &u_addr);
        if (ret)
                return ret;
 
diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index 4d6a697..dc27b65 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -270,10 +270,8 @@ static struct rtdm_fd_ops mqd_ops = {
 static inline int mqd_create(struct cobalt_mq *mq, unsigned long flags, int 
ufd)
 {
        struct cobalt_mqd *mqd;
-       struct xnsys_ppd *p;
 
-       p = cobalt_ppd_get(0);
-       if (p == &__xnsys_global_ppd)
+       if (cobalt_ppd_get(0) == &__xnsys_global_ppd)
                return -EPERM;
 
        mqd = kmalloc(sizeof(*mqd), GFP_KERNEL);
@@ -283,7 +281,7 @@ static inline int mqd_create(struct cobalt_mq *mq, unsigned 
long flags, int ufd)
        mqd->flags = flags;
        mqd->mq = mq;
 
-       return rtdm_fd_enter(p, &mqd->fd, ufd, COBALT_MQD_MAGIC, &mqd_ops);
+       return rtdm_fd_enter(&mqd->fd, ufd, COBALT_MQD_MAGIC, &mqd_ops);
 }
 
 static int mq_open(int uqd, const char *name, int oflags,
@@ -360,7 +358,7 @@ static int mq_open(int uqd, const char *name, int oflags,
                        list_add_tail(&mq->link, &cobalt_mqq);
                xnlock_put_irqrestore(&nklock, s);
                if (err < 0) {
-                       rtdm_fd_close(cobalt_ppd_get(0), uqd, COBALT_MQD_MAGIC);
+                       rtdm_fd_close(uqd, COBALT_MQD_MAGIC);
                        if (err == -EEXIST)
                                goto retry_bind;
                        return err;
@@ -376,7 +374,7 @@ static int mq_open(int uqd, const char *name, int oflags,
 
 static inline int mq_close(mqd_t fd)
 {
-       return rtdm_fd_close(cobalt_ppd_get(0), fd, COBALT_MQD_MAGIC);
+       return rtdm_fd_close(fd, COBALT_MQD_MAGIC);
 }
 
 static inline int mq_unlink(const char *name)
@@ -741,7 +739,7 @@ static inline struct cobalt_mqd *cobalt_mqd_get(mqd_t ufd)
 {
        struct rtdm_fd *fd;
 
-       fd = rtdm_fd_get(cobalt_ppd_get(0), ufd, COBALT_MQD_MAGIC);
+       fd = rtdm_fd_get(ufd, COBALT_MQD_MAGIC);
        if (IS_ERR(fd)) {
                int err = PTR_ERR(fd);
                if (err == -EBADF && cobalt_current_process() == NULL)
diff --git a/kernel/cobalt/posix/timerfd.c b/kernel/cobalt/posix/timerfd.c
index 8b85de3..5cd0521 100644
--- a/kernel/cobalt/posix/timerfd.c
+++ b/kernel/cobalt/posix/timerfd.c
@@ -198,8 +198,7 @@ COBALT_SYSCALL(timerfd_create, lostage,
        xnselect_init(&tfd->read_select);
        tfd->target = NULL;
 
-       ret = rtdm_fd_enter(ppd, &tfd->fd, ufd, COBALT_TIMERFD_MAGIC,
-                           &timerfd_ops);
+       ret = rtdm_fd_enter(&tfd->fd, ufd, COBALT_TIMERFD_MAGIC, &timerfd_ops);
        if (ret < 0)
                goto fail;
 
@@ -219,7 +218,7 @@ static inline struct cobalt_tfd *tfd_get(int ufd)
 {
        struct rtdm_fd *fd;
 
-       fd = rtdm_fd_get(cobalt_ppd_get(0), ufd, COBALT_TIMERFD_MAGIC);
+       fd = rtdm_fd_get(ufd, COBALT_TIMERFD_MAGIC);
        if (IS_ERR(fd)) {
                int err = PTR_ERR(fd);
                if (err == -EBADF && cobalt_current_process() == NULL)
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 9028652..84afc94 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -120,8 +120,7 @@ static int create_kinstance(struct rtdm_device *device,
        context->device = device;
        *context_ptr = context;
 
-       ret = rtdm_fd_enter(&__xnsys_global_ppd, &context->fd, ufd,
-                           RTDM_FD_MAGIC, &device->ops);
+       ret = rtdm_fd_enter(&context->fd, ufd, RTDM_FD_MAGIC, &device->ops);
        if (ret < 0)
                goto fail;
 
@@ -135,8 +134,7 @@ fail:
        return ret;
 }
 
-static int create_instance(struct xnsys_ppd *ppd, int ufd,
-                          struct rtdm_device *device,
+static int create_instance(int ufd, struct rtdm_device *device,
                           struct rtdm_dev_context **context_ptr)
 {
        struct rtdm_device_class *class = device->class;
@@ -160,7 +158,7 @@ static int create_instance(struct xnsys_ppd *ppd, int ufd,
        context->device = device;
        *context_ptr = context;
 
-       return rtdm_fd_enter(ppd, &context->fd, ufd, RTDM_FD_MAGIC, 
&device->ops);
+       return rtdm_fd_enter(&context->fd, ufd, RTDM_FD_MAGIC, &device->ops);
 }
 
 int __rtdm_dev_kopen(const char *path, int oflag)
@@ -169,6 +167,8 @@ int __rtdm_dev_kopen(const char *path, int oflag)
        struct rtdm_device *device;
        int ufd, ret;
 
+       secondary_mode_only();
+
        device = __rtdm_get_namedev(path);
        if (device == NULL)
                return -ENODEV;
@@ -205,10 +205,11 @@ int __rtdm_dev_open(const char *path, int oflag)
 {
        struct rtdm_dev_context *context;
        struct rtdm_device *device;
-       struct xnsys_ppd *ppd;
        struct file *filp;
        int ufd, ret;
 
+       secondary_mode_only();
+
        device = __rtdm_get_namedev(path);
        if (device == NULL)
                return -ENODEV;
@@ -225,8 +226,7 @@ int __rtdm_dev_open(const char *path, int oflag)
                goto fail_fopen;
        }
 
-       ppd = cobalt_ppd_get(0);
-       ret = create_instance(ppd, ufd, device, &context);
+       ret = create_instance(ufd, device, &context);
        if (ret < 0)
                goto fail_create;
 
@@ -268,6 +268,8 @@ int __rtdm_dev_ksocket(int protocol_family, int socket_type,
        struct rtdm_device *device;
        int ufd, ret;
 
+       secondary_mode_only();
+
        device = __rtdm_get_protodev(protocol_family, socket_type);
        if (device == NULL)
                return -EAFNOSUPPORT;
@@ -306,6 +308,8 @@ int __rtdm_dev_socket(int protocol_family, int socket_type,
        struct xnsys_ppd *ppd;
        int ufd, ret;
 
+       secondary_mode_only();
+
        device = __rtdm_get_protodev(protocol_family, socket_type);
        if (device == NULL)
                return -EAFNOSUPPORT;
@@ -317,7 +321,7 @@ int __rtdm_dev_socket(int protocol_family, int socket_type,
                goto fail_getfd;
        }
 
-       ret = create_instance(ppd, ufd, device, &context);
+       ret = create_instance(ufd, device, &context);
        if (ret < 0)
                goto fail_create;
 
diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c
index 8617e83..c6e6cce 100644
--- a/kernel/cobalt/rtdm/fd.c
+++ b/kernel/cobalt/rtdm/fd.c
@@ -115,10 +115,11 @@ static struct rtdm_fd *fetch_fd(struct xnsys_ppd *p, int 
ufd)
                }                                                       \
        while (0)
 
-int rtdm_fd_enter(struct xnsys_ppd *p, struct rtdm_fd *fd, int ufd,
-                 unsigned int magic, struct rtdm_fd_ops *ops)
+int rtdm_fd_enter(struct rtdm_fd *fd, int ufd, unsigned int magic,
+                 struct rtdm_fd_ops *ops)
 {
        struct rtdm_fd_index *idx;
+       struct xnsys_ppd *ppd;
        spl_t s;
        int ret;
 
@@ -140,15 +141,16 @@ int rtdm_fd_enter(struct xnsys_ppd *p, struct rtdm_fd 
*fd, int ufd,
        assign_invalid_default_handler(ops->mmap);
        __assign_default_handler(ops->close, nop_close);
 
+       ppd = cobalt_ppd_get(0);
        fd->magic = magic;
        fd->ops = ops;
-       fd->cont = p;
+       fd->owner = ppd;
        fd->refs = 1;
 
        idx->fd = fd;
 
        xnlock_get_irqsave(&__rtdm_fd_lock, s);
-       ret = xnid_enter(&p->fds, &idx->id, ufd);
+       ret = xnid_enter(&ppd->fds, &idx->id, ufd);
        xnlock_put_irqrestore(&__rtdm_fd_lock, s);
        if (ret < 0) {
                kfree(idx);
@@ -161,7 +163,6 @@ int rtdm_fd_enter(struct xnsys_ppd *p, struct rtdm_fd *fd, 
int ufd,
 /**
  * @brief Retrieve and lock a RTDM file descriptor
  *
- * @param[in] p PPD descriptor of the calling process
  * @param[in] ufd User-side file descriptor
  * @param[in] magic Magic word for lookup validation
  *
@@ -173,8 +174,9 @@ int rtdm_fd_enter(struct xnsys_ppd *p, struct rtdm_fd *fd, 
int ufd,
  *
  * @coretags{unrestricted}
  */
-struct rtdm_fd *rtdm_fd_get(struct xnsys_ppd *p, int ufd, unsigned int magic)
+struct rtdm_fd *rtdm_fd_get(int ufd, unsigned int magic)
 {
+       struct xnsys_ppd *p = cobalt_ppd_get(0);
        struct rtdm_fd *res;
        spl_t s;
 
@@ -328,7 +330,7 @@ void rtdm_fd_unlock(struct rtdm_fd *fd)
 }
 EXPORT_SYMBOL_GPL(rtdm_fd_unlock);
 
-int rtdm_fd_ioctl(struct xnsys_ppd *p, int ufd, unsigned int request, ...)
+int rtdm_fd_ioctl(int ufd, unsigned int request, ...)
 {
        void __user *arg;
        struct rtdm_fd *fd;
@@ -339,7 +341,7 @@ int rtdm_fd_ioctl(struct xnsys_ppd *p, int ufd, unsigned 
int request, ...)
        arg = va_arg(args, void __user *);
        va_end(args);
 
-       fd = rtdm_fd_get(p, ufd, XNFD_MAGIC_ANY);
+       fd = rtdm_fd_get(ufd, XNFD_MAGIC_ANY);
        if (IS_ERR(fd)) {
                err = PTR_ERR(fd);
                goto out;
@@ -371,12 +373,12 @@ int rtdm_fd_ioctl(struct xnsys_ppd *p, int ufd, unsigned 
int request, ...)
 EXPORT_SYMBOL_GPL(rtdm_fd_ioctl);
 
 ssize_t
-rtdm_fd_read(struct xnsys_ppd *p, int ufd, void __user *buf, size_t size)
+rtdm_fd_read(int ufd, void __user *buf, size_t size)
 {
        struct rtdm_fd *fd;
        ssize_t err;
 
-       fd = rtdm_fd_get(p, ufd, XNFD_MAGIC_ANY);
+       fd = rtdm_fd_get(ufd, XNFD_MAGIC_ANY);
        if (IS_ERR(fd)) {
                err = PTR_ERR(fd);
                goto out;
@@ -402,13 +404,12 @@ rtdm_fd_read(struct xnsys_ppd *p, int ufd, void __user 
*buf, size_t size)
 }
 EXPORT_SYMBOL_GPL(rtdm_fd_read);
 
-ssize_t rtdm_fd_write(struct xnsys_ppd *p, int ufd,
-                     const void __user *buf, size_t size)
+ssize_t rtdm_fd_write(int ufd, const void __user *buf, size_t size)
 {
        struct rtdm_fd *fd;
        ssize_t err;
 
-       fd = rtdm_fd_get(p, ufd, XNFD_MAGIC_ANY);
+       fd = rtdm_fd_get(ufd, XNFD_MAGIC_ANY);
        if (IS_ERR(fd)) {
                err = PTR_ERR(fd);
                goto out;
@@ -434,13 +435,12 @@ ssize_t rtdm_fd_write(struct xnsys_ppd *p, int ufd,
 }
 EXPORT_SYMBOL_GPL(rtdm_fd_write);
 
-ssize_t
-rtdm_fd_recvmsg(struct xnsys_ppd *p, int ufd, struct msghdr *msg, int flags)
+ssize_t rtdm_fd_recvmsg(int ufd, struct msghdr *msg, int flags)
 {
        struct rtdm_fd *fd;
        ssize_t err;
 
-       fd = rtdm_fd_get(p, ufd, XNFD_MAGIC_ANY);
+       fd = rtdm_fd_get(ufd, XNFD_MAGIC_ANY);
        if (IS_ERR(fd)) {
                err = PTR_ERR(fd);
                goto out;
@@ -457,8 +457,7 @@ rtdm_fd_recvmsg(struct xnsys_ppd *p, int ufd, struct msghdr 
*msg, int flags)
                    splnone();
 
        rtdm_fd_put(fd);
-
-  out:
+out:
        if (err < 0)
                trace_cobalt_fd_recvmsg_status(current, fd, ufd, err);
 
@@ -466,13 +465,12 @@ rtdm_fd_recvmsg(struct xnsys_ppd *p, int ufd, struct 
msghdr *msg, int flags)
 }
 EXPORT_SYMBOL_GPL(rtdm_fd_recvmsg);
 
-ssize_t
-rtdm_fd_sendmsg(struct xnsys_ppd *p, int ufd, const struct msghdr *msg, int 
flags)
+ssize_t rtdm_fd_sendmsg(int ufd, const struct msghdr *msg, int flags)
 {
        struct rtdm_fd *fd;
        ssize_t err;
 
-       fd = rtdm_fd_get(p, ufd, XNFD_MAGIC_ANY);
+       fd = rtdm_fd_get(ufd, XNFD_MAGIC_ANY);
        if (IS_ERR(fd)) {
                err = PTR_ERR(fd);
                goto out;
@@ -489,8 +487,7 @@ rtdm_fd_sendmsg(struct xnsys_ppd *p, int ufd, const struct 
msghdr *msg, int flag
                    splnone();
 
        rtdm_fd_put(fd);
-
-  out:
+out:
        if (err < 0)
                trace_cobalt_fd_sendmsg_status(current, fd, ufd, err);
 
@@ -507,14 +504,14 @@ __fd_close(struct xnsys_ppd *p, struct rtdm_fd_index 
*idx, spl_t s)
        kfree(idx);
 }
 
-int rtdm_fd_close(struct xnsys_ppd *p, int ufd, unsigned int magic)
+int __rtdm_fd_close(struct xnsys_ppd *ppd, int ufd, unsigned int magic)
 {
        struct rtdm_fd_index *idx;
        struct rtdm_fd *fd;
        spl_t s;
 
        xnlock_get_irqsave(&__rtdm_fd_lock, s);
-       idx = fetch_fd_index(p, ufd);
+       idx = fetch_fd_index(ppd, ufd);
        if (idx == NULL)
                goto ebadf;
 
@@ -528,20 +525,24 @@ int rtdm_fd_close(struct xnsys_ppd *p, int ufd, unsigned 
int magic)
        trace_cobalt_fd_close(current, fd, ufd, fd->refs);
 
        __rt_dev_unref(fd, xnid_key(&idx->id));
-       __fd_close(p, idx, s);
+       __fd_close(ppd, idx, s);
 
        return 0;
 }
+
+int rtdm_fd_close(int ufd, unsigned int magic)
+{
+       return __rtdm_fd_close(cobalt_ppd_get(0), ufd, magic);
+}
 EXPORT_SYMBOL_GPL(rtdm_fd_close);
 
-int rtdm_fd_mmap(struct xnsys_ppd *p, int ufd,
-                struct _rtdm_mmap_request *rma,
+int rtdm_fd_mmap(int ufd, struct _rtdm_mmap_request *rma,
                 void * __user *u_addrp)
 {
        struct rtdm_fd *fd;
        int ret;
 
-       fd = rtdm_fd_get(p, ufd, XNFD_MAGIC_ANY);
+       fd = rtdm_fd_get(ufd, XNFD_MAGIC_ANY);
        if (IS_ERR(fd)) {
                ret = PTR_ERR(fd);
                goto out;
@@ -599,12 +600,10 @@ int rtdm_fd_valid_p(int ufd)
 int rtdm_fd_select(int ufd, struct xnselector *selector,
                   unsigned int type)
 {
-       struct xnsys_ppd *p;
        struct rtdm_fd *fd;
        int rc;
 
-       p = cobalt_ppd_get(0);
-       fd = rtdm_fd_get(p, ufd, XNFD_MAGIC_ANY);
+       fd = rtdm_fd_get(ufd, XNFD_MAGIC_ANY);
        if (IS_ERR(fd))
                return PTR_ERR(fd);
 
diff --git a/kernel/cobalt/rtdm/proc.c b/kernel/cobalt/rtdm/proc.c
index 87b279b..fe635f3 100644
--- a/kernel/cobalt/rtdm/proc.c
+++ b/kernel/cobalt/rtdm/proc.c
@@ -190,7 +190,7 @@ static int openfd_show(struct xnvfile_regular_iterator *it, 
void *data)
 
        i = (int)it->pos - 1;
 
-       fd = rtdm_fd_get(&__xnsys_global_ppd, i, RTDM_FD_MAGIC);
+       fd = rtdm_fd_get(i, RTDM_FD_MAGIC);
        if (IS_ERR(fd))
                return VFILE_SEQ_SKIP;
 
@@ -215,7 +215,11 @@ static ssize_t openfd_store(struct xnvfile_input *input)
        if (ret < 0)
                return ret;
 
-       cret = rtdm_fd_close(&__xnsys_global_ppd, (int)val, RTDM_FD_MAGIC);
+       /*
+        * This ugly beast allows to force a close on a
+        * kernel-originated connection.
+        */
+       cret = __rtdm_fd_close(&__xnsys_global_ppd, (int)val, RTDM_FD_MAGIC);
        if (cret < 0)
                return cret;
 


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

Reply via email to