Re: [PATCH 15/49] staging: comedi: gsc_hpdi: factor out step 5 of (*do_cmdtest)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Also, remove the unnecessary chanlist sanity check in Step 3.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
  drivers/staging/comedi/drivers/gsc_hpdi.c | 36 ++++++++++++++++++-------------
  1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c
index 08d7655..7cf8459 100644
--- a/drivers/staging/comedi/drivers/gsc_hpdi.c
+++ b/drivers/staging/comedi/drivers/gsc_hpdi.c
@@ -360,12 +360,30 @@ static int gsc_hpdi_cmd(struct comedi_device *dev,
  	return 0;
  }

+static int gsc_hpdi_check_chanlist(struct comedi_device *dev,
+				   struct comedi_subdevice *s,
+				   struct comedi_cmd *cmd)
+{
+	int i;
+
+	for (i = 0; i < cmd->chanlist_len; i++) {
+		unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+
+		if (chan != i) {
+			/*  XXX could support 8 or 16 channels */
+			dev_err(dev->class_dev,
+				"chanlist must be ch 0 to 31 in order\n");
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+
  static int gsc_hpdi_cmd_test(struct comedi_device *dev,
  			     struct comedi_subdevice *s,
  			     struct comedi_cmd *cmd)
  {
  	int err = 0;
-	int i;

  	if (s->io_bits)
  		return -EINVAL;
@@ -392,10 +410,6 @@ static int gsc_hpdi_cmd_test(struct comedi_device *dev,

  	/* Step 3: check if arguments are trivially valid */

-	if (!cmd->chanlist_len || !cmd->chanlist) {
-		cmd->chanlist_len = 32;
-		err |= -EINVAL;
-	}
  	err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);

  	if (cmd->stop_src == TRIG_COUNT)
@@ -411,17 +425,9 @@ static int gsc_hpdi_cmd_test(struct comedi_device *dev,
  	if (err)
  		return 4;

-	/* step 5: complain about special chanlist considerations */
+	/* Step 5: check channel list */

-	for (i = 0; i < cmd->chanlist_len; i++) {
-		if (CR_CHAN(cmd->chanlist[i]) != i) {
-			/*  XXX could support 8 or 16 channels */
-			dev_err(dev->class_dev,
-				"chanlist must be ch 0 to 31 in order");
-			err |= -EINVAL;
-			break;
-		}
-	}
+	err |= gsc_hpdi_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 gsc_hpdi_check_chanlist() should only be called if chanlist is non-NULL and chanlist_len is non-0.

Actually in this case, it seems safe to call gsc_hpdi_check_chanlist() if chanlist_len is 0, so only chanlist needs to be checked.

Also, 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 pci9111_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




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux