On 2014-04-15 18:37, H Hartley Sweeten wrote:
Step 5 of the (*do_cmdtest) validates that the chanlist, chan/range/aref/etc, is compatible with the actual hardware. At this point in the (*do_cmdtest) the chanlist is valid, due to checks in the core, so the sanity check is not needed. For aesthetics, factor the step 5 code into a helper function. Tidy up the factored out code. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/das16m1.c | 48 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/drivers/staging/comedi/drivers/das16m1.c b/drivers/staging/comedi/drivers/das16m1.c index 7792258..75dc967 100644 --- a/drivers/staging/comedi/drivers/das16m1.c +++ b/drivers/staging/comedi/drivers/das16m1.c @@ -150,11 +150,38 @@ static void munge_sample_array(unsigned short *array, unsigned int num_elements) array[i] = munge_sample(array[i]); } +static int das16m1_ai_check_chanlist(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_cmd *cmd) +{ + int i; + + if (cmd->chanlist_len == 1) + return 0; + + if ((cmd->chanlist_len % 2) != 0) { + dev_err(dev->class_dev, + "chanlist must be of even length or length 1\n"); + return -EINVAL; + } + for (i = 0; i < cmd->chanlist_len; i++) { + unsigned int chan = CR_CHAN(cmd->chanlist[i]); + + if ((i % 2) != (chan % 2)) { + dev_err(dev->class_dev, + "even/odd channels must go have even/odd chanlist indices\n"); + return -EINVAL; + } + } + return 0; +} + static int das16m1_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_cmd *cmd) { struct das16m1_private_struct *devpriv = dev->private; - unsigned int err = 0, tmp, i; + int err = 0; + unsigned int tmp; /* Step 1 : check if triggers are trivially valid */ @@ -216,22 +243,9 @@ static int das16m1_cmd_test(struct comedi_device *dev, if (err) return 4; - /* check chanlist against board's peculiarities */ - if (cmd->chanlist && cmd->chanlist_len > 1) { - for (i = 0; i < cmd->chanlist_len; i++) { - /* even/odd channels must go into even/odd queue addresses */ - if ((i % 2) != (CR_CHAN(cmd->chanlist[i]) % 2)) { - comedi_error(dev, "bad chanlist:\n" - " even/odd channels must go have even/odd chanlist indices"); - err++; - } - } - if ((cmd->chanlist_len % 2) != 0) { - comedi_error(dev, - "chanlist must be of even length or length 1"); - err++; - } - } + /* Step 5: check channel list */ + + err |= das16m1_ai_check_chanlist(dev, s, cmd); if (err) return 5;
As for the remarks in patch 02, it's possible for chanlist to be NULL or for chanlist_len to be 0, so das16m1_ai_check_chanlist() should only be called if chanlist is non-NULL and chanlist_len is non-0.
But if chanlist is forced to be NULL by __comedi_get_user_chanlist() when chanlist_len is 0, it would be sufficient to check that chanlist is non-NULL before calling das16m1_ai_check_chanlist().
-- -=( Ian Abbott @ MEV Ltd. E-mail: <abbotti@xxxxxxxxx> )=- -=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=- _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel