[Xenomai-git] Alexis Berlemont : Add error messages for the IOCTL interface (attach, instruction, cmd, etc.)

2009-10-27 Thread GIT version control
Module: xenomai-abe
Branch: analogy
Commit: 39614e10be1d7fc5344b56646b8801cbf8756e08
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=39614e10be1d7fc5344b56646b8801cbf8756e08

Author: Alexis Berlemont 
Date:   Mon Oct 26 14:23:03 2009 +0100

Add error messages for the IOCTL interface (attach, instruction, cmd, etc.)

---

 ksrc/drivers/analogy/buffer.c  |  151 +---
 ksrc/drivers/analogy/command.c |   96 ++-
 ksrc/drivers/analogy/device.c  |   27 +--
 ksrc/drivers/analogy/instruction.c |   24 +-
 ksrc/drivers/analogy/subdevice.c   |   77 +-
 ksrc/drivers/analogy/transfer.c|   46 ---
 src/drvlib/analogy/sync.c  |   27 ---
 7 files changed, 328 insertions(+), 120 deletions(-)

diff --git a/ksrc/drivers/analogy/buffer.c b/ksrc/drivers/analogy/buffer.c
index 304791c..cad8a06 100644
--- a/ksrc/drivers/analogy/buffer.c
+++ b/ksrc/drivers/analogy/buffer.c
@@ -337,7 +337,7 @@ int a4l_buf_evt(a4l_subd_t *subd, unsigned long evts)
clear_bit(tmp, &evts);
}
 
-   /* Notifies the user-space side */
+   /* Notify the user-space side */
a4l_signal_sync(&buf->sync);
 
return 0;
@@ -376,7 +376,7 @@ open:a4l_map,
 close:a4l_unmap,
 };
 
-int a4l_ioctl_mmap(a4l_cxt_t * cxt, void *arg)
+int a4l_ioctl_mmap(a4l_cxt_t *cxt, void *arg)
 {
a4l_mmap_t map_cfg;
a4l_dev_t *dev;
@@ -387,34 +387,44 @@ int a4l_ioctl_mmap(a4l_cxt_t * cxt, void *arg)
 
dev = a4l_get_dev(cxt);
 
-   /* Basically checks the device */
-   if (!test_bit(A4L_DEV_ATTACHED, &dev->flags))
+   /* Basically check the device */
+   if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) {
+   __a4l_err("a4l_ioctl_mmap: cannot mmap on "
+ "an unattached device\n");
return -EINVAL;
+   }
 
/* The mmap operation cannot be performed in a 
   real-time context */
-   if (a4l_test_rt() != 0)
+   if (a4l_test_rt() != 0) {
+   __a4l_err("a4l_ioctl_mmap: mmap must be done in NRT context\n");
return -EPERM;
+   }
 
-   /* Recovers the argument structure */
+   /* Recover the argument structure */
if (rtdm_safe_copy_from_user(cxt->user_info,
 &map_cfg, arg, sizeof(a4l_mmap_t)) != 0)
return -EFAULT;
 
-   /* Checks the subdevice */
+   /* 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)
+   flags & A4L_SUBD_MMAP) == 0) {
+   __a4l_err("a4l_ioctl_mmap: wrong subdevice selected (idx=%d)\n",
+ map_cfg.idx_subd);
return -EINVAL;
+   }
 
-   /* Checks the buffer is not already mapped */
+   /* Check the buffer is not already mapped */
if (test_bit(A4L_TSF_MMAP,
-&(dev->transfer.status[map_cfg.idx_subd])))
+&(dev->transfer.status[map_cfg.idx_subd]))) {
+   __a4l_err("a4l_ioctl_mmap: mmap is already done\n");
return -EBUSY;
+   }
 
-   /* Basically checks the size to be mapped */
+   /* Basically check the size to be mapped */
if ((map_cfg.size & ~(PAGE_MASK)) != 0 ||
map_cfg.size > dev->transfer.bufs[map_cfg.idx_subd]->size)
return -EFAULT;
@@ -427,8 +437,11 @@ int a4l_ioctl_mmap(a4l_cxt_t * cxt, void *arg)
&a4l_vm_ops,
&(dev->transfer.status[map_cfg.idx_subd]));
 
-   if (ret < 0)
+   if (ret < 0) {
+   __a4l_err("a4l_ioctl_mmap: internal error, "
+ "rtdm_mmap_to_user failed (err=%d)\n", ret);
return ret;
+   }
 
return rtdm_safe_copy_to_user(cxt->user_info, 
  arg, &map_cfg, sizeof(a4l_mmap_t));
@@ -445,34 +458,49 @@ int a4l_ioctl_bufcfg(a4l_cxt_t * cxt, void *arg)
  "a4l_ioctl_bufcfg: minor=%d\n", a4l_get_minor(cxt));
 
/* Basic checking */
-   if (!test_bit(A4L_DEV_ATTACHED, &dev->flags))
+   if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) {
+   __a4l_err("a4l_ioctl_bufcfg: unattached device\n");
return -EINVAL;
+   }
 
/* As Linux API is used to allocate a virtual buffer,
   the calling process must not be in primary mode */
-   if (a4l_test_rt() != 0)
+   if (a4l_test_rt() != 0) {
+   __a4l_err("a4l_ioctl_bufcfg: buffer config must done "
+ "in NRT context\n");
return -EPERM;
+   }
 
