Skip to content

Commit 5618332

Browse files
berndporrgregkh
authored andcommitted
staging: comedi: usbduxfast: usbduxfast_ai_cmdtest rounding error
The userspace comedilib function 'get_cmd_generic_timed' fills the cmd structure with an informed guess and then calls the function 'usbduxfast_ai_cmdtest' in this driver repeatedly while 'usbduxfast_ai_cmdtest' is modifying the cmd struct until it no longer changes. However, because of rounding errors this never converged because 'steps = (cmd->convert_arg * 30) / 1000' and then back to 'cmd->convert_arg = (steps * 1000) / 30' won't be the same because of rounding errors. 'Steps' should only be converted back to the 'convert_arg' if 'steps' has actually been modified. In addition the case of steps being 0 wasn't checked which is also now done. Signed-off-by: Bernd Porr <[email protected]> Cc: <[email protected]> # 4.4+ Reviewed-by: Ian Abbott <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1637a94 commit 5618332

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

drivers/staging/comedi/drivers/usbduxfast.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// SPDX-License-Identifier: GPL-2.0+
22
/*
3-
* Copyright (C) 2004-2014 Bernd Porr, [email protected]
3+
* Copyright (C) 2004-2019 Bernd Porr, [email protected]
44
*/
55

66
/*
77
* Driver: usbduxfast
88
* Description: University of Stirling USB DAQ & INCITE Technology Limited
99
* Devices: [ITL] USB-DUX-FAST (usbduxfast)
1010
* Author: Bernd Porr <[email protected]>
11-
* Updated: 10 Oct 2014
11+
* Updated: 16 Nov 2019
1212
* Status: stable
1313
*/
1414

@@ -22,6 +22,7 @@
2222
*
2323
*
2424
* Revision history:
25+
* 1.0: Fixed a rounding error in usbduxfast_ai_cmdtest
2526
* 0.9: Dropping the first data packet which seems to be from the last transfer.
2627
* Buffer overflows in the FX2 are handed over to comedi.
2728
* 0.92: Dropping now 4 packets. The quad buffer has to be emptied.
@@ -350,6 +351,7 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
350351
struct comedi_cmd *cmd)
351352
{
352353
int err = 0;
354+
int err2 = 0;
353355
unsigned int steps;
354356
unsigned int arg;
355357

@@ -399,11 +401,16 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
399401
*/
400402
steps = (cmd->convert_arg * 30) / 1000;
401403
if (cmd->chanlist_len != 1)
402-
err |= comedi_check_trigger_arg_min(&steps,
403-
MIN_SAMPLING_PERIOD);
404-
err |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD);
405-
arg = (steps * 1000) / 30;
406-
err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
404+
err2 |= comedi_check_trigger_arg_min(&steps,
405+
MIN_SAMPLING_PERIOD);
406+
else
407+
err2 |= comedi_check_trigger_arg_min(&steps, 1);
408+
err2 |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD);
409+
if (err2) {
410+
err |= err2;
411+
arg = (steps * 1000) / 30;
412+
err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
413+
}
407414

408415
if (cmd->stop_src == TRIG_COUNT)
409416
err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);

0 commit comments

Comments
 (0)