Module: xenomai-abe
Branch: analogy
Commit: ca358d2dd68741bb1f9c52ec4117f254fa134907
URL:    
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=ca358d2dd68741bb1f9c52ec4117f254fa134907

Author: Alexis Berlemont <alexis.berlem...@gmail.com>
Date:   Thu Nov  5 23:54:47 2009 +0100

analogy: improve ioctl error handling

---

 ksrc/drivers/analogy/buffer.c      |   72 ++++++++++++++++++++++++-----------
 ksrc/drivers/analogy/command.c     |    9 ++--
 ksrc/drivers/analogy/device.c      |    2 +-
 ksrc/drivers/analogy/instruction.c |    2 +-
 ksrc/drivers/analogy/subdevice.c   |    3 +-
 ksrc/drivers/analogy/transfer.c    |   10 ++++-
 6 files changed, 67 insertions(+), 31 deletions(-)

diff --git a/ksrc/drivers/analogy/buffer.c b/ksrc/drivers/analogy/buffer.c
index cad8a06..2672d7d 100644
--- a/ksrc/drivers/analogy/buffer.c
+++ b/ksrc/drivers/analogy/buffer.c
@@ -407,13 +407,20 @@ int a4l_ioctl_mmap(a4l_cxt_t *cxt, void *arg)
                return -EFAULT;
 
        /* Check the subdevice */
-       if (map_cfg.idx_subd >= dev->transfer.nb_subd ||
-           (dev->transfer.subds[map_cfg.idx_subd]->flags & A4L_SUBD_CMD) ==
-           0
-           || (dev->transfer.subds[map_cfg.idx_subd]->
-               flags & A4L_SUBD_MMAP) == 0) {
-               __a4l_err("a4l_ioctl_mmap: wrong subdevice selected (idx=%d)\n",
-                         map_cfg.idx_subd);
+       if (map_cfg.idx_subd >= dev->transfer.nb_subd) {
+               __a4l_err("a4l_ioctl_mmap: subdevice index "
+                         "out of range (idx=%d)\n", map_cfg.idx_subd);
+               return -EINVAL;
+       }
+
+       if ((dev->transfer.subds[map_cfg.idx_subd]->flags & A4L_SUBD_CMD) == 0) 
{
+               __a4l_err("a4l_ioctl_mmap: operation not supported, "
+                         "synchronous only subdevice\n");
+               return -EINVAL;
+       }
+
+       if ((dev->transfer.subds[map_cfg.idx_subd]->flags & A4L_SUBD_MMAP) == 
0) {
+               __a4l_err("a4l_ioctl_mmap: mmap not allowed on this 
subdevice\n");
                return -EINVAL;
        }
 
@@ -476,9 +483,16 @@ int a4l_ioctl_bufcfg(a4l_cxt_t * cxt, void *arg)
                                     arg, sizeof(a4l_bufcfg_t)) != 0)
                return -EFAULT;
 
-       if (buf_cfg.idx_subd >= dev->transfer.nb_subd ||
-           (dev->transfer.subds[buf_cfg.idx_subd]->flags & A4L_SUBD_CMD) == 0) 
{
-               __a4l_err("a4l_ioctl_bufcfg: wrong subdevice selected\n");
+       /* Check the subdevice */
+       if (buf_cfg.idx_subd >= dev->transfer.nb_subd) {
+               __a4l_err("a4l_ioctl_bufcfg: subdevice index "
+                         "out of range (idx=%d)\n", buf_cfg.idx_subd);
+               return -EINVAL;
+       }
+
+       if ((dev->transfer.subds[buf_cfg.idx_subd]->flags & A4L_SUBD_CMD) == 0) 
{
+               __a4l_err("a4l_ioctl_bufcfg: operation not supported, "
+                         "synchronous only subdevice\n");
                return -EINVAL;
        }
 
@@ -491,7 +505,7 @@ int a4l_ioctl_bufcfg(a4l_cxt_t * cxt, void *arg)
           no buffer size change is allowed */
        if (test_bit(A4L_TSF_BUSY,
                     &(dev->transfer.status[buf_cfg.idx_subd]))) {
-               __a4l_err("a4l_ioctl_bufcfg: buffer size too big (<=16MB)\n");
+               __a4l_err("a4l_ioctl_bufcfg: acquisition in progress\n");
                return -EBUSY;
        }
 
@@ -531,9 +545,16 @@ int a4l_ioctl_bufinfo(a4l_cxt_t * cxt, void *arg)
                                     &info, arg, sizeof(a4l_bufinfo_t)) != 0)
                return -EFAULT;
 