if (rtdm_safe_copy_from_user(cxt->user_info,
 

[Xenomai-git] Alexis Berlemont : Add error messages for the IOCTL interface (attach, instruction, cmd, etc.)

2009-10-27 Thread GIT version control
Module: xenomai-abe
Branch: analogy
Commit: 00e387d26a51e28239d7e5d6684f41dd60ada6a9
URL:
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=00e387d26a51e28239d7e5d6684f41dd60ada6a9

Author: Alexis Berlemont 
Date:   Mon Oct 26 14:23:03 2009 +0100

Add error messages for the IOCTL interface (attach, instruction, cmd, etc.)

---

 ksrc/drivers/analogy/buffer.c  |  151 +---
 ksrc/drivers/analogy/command.c |   96 ++-
 ksrc/drivers/analogy/device.c  |   27 +--
 ksrc/drivers/analogy/instruction.c |   24 +-
 ksrc/drivers/analogy/subdevice.c   |   77 +-
 ksrc/drivers/analogy/transfer.c|   46 ---
 src/drvlib/analogy/sync.c  |   27 ---
 7 files changed, 328 insertions(+), 120 deletions(-)

diff --git a/ksrc/drivers/analogy/buffer.c b/ksrc/drivers/analogy/buffer.c
index 304791c..cad8a06 100644
--- a/ksrc/drivers/analogy/buffer.c
+++ b/ksrc/drivers/analogy/buffer.c
@@ -337,7 +337,7 @@ int a4l_buf_evt(a4l_subd_t *subd, unsigned long evts)
clear_bit(tmp, &evts);
}
 
-   /* Notifies the user-space side */
+   /* Notify the user-space side */
a4l_signal_sync(&buf->sync);
 
return 0;
@@ -376,7 +376,7 @@ open:a4l_map,
 close:a4l_unmap,
 };
 
-int a4l_ioctl_mmap(a4l_cxt_t * cxt, void *arg)
+int a4l_ioctl_mmap(a4l_cxt_t *cxt, void *arg)
 {
a4l_mmap_t map_cfg;
a4l_dev_t *dev;
@@ -387,34 +387,44 @@ int a4l_ioctl_mmap(a4l_cxt_t * cxt, void *arg)
 
dev = a4l_get_dev(cxt);
 
-   /* Basically checks the device */
-   if (!test_bit(A4L_DEV_ATTACHED, &dev->flags))
+   /* Basically check the device */
+   if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) {
+   __a4l_err("a4l_ioctl_mmap: cannot mmap on "
+ "an unattached device\n");
return -EINVAL;
+   }
 
/* The mmap operation cannot be performed in a 
   real-time context */
-   if (a4l_test_rt() != 0)
+   if (a4l_test_rt() != 0) {
+   __a4l_err("a4l_ioctl_mmap: mmap must be done in NRT context\n");
return -EPERM;
+   }
 
-   /* Recovers the argument structure */
+   /* Recover the argument structure */
if (rtdm_safe_copy_from_user(cxt->user_info,
 &map_cfg, arg, sizeof(a4l_mmap_t)) != 0)
return -EFAULT;
 
-   /* Checks the subdevice */
+   /* 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)
+   flags & A4L_SUBD_MMAP) == 0) {
+   __a4l_err("a4l_ioctl_mmap: wrong subdevice selected (idx=%d)\n",
+ map_cfg.idx_subd);
return -EINVAL;
+   }
 
-   /* Checks the buffer is not already mapped */
+   /* Check the buffer is not already mapped */
if (test_bit(A4L_TSF_MMAP,
-&(dev->transfer.status[map_cfg.idx_subd])))
+&(dev->transfer.status[map_cfg.idx_subd]))) {
+   __a4l_err("a4l_ioctl_mmap: mmap is already done\n");
return -EBUSY;
+   }
 
-   /* Basically checks the size to be mapped */
+   /* Basically check the size to be mapped */
if ((map_cfg.size & ~(PAGE_MASK)) != 0 ||
map_cfg.size > dev->transfer.bufs[map_cfg.idx_subd]->size)
return -EFAULT;
@@ -427,8 +437,11 @@ int a4l_ioctl_mmap(a4l_cxt_t * cxt, void *arg)
&a4l_vm_ops,
&(dev->transfer.status[map_cfg.idx_subd]));
 
-   if (ret < 0)
+   if (ret < 0) {
+   __a4l_err("a4l_ioctl_mmap: internal error, "
+ "rtdm_mmap_to_user failed (err=%d)\n", ret);
return ret;
+   }
 
return rtdm_safe_copy_to_user(cxt->user_info, 
  arg, &map_cfg, sizeof(a4l_mmap_t));
@@ -445,34 +458,49 @@ int a4l_ioctl_bufcfg(a4l_cxt_t * cxt, void *arg)
  "a4l_ioctl_bufcfg: minor=%d\n", a4l_get_minor(cxt));
 
/* Basic checking */
-   if (!test_bit(A4L_DEV_ATTACHED, &dev->flags))
+   if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) {
+   __a4l_err("a4l_ioctl_bufcfg: unattached device\n");
return -EINVAL;
+   }
 
/* As Linux API is used to allocate a virtual buffer,
   the calling process must not be in primary mode */
-   if (a4l_test_rt() != 0)
+   if (a4l_test_rt() != 0) {
+   __a4l_err("a4l_ioctl_bufcfg: buffer config must done "
+ "in NRT context\n");
return -EPERM;
+   }
 
if (rtdm_safe_copy_from_user(cxt->user_info,