Skip to content

Commit 423b24c

Browse files
ian-abbottgregkh
authored andcommitted
staging: comedi: usbduxsigma: don't clobber ai_timer in command test
`devpriv->ai_timer` is used while an asynchronous command is running on the AI subdevice. It also gets modified by the subdevice's `cmdtest` handler for checking new asynchronous commands (`usbduxsigma_ai_cmdtest()`), which is not correct as it's allowed to check new commands while an old command is still running. Fix it by moving the code which sets up `devpriv->ai_timer` and `devpriv->ai_interval` into the subdevice's `cmd` handler, `usbduxsigma_ai_cmd()`. Note that the removed code in `usbduxsigma_ai_cmdtest()` checked that `devpriv->ai_timer` did not end up less than than 1, but that could not happen because `cmd->scan_begin_arg` had already been checked to be at least the minimum required value (at least when `cmd->scan_begin_src == TRIG_TIMER`, which had also been checked to be the case). Fixes: b986be8 ("staging: comedi: usbduxsigma: tidy up analog input command support) Signed-off-by: Ian Abbott <[email protected]> Reviewed-by: Bernd Porr <[email protected]> Reviewed-by: H Hartley Sweeten <[email protected]> Cc: <[email protected]> # 3.19 onwards Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ab74359 commit 423b24c

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

drivers/staging/comedi/drivers/usbduxsigma.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -551,27 +551,6 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev,
551551
if (err)
552552
return 3;
553553

554-
/* Step 4: fix up any arguments */
555-
556-
if (high_speed) {
557-
/*
558-
* every 2 channels get a time window of 125us. Thus, if we
559-
* sample all 16 channels we need 1ms. If we sample only one
560-
* channel we need only 125us
561-
*/
562-
devpriv->ai_interval = interval;
563-
devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval);
564-
} else {
565-
/* interval always 1ms */
566-
devpriv->ai_interval = 1;
567-
devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
568-
}
569-
if (devpriv->ai_timer < 1)
570-
err |= -EINVAL;
571-
572-
if (err)
573-
return 4;
574-
575554
return 0;
576555
}
577556

@@ -669,6 +648,22 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
669648

670649
down(&devpriv->sem);
671650

651+
if (devpriv->high_speed) {
652+
/*
653+
* every 2 channels get a time window of 125us. Thus, if we
654+
* sample all 16 channels we need 1ms. If we sample only one
655+
* channel we need only 125us
656+
*/
657+
unsigned int interval = usbduxsigma_chans_to_interval(len);
658+
659+
devpriv->ai_interval = interval;
660+
devpriv->ai_timer = cmd->scan_begin_arg / (125000 * interval);
661+
} else {
662+
/* interval always 1ms */
663+
devpriv->ai_interval = 1;
664+
devpriv->ai_timer = cmd->scan_begin_arg / 1000000;
665+
}
666+
672667
for (i = 0; i < len; i++) {
673668
unsigned int chan = CR_CHAN(cmd->chanlist[i]);
674669

0 commit comments

Comments
 (0)