-       if (info.idx_subd >= dev->transfer.nb_subd ||
-           (dev->transfer.subds[info.idx_subd]->flags & A4L_SUBD_CMD) == 0) {
-               __a4l_err("a4l_ioctl_bufinfo: wrong subdevice selected\n");
+       /* Check the subdevice */
+       if (info.idx_subd >= dev->transfer.nb_subd) {
+               __a4l_err("a4l_ioctl_bufinfo: subdevice index "
+                         "out of range (idx=%d)\n", info.idx_subd);
+               return -EINVAL;
+       }
+
+       if ((dev->transfer.subds[info.idx_subd]->flags & A4L_SUBD_CMD) == 0) {
+               __a4l_err("a4l_ioctl_bufinfo: operation not supported, "
+                         "synchronous only subdevice\n");
                return -EINVAL;
        }
 
@@ -829,11 +850,6 @@ int a4l_select(a4l_cxt_t *cxt,
                return -ENOENT; 
        }
 
-       /* TODO: to be removed
-          Check the subdevice capabilities */
-       if ((dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD) == 0)
-               return -EINVAL;
-
        /* Performs a bind on the Analogy synchronization element */
        return a4l_select_sync(&(buf->sync), selector, type, fd_index); 
 }
@@ -856,10 +872,20 @@ int a4l_ioctl_poll(a4l_cxt_t * cxt, void *arg)
                                     &poll, arg, sizeof(a4l_poll_t)) != 0)
                return -EFAULT;
 
-       /* Checks the subdevice capabilities */
-       if ((dev->transfer.subds[poll.idx_subd]->flags &
-            A4L_SUBD_CMD) == 0 ||
-           (dev->transfer.subds[poll.idx_subd]->flags &
+       /* Check the subdevice */
+       if (poll.idx_subd >= dev->transfer.nb_subd) {
+               __a4l_err("a4l_poll: subdevice index out of range (idx=%d)\n", 
+                         buf_cfg.idx_subd);
+               return -EINVAL;
+       }
+
+       if ((dev->transfer.subds[poll.idx_subd]->flags & A4L_SUBD_CMD) == 0) {
+               __a4l_err("a4l_poll: operation not supported, "
+                         "synchronous only subdevice\n");
+               return -EINVAL;
+       }
+
+       if ((dev->transfer.subds[poll.idx_subd]->flags & 
             A4L_SUBD_MASK_SPECIAL) != 0) {
                __a4l_err("a4l_poll: wrong subdevice selected\n");
                return -EINVAL;
diff --git a/ksrc/drivers/analogy/command.c b/ksrc/drivers/analogy/command.c
index c4b42d7..2fb9344 100644
--- a/ksrc/drivers/analogy/command.c
+++ b/ksrc/drivers/analogy/command.c
@@ -98,19 +98,20 @@ int a4l_check_cmddesc(a4l_cxt_t * cxt, a4l_cmd_t * desc)
 
        if (desc->idx_subd >= dev->transfer.nb_subd) {
                __a4l_err("a4l_check_cmddesc: "
-                            "subdevice index out of range (%u >= %u)\n",
-                            desc->idx_subd, dev->transfer.nb_subd);
+                         "subdevice index out of range (%u >= %u)\n",
+                         desc->idx_subd, dev->transfer.nb_subd);
                return -EINVAL;
        }
 
        if (dev->transfer.subds[desc->idx_subd]->flags & A4L_SUBD_UNUSED) {
                __a4l_err("a4l_check_cmddesc: "
-                            "subdevice type incoherent\n");
+                         "subdevice type incoherent\n");
                return -EIO;
        }
 
        if (!(dev->transfer.subds[desc->idx_subd]->flags & A4L_SUBD_CMD)) {
-               __a4l_err("a4l_check_cmddesc: operation not supported\n");
+               __a4l_err("a4l_check_cmddesc: operation not supported, "
+                         "synchronous only subdevice\n");
                return -EIO;
        }
 
diff --git a/ksrc/drivers/analogy/device.c b/ksrc/drivers/analogy/device.c
index e702d6b..ca454f5 100644
--- a/ksrc/drivers/analogy/device.c
+++ b/ksrc/drivers/analogy/device.c
@@ -500,7 +500,7 @@ int a4l_ioctl_devinfo(a4l_cxt_t * cxt, void *arg)
 
        if (rtdm_safe_copy_to_user(cxt->user_info, 
                                   arg, &info, sizeof(a4l_dvinfo_t)) != 0)
-               return -EINVAL;
+               return -EFAULT;
 
        return 0;
 }
