linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: comedi: fix scan_end_arg == chanlist_len assumption
@ 2014-11-12 16:00 Ian Abbott
  2014-11-12 16:27 ` Hartley Sweeten
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Abbott @ 2014-11-12 16:00 UTC (permalink / raw)
  To: driverdev-devel
  Cc: Greg Kroah-Hartman, Ian Abbott, H Hartley Sweeten, linux-kernel

Some comedi drivers allow the `scan_end_arg` value of an asynchronous
command to be a multiple (> 1) of the `chanlist_len` although most
require them to be the same value.

`comedi_bytes_per_scan()` is incorrectly using `chanlist_len` as the
length of the scan.  Change it to use `scan_end_arg`.

`comedi_nsamples_left()` is incorrectly using `cur_chan` as the current
sample position in the scan (it is actually the current position in the
channel list).  Change it to use the actual sample position in the scan.
(Unfortunately we only have the current scan position in bytes currently,
so convert that to a sample position.)

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 82ac845..e516ed9 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -317,10 +317,10 @@ unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s)
 	case COMEDI_SUBD_DO:
 	case COMEDI_SUBD_DIO:
 		bits_per_sample = 8 * comedi_bytes_per_sample(s);
-		num_samples = DIV_ROUND_UP(cmd->chanlist_len, bits_per_sample);
+		num_samples = DIV_ROUND_UP(cmd->scan_end_arg, bits_per_sample);
 		break;
 	default:
-		num_samples = cmd->chanlist_len;
+		num_samples = cmd->scan_end_arg;
 		break;
 	}
 	return comedi_samples_to_bytes(s, num_samples);
@@ -384,11 +384,13 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
 		/* +1 to force comedi_nscans_left() to return the scans left */
 		unsigned int nscans = (nsamples / cmd->scan_end_arg) + 1;
 		unsigned int scans_left = comedi_nscans_left(s, nscans);
+		unsigned int scan_pos =
+		    comedi_bytes_to_samples(s, async->scan_progress);
 		unsigned long long samples_left = 0;
 
 		if (scans_left) {
 			samples_left = ((unsigned long long)scans_left *
-				       cmd->scan_end_arg) - async->cur_chan;
+					cmd->scan_end_arg) - scan_pos;
 		}
 
 		if (samples_left < nsamples)
-- 
2.1.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH] staging: comedi: fix scan_end_arg == chanlist_len assumption
  2014-11-12 16:00 [PATCH] staging: comedi: fix scan_end_arg == chanlist_len assumption Ian Abbott
@ 2014-11-12 16:27 ` Hartley Sweeten
  0 siblings, 0 replies; 2+ messages in thread
From: Hartley Sweeten @ 2014-11-12 16:27 UTC (permalink / raw)
  To: Ian Abbott, driverdev-devel; +Cc: Greg Kroah-Hartman, linux-kernel

On Wednesday, November 12, 2014 9:01 AM, Ian Abbott wrote:
> Some comedi drivers allow the `scan_end_arg` value of an asynchronous
> command to be a multiple (> 1) of the `chanlist_len` although most
> require them to be the same value.
>
> `comedi_bytes_per_scan()` is incorrectly using `chanlist_len` as the
> length of the scan.  Change it to use `scan_end_arg`.
>
> `comedi_nsamples_left()` is incorrectly using `cur_chan` as the current
> sample position in the scan (it is actually the current position in the
> channel list).  Change it to use the actual sample position in the scan.
> (Unfortunately we only have the current scan position in bytes currently,
> so convert that to a sample position.)
>
> Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
> ---
>  drivers/staging/comedi/drivers.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-12 16:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-12 16:00 [PATCH] staging: comedi: fix scan_end_arg == chanlist_len assumption Ian Abbott
2014-11-12 16:27 ` Hartley Sweeten

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).