Re: [PATCH] comedi: fix comedi_nsamples_left.

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

 



On 15/02/18 20:13, Frank Mori Hess wrote:
A rounding error was causing comedi_nsamples_left to
return the wrong value when nsamples was not a multiple
of the scan length.

Cc: <stable@xxxxxxxxxxxxxxx> # v4.4+
Signed-off-by: Frank Mori Hess <fmh6jj@xxxxxxxxx>
---
  drivers/staging/comedi/drivers.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 0b43db6371c6..c11c22bd6d13 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -484,8 +484,7 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
  	struct comedi_cmd *cmd = &async->cmd;
if (cmd->stop_src == TRIG_COUNT) {
-		unsigned int nscans = nsamples / cmd->scan_end_arg;
-		unsigned int scans_left = __comedi_nscans_left(s, nscans);
+		unsigned int scans_left = __comedi_nscans_left(s, cmd->stop_arg);
  		unsigned int scan_pos =
  		    comedi_bytes_to_samples(s, async->scan_progress);
  		unsigned long long samples_left = 0;


I think Hartley's original implementation of comedi_nsamples_left() in commit f615915ee5fa ("staging: comedi: drivers: introduce comedi_nsamples_left()") may have also avoided the problem by adding 1 to nscans:

		/* +1 to force comedi_nscans_left() to return the scans left */
		unsigned int nscans = (nsamples / cmd->scan_end_arg) + 1;

except for an extreme case I attempted to fix in commit 92d354cbe95f ("staging: comedi: fix extreme case of comedi_nsamples_left()") where I removed the "+ 1" amongst other changes. So I may have broke it.

Your fix should work though.  Thanks!

Reviewed-by: Ian Abbott <abbotti@xxxxxxxxx>

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx> )=-
-=(                          Web: http://www.mev.co.uk/  )=-
_______________________________________________
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