diff --git a/ksrc/drivers/analogy/instruction.c 
b/ksrc/drivers/analogy/instruction.c
index 1121d1f..3bd92d9 100644
--- a/ksrc/drivers/analogy/instruction.c
+++ b/ksrc/drivers/analogy/instruction.c
@@ -189,7 +189,7 @@ int a4l_do_insn(a4l_cxt_t * cxt, a4l_kinsn_t * dsc)
 
        /* Checks the subdevice index */
        if (dsc->idx_subd >= dev->transfer.nb_subd) {
-               __a4l_err("a4l_do_insn: bad subdevice index\n");
+               __a4l_err("a4l_do_insn: subdevice index out of range\n");
                return -EINVAL;
        }
 
diff --git a/ksrc/drivers/analogy/subdevice.c b/ksrc/drivers/analogy/subdevice.c
index a3cffc8..b1ea01d 100644
--- a/ksrc/drivers/analogy/subdevice.c
+++ b/ksrc/drivers/analogy/subdevice.c
@@ -231,7 +231,8 @@ int a4l_ioctl_nbchaninfo(a4l_cxt_t * cxt, void *arg)
                return -EFAULT;
 
        if (inarg.idx_subd >= dev->transfer.nb_subd) {
-               __a4l_err("a4l_ioctl_nbchaninfo: bad subdevice index\n");
+               __a4l_err("a4l_ioctl_nbchaninfo: subdevice index "
+                         "out of range\n");
                return -EINVAL;
        }
 
diff --git a/ksrc/drivers/analogy/transfer.c b/ksrc/drivers/analogy/transfer.c
index e3b85bf..d654329 100644
--- a/ksrc/drivers/analogy/transfer.c
+++ b/ksrc/drivers/analogy/transfer.c
@@ -448,6 +448,13 @@ int a4l_ioctl_cancel(a4l_cxt_t * cxt, void *arg)
        a4l_dev_t *dev = a4l_get_dev(cxt);
        a4l_subd_t *subd;
 
+       /* Basically check the device */
+       if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) {
+               __a4l_err("a4l_ioctl_cancel: operation not supported on "
+                         "an unattached device\n");
+               return -EINVAL;
+       }
+
        if (idx_subd >= dev->transfer.nb_subd) {
                __a4l_err("a4l_ioctl_cancel: bad subdevice index\n");
                return -EINVAL;
@@ -459,7 +466,8 @@ int a4l_ioctl_cancel(a4l_cxt_t * cxt, void *arg)
        }
 
        if (!(dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD)) {
-               __a4l_err("a4l_ioctl_cancel: synchronous only subdevice\n");
+               __a4l_err("a4l_ioctl_cancel: operation not supported, "
+                         "synchronous only subdevice\n");
                return -EIO;
        }
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to