Module: xenomai-head Branch: master Commit: fe9f70a8eca2521dfa54c92b3ebd84052ea0f7f3 URL: http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=fe9f70a8eca2521dfa54c92b3ebd84052ea0f7f3
Author: Alexis Berlemont <alexis.berlem...@gmail.com> Date: Mon Oct 26 14:23:03 2009 +0100 analogy: add error messages for the IOCTL interface --- 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, &buf_cfg, arg, sizeof(a4l_bufcfg_t)) != 0) return -EFAULT; - if (buf_cfg.idx_subd >= dev->transfer.nb_subd) + 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"); return -EINVAL; + } - if (buf_cfg.buf_size > A4L_BUF_MAXSIZE) + if (buf_cfg.buf_size > A4L_BUF_MAXSIZE) { + __a4l_err("a4l_ioctl_bufcfg: buffer size too big (<=16MB)\n"); return -EINVAL; + } /* If a transfer is occuring or if the buffer is mmapped, no buffer size change is allowed */ if (test_bit(A4L_TSF_BUSY, - &(dev->transfer.status[buf_cfg.idx_subd]))) + &(dev->transfer.status[buf_cfg.idx_subd]))) { + __a4l_err("a4l_ioctl_bufcfg: buffer size too big (<=16MB)\n"); return -EBUSY; + } if (test_bit(A4L_TSF_MMAP, - &(dev->transfer.status[buf_cfg.idx_subd]))) + &(dev->transfer.status[buf_cfg.idx_subd]))) { + __a4l_err("a4l_ioctl_bufcfg: please unmap before " + "configuring buffer\n"); return -EPERM; + } /* Performs the re-allocation */ a4l_free_buffer(dev->transfer.bufs[buf_cfg.idx_subd]); @@ -494,18 +522,20 @@ int a4l_ioctl_bufinfo(a4l_cxt_t * cxt, void *arg) "a4l_ioctl_bufinfo: 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_bufinfo: unattached device\n"); return -EINVAL; + } if (rtdm_safe_copy_from_user(cxt->user_info, &info, arg, sizeof(a4l_bufinfo_t)) != 0) return -EFAULT; - if (info.idx_subd > dev->transfer.nb_subd) - return -EINVAL; - - if ((dev->transfer.subds[info.idx_subd]->flags & A4L_SUBD_CMD) == 0) + 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"); return -EINVAL; + } buf = dev->transfer.bufs[info.idx_subd]; @@ -555,8 +585,10 @@ int a4l_ioctl_bufinfo(a4l_cxt_t * cxt, void *arg) "a4l_ioctl_bufinfo: count to write=%lu\n", info.rw_count); - } else + } else { + __a4l_err("a4l_ioctl_bufinfo: wrong subdevice selected\n"); return -EINVAL; + } /* Performs the munge if need be */ if (dev->transfer.subds[info.idx_subd]->munge != NULL) { @@ -587,25 +619,32 @@ ssize_t a4l_read(a4l_cxt_t * cxt, void *bufdata, size_t nbytes) ssize_t count = 0; /* Basic checkings */ - if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_read: unattached device\n"); return -EINVAL; + } - if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]))) + if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]))) { + __a4l_err("a4l_read: idle subdevice\n"); return -ENOENT; + } - /* Checks the subdevice capabilities */ - if ((dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD) == 0) + /* TODO: to be removed + Check the subdevice capabilities */ + if ((dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD) == 0) { + __a4l_err("a4l_read: incoherent state\n"); return -EINVAL; + } while (count < nbytes) { - /* Checks the events */ + /* Check the events */ int ret = __handle_event(buf); - /* Computes the data amount to copy */ + /* Compute the data amount to copy */ unsigned long tmp_cnt = __count_to_get(buf); - /* Checks tmp_cnt count is not higher than + /* Check tmp_cnt count is not higher than the global count to read */ if (tmp_cnt > nbytes - count) tmp_cnt = nbytes - count; @@ -676,25 +715,32 @@ ssize_t a4l_write(a4l_cxt_t *cxt, ssize_t count = 0; /* Basic checkings */ - if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_write: unattached device\n"); return -EINVAL; + } - if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]))) + if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]))) { + __a4l_err("a4l_write: idle subdevice\n"); return -ENOENT; + } - /* Checks the subdevice capabilities */ - if ((dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD) == 0) + /* TODO: to be removed + Check the subdevice capabilities */ + if ((dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD) == 0) { + __a4l_err("a4l_write: incoherent state\n"); return -EINVAL; + } while (count < nbytes) { - /* Checks the events */ + /* Check the events */ int ret = __handle_event(buf); - /* Computes the data amount to copy */ + /* Compute the data amount to copy */ unsigned long tmp_cnt = __count_to_put(buf); - /* Checks tmp_cnt count is not higher than + /* Check tmp_cnt count is not higher than the global count to write */ if (tmp_cnt > nbytes - count) tmp_cnt = nbytes - count; @@ -764,20 +810,27 @@ int a4l_select(a4l_cxt_t *cxt, dev->transfer.idx_write_subd; a4l_buf_t *buf = dev->transfer.bufs[idx_subd]; - /* Checks the RTDM select type + /* Check the RTDM select type (RTDM_SELECTTYPE_EXCEPT is not supported) */ if(type != RTDM_SELECTTYPE_READ && - type != RTDM_SELECTTYPE_WRITE) + type != RTDM_SELECTTYPE_WRITE) { + __a4l_err("a4l_select: wrong select argument\n"); return -EINVAL; + } /* Basic checkings */ - if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_select: unattached device\n"); return -EINVAL; + } - if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]))) + if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]))) { + __a4l_err("a4l_select: idle subdevice\n"); return -ENOENT; + } - /* Checks the subdevice capabilities */ + /* TODO: to be removed + Check the subdevice capabilities */ if ((dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD) == 0) return -EINVAL; @@ -794,8 +847,10 @@ int a4l_ioctl_poll(a4l_cxt_t * cxt, void *arg) a4l_poll_t poll; /* Basic checking */ - if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_poll: unattached device\n"); return -EINVAL; + } if (rtdm_safe_copy_from_user(cxt->user_info, &poll, arg, sizeof(a4l_poll_t)) != 0) @@ -805,12 +860,16 @@ int a4l_ioctl_poll(a4l_cxt_t * cxt, void *arg) if ((dev->transfer.subds[poll.idx_subd]->flags & A4L_SUBD_CMD) == 0 || (dev->transfer.subds[poll.idx_subd]->flags & - A4L_SUBD_MASK_SPECIAL) != 0) + A4L_SUBD_MASK_SPECIAL) != 0) { + __a4l_err("a4l_poll: wrong subdevice selected\n"); return -EINVAL; + } /* Checks a transfer is occuring */ - if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[poll.idx_subd]))) + if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[poll.idx_subd]))) { + __a4l_err("a4l_poll: idle subdevice\n"); return -EINVAL; + } buf = dev->transfer.bufs[poll.idx_subd]; diff --git a/ksrc/drivers/analogy/command.c b/ksrc/drivers/analogy/command.c index fb6f07a..c4b42d7 100644 --- a/ksrc/drivers/analogy/command.c +++ b/ksrc/drivers/analogy/command.c @@ -136,66 +136,96 @@ int a4l_check_generic_cmdcnt(a4l_cmd_t * desc) tmp1 = desc->start_src & ~(TRIG_NOW | TRIG_INT | TRIG_EXT | TRIG_FOLLOW); tmp2 = desc->start_src & (TRIG_NOW | TRIG_INT | TRIG_EXT | TRIG_FOLLOW); - if (tmp1 != 0 || tmp2 == 0) + if (tmp1 != 0 || tmp2 == 0) { + __a4l_err("a4l_check_cmddesc: start_src, weird trigger\n"); return -EINVAL; + } tmp1 = desc->scan_begin_src & ~(TRIG_TIMER | TRIG_EXT | TRIG_FOLLOW); tmp2 = desc->scan_begin_src & (TRIG_TIMER | TRIG_EXT | TRIG_FOLLOW); - if (tmp1 != 0 || tmp2 == 0) + if (tmp1 != 0 || tmp2 == 0) { + __a4l_err("a4l_check_cmddesc: scan_begin_src, , weird trigger\n"); return -EINVAL; + } tmp1 = desc->convert_src & ~(TRIG_TIMER | TRIG_EXT | TRIG_NOW); tmp2 = desc->convert_src & (TRIG_TIMER | TRIG_EXT | TRIG_NOW); - if (tmp1 != 0 || tmp2 == 0) + if (tmp1 != 0 || tmp2 == 0) { + __a4l_err("a4l_check_cmddesc: convert_src, weird trigger\n"); return -EINVAL; + } tmp1 = desc->scan_end_src & ~(TRIG_COUNT); - if (tmp1 != 0) + if (tmp1 != 0) { + __a4l_err("a4l_check_cmddesc: scan_end_src, weird trigger\n"); return -EINVAL; + } tmp1 = desc->stop_src & ~(TRIG_COUNT | TRIG_NONE); tmp2 = desc->stop_src & (TRIG_COUNT | TRIG_NONE); - if (tmp1 != 0 || tmp2 == 0) + if (tmp1 != 0 || tmp2 == 0) { + __a4l_err("a4l_check_cmddesc: stop_src, weird trigger\n"); return -EINVAL; + } /* Makes sure trigger sources are unique */ if (desc->start_src != TRIG_NOW && desc->start_src != TRIG_INT && - desc->start_src != TRIG_EXT && desc->start_src != TRIG_FOLLOW) + desc->start_src != TRIG_EXT && desc->start_src != TRIG_FOLLOW) { + __a4l_err("a4l_check_cmddesc: start_src, " + "only one trigger should be set\n"); return -EINVAL; + } if (desc->scan_begin_src != TRIG_TIMER && desc->scan_begin_src != TRIG_EXT && - desc->scan_begin_src != TRIG_FOLLOW) + desc->scan_begin_src != TRIG_FOLLOW) { + __a4l_err("a4l_check_cmddesc: scan_begin_src, " + "only one trigger should be set\n"); return -EINVAL; + } if (desc->convert_src != TRIG_TIMER && - desc->convert_src != TRIG_EXT && desc->convert_src != TRIG_NOW) + desc->convert_src != TRIG_EXT && desc->convert_src != TRIG_NOW) { + __a4l_err("a4l_check_cmddesc: convert_src, " + "only one trigger should be set\n"); return -EINVAL; + } - if (desc->stop_src != TRIG_COUNT && desc->stop_src != TRIG_NONE) + if (desc->stop_src != TRIG_COUNT && desc->stop_src != TRIG_NONE) { + __a4l_err("a4l_check_cmddesc: stop_src, " + "only one trigger should be set\n"); return -EINVAL; + } /* Makes sure arguments are trivially compatible */ tmp1 = desc->start_src & (TRIG_NOW | TRIG_FOLLOW | TRIG_INT); tmp2 = desc->start_arg; - if (tmp1 != 0 && tmp2 != 0) + if (tmp1 != 0 && tmp2 != 0) { + __a4l_err("a4l_check_cmddesc: no start_arg expected\n"); return -EINVAL; + } tmp1 = desc->scan_begin_src & TRIG_FOLLOW; tmp2 = desc->scan_begin_arg; - if (tmp1 != 0 && tmp2 != 0) + if (tmp1 != 0 && tmp2 != 0) { + __a4l_err("a4l_check_cmddesc: no scan_begin_arg expected\n"); return -EINVAL; + } tmp1 = desc->convert_src & TRIG_NOW; tmp2 = desc->convert_arg; - if (tmp1 != 0 && tmp2 != 0) + if (tmp1 != 0 && tmp2 != 0) { + __a4l_err("a4l_check_cmddesc: no convert_arg expected\n"); return -EINVAL; + } tmp1 = desc->stop_src & TRIG_NONE; tmp2 = desc->stop_arg; - if (tmp1 != 0 && tmp2 != 0) + if (tmp1 != 0 && tmp2 != 0) { + __a4l_err("a4l_check_cmddesc: no stop_arg expected\n"); return -EINVAL; + } return 0; } @@ -212,35 +242,50 @@ int a4l_check_specific_cmdcnt(a4l_cxt_t * cxt, a4l_cmd_t * desc) if (cmd_mask->start_src != 0) { tmp1 = desc->start_src & ~(cmd_mask->start_src); tmp2 = desc->start_src & (cmd_mask->start_src); - if (tmp1 != 0 || tmp2 == 0) + if (tmp1 != 0 || tmp2 == 0) { + __a4l_err("a4l_check_cmddesc: start_src, " + "trigger unsupported\n"); return -EINVAL; + } } if (cmd_mask->scan_begin_src != 0) { tmp1 = desc->scan_begin_src & ~(cmd_mask->scan_begin_src); tmp2 = desc->scan_begin_src & (cmd_mask->scan_begin_src); - if (tmp1 != 0 || tmp2 == 0) + if (tmp1 != 0 || tmp2 == 0) { + __a4l_err("a4l_check_cmddesc: scan_begin_src, " + "trigger unsupported\n"); return -EINVAL; + } } if (cmd_mask->convert_src != 0) { tmp1 = desc->convert_src & ~(cmd_mask->convert_src); tmp2 = desc->convert_src & (cmd_mask->convert_src); - if (tmp1 != 0 || tmp2 == 0) + if (tmp1 != 0 || tmp2 == 0) { + __a4l_err("a4l_check_cmddesc: convert_src, " + "trigger unsupported\n"); return -EINVAL; + } } if (cmd_mask->scan_end_src != 0) { tmp1 = desc->scan_end_src & ~(cmd_mask->scan_end_src); - if (tmp1 != 0) + if (tmp1 != 0) { + __a4l_err("a4l_check_cmddesc: scan_end_src, " + "trigger unsupported\n"); return -EINVAL; + } } if (cmd_mask->stop_src != 0) { tmp1 = desc->stop_src & ~(cmd_mask->stop_src); tmp2 = desc->stop_src & (cmd_mask->stop_src); - if (tmp1 != 0 || tmp2 == 0) + if (tmp1 != 0 || tmp2 == 0) { + __a4l_err("a4l_check_cmddesc: stop_src, " + "trigger unsupported\n"); return -EINVAL; + } } return 0; @@ -255,7 +300,14 @@ int a4l_ioctl_cmd(a4l_cxt_t * cxt, void *arg) a4l_dev_t *dev = a4l_get_dev(cxt); __a4l_dbg(1, core_dbg, - "a4l_ioctl_cmd: minor=%d\n", a4l_get_minor(cxt)); + "a4l_ioctl_cmd: minor=%d\n", a4l_get_minor(cxt)); + + /* Basically check the device */ + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_ioctl_cmd: cannot command " + "an unattached device\n"); + return -EINVAL; + } /* Allocates the command */ cmd_desc = (a4l_cmd_t *) rtdm_malloc(sizeof(a4l_cmd_t)); @@ -281,6 +333,9 @@ int a4l_ioctl_cmd(a4l_cxt_t * cxt, void *arg) if (ret != 0) goto out_ioctl_cmd; + __a4l_dbg(1, core_dbg, + "a4l_ioctl_cmd: 1st cmd checks passed\n"); + /* Tests the command with the cmdtest function */ if (dev->transfer.subds[cmd_desc->idx_subd]->do_cmdtest != NULL) ret = dev->transfer.subds[cmd_desc->idx_subd]-> @@ -289,6 +344,9 @@ int a4l_ioctl_cmd(a4l_cxt_t * cxt, void *arg) if (ret != 0) goto out_ioctl_cmd; + __a4l_dbg(1, core_dbg, + "a4l_ioctl_cmd: driver's cmd checks passed\n"); + if (cmd_desc->flags & A4L_CMD_SIMUL) { simul_flag = 1; goto out_ioctl_cmd; diff --git a/ksrc/drivers/analogy/device.c b/ksrc/drivers/analogy/device.c index faa2972..e702d6b 100644 --- a/ksrc/drivers/analogy/device.c +++ b/ksrc/drivers/analogy/device.c @@ -196,7 +196,7 @@ void a4l_proc_detach(a4l_cxt_t * cxt) /* --- Attach / detach section --- */ int a4l_fill_lnkdesc(a4l_cxt_t * cxt, - a4l_lnkdesc_t * link_arg, void *arg) + a4l_lnkdesc_t * link_arg, void *arg) { int ret; char *tmpname = NULL; @@ -330,8 +330,11 @@ int a4l_assign_driver(a4l_cxt_t * cxt, out_assign_driver: /* Increments module's count */ - if (ret == 0 && (!try_module_get(drv->owner))) + if (ret == 0 && (!try_module_get(drv->owner))) { + __a4l_err("a4l_assign_driver: " + "driver's owner field wrongly set\n"); ret = -ENODEV; + } if (ret != 0 && dev->priv != NULL) { rtdm_free(dev->priv); @@ -390,8 +393,11 @@ int a4l_device_attach(a4l_cxt_t * cxt, void *arg) if ((ret = a4l_fill_lnkdesc(cxt, &link_arg, arg)) != 0) goto out_attach; - if ((ret = a4l_lct_drv(link_arg.bname, &drv)) != 0) + if ((ret = a4l_lct_drv(link_arg.bname, &drv)) != 0) { + __a4l_err("a4l_device_attach: " + "cannot find board name %s\n", link_arg.bname); goto out_attach; + } if ((ret = a4l_assign_driver(cxt, drv, &link_arg)) != 0) goto out_attach; @@ -408,8 +414,11 @@ int a4l_device_detach(a4l_cxt_t * cxt) __a4l_dbg(1, core_dbg, "a4l_device_detach: minor=%d\n", a4l_get_minor(cxt)); - if (dev->driver == NULL) + if (dev->driver == NULL) { + __a4l_err("a4l_device_detach: " + "incoherent state, driver not reachable\n"); return -ENXIO; + } return a4l_release_driver(cxt); } @@ -429,8 +438,11 @@ int a4l_ioctl_devcfg(a4l_cxt_t * cxt, void *arg) if (arg == NULL) { /* Basic checking */ if (!test_bit - (A4L_DEV_ATTACHED, &(a4l_get_dev(cxt)->flags))) + (A4L_DEV_ATTACHED, &(a4l_get_dev(cxt)->flags))) { + __a4l_err("a4l_ioctl_devcfg: " + "free device, no driver to detach\n"); return -EINVAL; + } /* Removes the related proc file */ a4l_proc_detach(cxt); /* Frees the transfer structure and its related data */ @@ -443,8 +455,11 @@ int a4l_ioctl_devcfg(a4l_cxt_t * cxt, void *arg) } else { /* Basic checking */ if (test_bit - (A4L_DEV_ATTACHED, &(a4l_get_dev(cxt)->flags))) + (A4L_DEV_ATTACHED, &(a4l_get_dev(cxt)->flags))) { + __a4l_err("a4l_ioctl_devcfg: " + "linked device, cannot attach more driver\n"); return -EINVAL; + } /* Pre-initialization of the transfer structure */ a4l_presetup_transfer(cxt); /* Links the device with the driver */ diff --git a/ksrc/drivers/analogy/instruction.c b/ksrc/drivers/analogy/instruction.c index d1fc39d..41fd1b7 100644 --- a/ksrc/drivers/analogy/instruction.c +++ b/ksrc/drivers/analogy/instruction.c @@ -173,6 +173,8 @@ int a4l_do_special_insn(a4l_cxt_t * cxt, a4l_kinsn_t * dsc) ret = a4l_do_insn_trig(cxt, dsc); break; default: + __a4l_err("a4l_do_special_insn: " + "incoherent instruction code\n"); ret = -EINVAL; } @@ -186,16 +188,20 @@ int a4l_do_insn(a4l_cxt_t * cxt, a4l_kinsn_t * dsc) a4l_dev_t *dev = a4l_get_dev(cxt); /* Checks the subdevice index */ - if (dsc->idx_subd >= dev->transfer.nb_subd) + if (dsc->idx_subd >= dev->transfer.nb_subd) { + __a4l_err("a4l_do_insn: bad subdevice index\n"); return -EINVAL; + } /* Recovers pointers on the proper subdevice */ subd = dev->transfer.subds[dsc->idx_subd]; /* Checks the subdevice's characteristics */ if (((subd->flags & A4L_SUBD_UNUSED) != 0) || - ((subd->flags & A4L_SUBD_CMD) == 0)) + ((subd->flags & A4L_SUBD_CMD) == 0)) { + __a4l_err("a4l_do_insn: wrong subdevice selected\n"); return -EINVAL; + } /* Checks the channel descriptor */ ret = a4l_check_chanlist(dev->transfer.subds[dsc->idx_subd], @@ -239,6 +245,13 @@ int a4l_ioctl_insn(a4l_cxt_t * cxt, void *arg) { int ret = 0; a4l_kinsn_t insn; + a4l_dev_t *dev = a4l_get_dev(cxt); + + /* Basic checking */ + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_ioctl_insn: unattached device\n"); + return -EINVAL; + } /* Recovers the instruction descriptor */ ret = a4l_fill_insndsc(cxt, &insn, arg); @@ -329,6 +342,13 @@ int a4l_ioctl_insnlist(a4l_cxt_t * cxt, void *arg) { int i, ret = 0; a4l_kilst_t ilst; + a4l_dev_t *dev = a4l_get_dev(cxt); + + /* Basic checking */ + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_ioctl_insnlist: unattached device\n"); + return -EINVAL; + } if ((ret = a4l_fill_ilstdsc(cxt, &ilst, arg)) < 0) return ret; diff --git a/ksrc/drivers/analogy/subdevice.c b/ksrc/drivers/analogy/subdevice.c index 540c29e..a3cffc8 100644 --- a/ksrc/drivers/analogy/subdevice.c +++ b/ksrc/drivers/analogy/subdevice.c @@ -88,10 +88,9 @@ int a4l_check_chanlist(a4l_subd_t * subd, return -EINVAL; for (i = 0; i < nb_chan; i++) { - int j = - (subd->rng_desc->mode != A4L_RNG_GLOBAL_RNGDESC) ? i : 0; - int k = - (subd->chan_desc->mode != + int j = (subd->rng_desc->mode != + A4L_RNG_GLOBAL_RNGDESC) ? i : 0; + int k = (subd->chan_desc->mode != A4L_CHAN_GLOBAL_CHANDESC) ? i : 0; if (CR_CHAN(chans[i]) >= subd->chan_desc->length) { @@ -185,11 +184,13 @@ int a4l_ioctl_subdinfo(a4l_cxt_t * cxt, void *arg) a4l_sbinfo_t *subd_info; /* Basic checking */ - if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_ioctl_subdinfo: unattached device\n"); return -EINVAL; + } - subd_info = - rtdm_malloc(dev->transfer.nb_subd * sizeof(a4l_sbinfo_t)); + subd_info = rtdm_malloc(dev->transfer.nb_subd * + sizeof(a4l_sbinfo_t)); if (subd_info == NULL) return -ENOMEM; @@ -219,16 +220,20 @@ int a4l_ioctl_nbchaninfo(a4l_cxt_t * cxt, void *arg) a4l_chinfo_arg_t inarg; /* Basic checking */ - if (!dev->flags & A4L_DEV_ATTACHED) + if (!dev->flags & A4L_DEV_ATTACHED) { + __a4l_err("a4l_ioctl_nbchaninfo: unattached device\n"); return -EINVAL; + } if (rtdm_safe_copy_from_user(cxt->user_info, &inarg, arg, sizeof(a4l_chinfo_arg_t)) != 0) return -EFAULT; - if (inarg.idx_subd >= dev->transfer.nb_subd) + if (inarg.idx_subd >= dev->transfer.nb_subd) { + __a4l_err("a4l_ioctl_nbchaninfo: bad subdevice index\n"); return -EINVAL; + } if(dev->transfer.subds[inarg.idx_subd]->chan_desc == NULL) inarg.info = (void *)0; @@ -254,22 +259,29 @@ int a4l_ioctl_chaninfo(a4l_cxt_t * cxt, void *arg) a4l_rngdesc_t *rng_desc; /* Basic checking */ - if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_ioctl_chaninfo: unattached device\n"); return -EINVAL; + } if (rtdm_safe_copy_from_user(cxt->user_info, &inarg, arg, sizeof(a4l_chinfo_arg_t)) != 0) return -EFAULT; - if (inarg.idx_subd >= dev->transfer.nb_subd) - return -EINVAL; + if (inarg.idx_subd >= dev->transfer.nb_subd) { + __a4l_err("a4l_ioctl_chaninfo: bad subdevice index\n"); + return -EINVAL; + } chan_desc = dev->transfer.subds[inarg.idx_subd]->chan_desc; rng_desc = dev->transfer.subds[inarg.idx_subd]->rng_desc; - if (chan_desc == NULL) + if (chan_desc == NULL) { + __a4l_err("a4l_ioctl_chaninfo: no channel descriptor " + "for subdevice %d\n", inarg.idx_subd); return -EINVAL; + } if(rng_desc == NULL) rng_desc = &range_fake; @@ -313,23 +325,32 @@ int a4l_ioctl_nbrnginfo(a4l_cxt_t * cxt, void *arg) a4l_rngdesc_t *rng_desc; /* Basic checking */ - if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_ioctl_nbrnginfo: unattached device\n"); return -EINVAL; + } if (rtdm_safe_copy_from_user(cxt->user_info, &inarg, arg, sizeof(a4l_rnginfo_arg_t)) != 0) return -EFAULT; - if (inarg.idx_subd >= dev->transfer.nb_subd) + if (inarg.idx_subd >= dev->transfer.nb_subd) { + __a4l_err("a4l_ioctl_nbrnginfo: bad subdevice index\n"); return -EINVAL; + } - if (dev->transfer.subds[inarg.idx_subd]->chan_desc == NULL) + if (dev->transfer.subds[inarg.idx_subd]->chan_desc == NULL) { + __a4l_err("a4l_ioctl_nbrnginfo: no channel descriptor " + "for subdevice %d\n", inarg.idx_subd); return -EINVAL; + } if (inarg.idx_chan >= - dev->transfer.subds[inarg.idx_subd]->chan_desc->length) + dev->transfer.subds[inarg.idx_subd]->chan_desc->length) { + __a4l_err("a4l_ioctl_nbrnginfo: bad channel index\n"); return -EINVAL; + } rng_desc = dev->transfer.subds[inarg.idx_subd]->rng_desc; if (rng_desc != NULL) { @@ -359,27 +380,39 @@ int a4l_ioctl_rnginfo(a4l_cxt_t * cxt, void *arg) a4l_rnginfo_arg_t inarg; /* Basic checking */ - if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) + if (!test_bit(A4L_DEV_ATTACHED, &dev->flags)) { + __a4l_err("a4l_ioctl_rnginfo: unattached device\n"); return -EINVAL; + } if (rtdm_safe_copy_from_user(cxt->user_info, &inarg, arg, sizeof(a4l_rnginfo_arg_t)) != 0) return -EFAULT; - if (inarg.idx_subd >= dev->transfer.nb_subd) + if (inarg.idx_subd >= dev->transfer.nb_subd) { + __a4l_err("a4l_ioctl_rnginfo: bad subdevice index\n"); return -EINVAL; + } - if (dev->transfer.subds[inarg.idx_subd]->chan_desc == NULL) + if (dev->transfer.subds[inarg.idx_subd]->chan_desc == NULL) { + __a4l_err("a4l_ioctl_rnginfo: no channel descriptor " + "for subdevice %d\n", inarg.idx_subd); return -EINVAL; + } if (inarg.idx_chan >= - dev->transfer.subds[inarg.idx_subd]->chan_desc->length) + dev->transfer.subds[inarg.idx_subd]->chan_desc->length) { + __a4l_err("a4l_ioctl_rnginfo: bad channel index\n"); return -EINVAL; + } rng_desc = dev->transfer.subds[inarg.idx_subd]->rng_desc; - if (rng_desc == NULL) + if (rng_desc == NULL) { + __a4l_err("a4l_ioctl_rnginfo: no range descriptor " + "for channel %d\n", inarg.idx_chan); return -EINVAL; + } /* If the range descriptor is global, we take the first instance */ diff --git a/ksrc/drivers/analogy/transfer.c b/ksrc/drivers/analogy/transfer.c index ea573a7..e3b85bf 100644 --- a/ksrc/drivers/analogy/transfer.c +++ b/ksrc/drivers/analogy/transfer.c @@ -46,15 +46,24 @@ int a4l_cleanup_transfer(a4l_cxt_t * cxt) dev = a4l_get_dev(cxt); tsf = &dev->transfer; - if (tsf == NULL) + if (tsf == NULL) { + __a4l_err("a4l_cleanup_transfer: " + "incoherent status, transfer block not reachable\n"); return -ENODEV; + } for (i = 0; i < tsf->nb_subd; i++) { - if (test_bit(A4L_TSF_BUSY, &(tsf->status[i]))) + if (test_bit(A4L_TSF_BUSY, &(tsf->status[i]))) { + __a4l_err("a4l_cleanup_transfer: " + "device busy, acquisition occuring\n"); return EBUSY; + } - if (test_bit(A4L_TSF_MMAP, &(tsf->status[i]))) + if (test_bit(A4L_TSF_MMAP, &(tsf->status[i]))) { + __a4l_err("a4l_cleanup_transfer: " + "device busy, buffer must be unmapped\n"); return -EPERM; + } } /* Releases the various buffers */ @@ -128,7 +137,7 @@ int a4l_setup_transfer(a4l_cxt_t * cxt) /* Allocates a suitable tab for the subdevices */ tsf->subds = rtdm_malloc(tsf->nb_subd * sizeof(a4l_subd_t *)); if (tsf->subds == NULL) { - __a4l_err("a4l_setup_transfer: call2(alloc) failed \n"); + __a4l_err("a4l_setup_transfer: call1(alloc) failed \n"); ret = -ENOMEM; goto out_setup_tsf; } @@ -149,6 +158,7 @@ int a4l_setup_transfer(a4l_cxt_t * cxt) /* Allocates various buffers */ tsf->bufs = rtdm_malloc(tsf->nb_subd * sizeof(a4l_buf_t *)); if (tsf->bufs == NULL) { + __a4l_err("a4l_setup_transfer: call2(alloc) failed \n"); ret = -ENOMEM; goto out_setup_tsf; } @@ -159,7 +169,7 @@ int a4l_setup_transfer(a4l_cxt_t * cxt) tsf->bufs[i] = rtdm_malloc(sizeof(a4l_buf_t)); if (tsf->bufs[i] == NULL) { __a4l_err("a4l_setup_transfer: " - "call5-6(alloc) failed \n"); + "call3(alloc) failed \n"); ret = -ENOMEM; goto out_setup_tsf; } @@ -174,7 +184,7 @@ int a4l_setup_transfer(a4l_cxt_t * cxt) tsf->status = rtdm_malloc(tsf->nb_subd * sizeof(unsigned long)); if (tsf->status == NULL) { - __a4l_err("a4l_setup_transfer: call8(alloc) failed \n"); + __a4l_err("a4l_setup_transfer: call4(alloc) failed \n"); ret = -ENOMEM; } @@ -197,8 +207,10 @@ int a4l_reserve_transfer(a4l_cxt_t * cxt, int idx_subd) a4l_get_minor(cxt), idx_subd); if (test_and_set_bit(A4L_TSF_BUSY, - &(dev->transfer.status[idx_subd]))) + &(dev->transfer.status[idx_subd]))) { + __a4l_err("a4l_reserve_transfer: device currently busy\n"); return -EBUSY; + } return 0; } @@ -311,8 +323,10 @@ int a4l_request_irq(a4l_dev_t * dev, ret = __a4l_request_irq(&dev->transfer.irq_desc, irq, handler, flags, cookie); - if (ret != 0) + if (ret != 0) { + __a4l_err("a4l_request_irq: IRQ registration failed\n"); dev->transfer.irq_desc.irq = A4L_IRQ_UNUSED; + } a4l_unlock_irqrestore(&dev->lock, __flags); @@ -434,19 +448,27 @@ int a4l_ioctl_cancel(a4l_cxt_t * cxt, void *arg) a4l_dev_t *dev = a4l_get_dev(cxt); a4l_subd_t *subd; - if (idx_subd >= dev->transfer.nb_subd) + if (idx_subd >= dev->transfer.nb_subd) { + __a4l_err("a4l_ioctl_cancel: bad subdevice index\n"); return -EINVAL; + } - if (dev->transfer.subds[idx_subd]->flags & A4L_SUBD_UNUSED) + if (dev->transfer.subds[idx_subd]->flags & A4L_SUBD_UNUSED) { + __a4l_err("a4l_ioctl_cancel: non functional subdevice\n"); return -EIO; + } - if (!(dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD)) + if (!(dev->transfer.subds[idx_subd]->flags & A4L_SUBD_CMD)) { + __a4l_err("a4l_ioctl_cancel: synchronous only subdevice\n"); return -EIO; + } subd = dev->transfer.subds[idx_subd]; - if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]))) + if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]))) { + __a4l_err("a4l_ioctl_cancel: subdevice currently idle\n"); return -EINVAL; + } return a4l_cancel_transfer(cxt, idx_subd); } diff --git a/src/drvlib/analogy/sync.c b/src/drvlib/analogy/sync.c index 23191ac..51d2d9b 100644 --- a/src/drvlib/analogy/sync.c +++ b/src/drvlib/analogy/sync.c @@ -122,17 +122,18 @@ int a4l_sync_write(a4l_desc_t * dsc, int ret; a4l_insn_t insn_tab[2] = { { - type:A4L_INSN_WRITE, - idx_subd:idx_subd, - chan_desc:chan_desc, - data_size:0, - data:buf}, - { - type:A4L_INSN_WAIT, - idx_subd:idx_subd, - chan_desc:chan_desc, - data_size:1, - data:NULL} + .type = A4L_INSN_WRITE, + .idx_subd = idx_subd, + .chan_desc = chan_desc, + .data_size = 0, + .data = buf + }, { + .type = A4L_INSN_WAIT, + .idx_subd = idx_subd, + .chan_desc = chan_desc, + .data_size = 1, + .data = NULL + } }; /* If some delay needs to be applied, @@ -141,8 +142,8 @@ int a4l_sync_write(a4l_desc_t * dsc, int ret; lsampl_t _delay = (lsampl_t) ns_delay; a4l_insnlst_t insnlst = { - count:2, - insns:insn_tab + .count = 2, + .insns = insn_tab }; /* Sets the delay to wait */ _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git