All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH stable 3.9 to 3.16] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write()
@ 2018-07-10 17:02 Ian Abbott
  2018-11-09 23:44 ` Ben Hutchings
  0 siblings, 1 reply; 7+ messages in thread
From: Ian Abbott @ 2018-07-10 17:02 UTC (permalink / raw)
  To: stable
  Cc: Greg Kroah-Hartman, Dan Carpenter, Ian Abbott, H Hartley Sweeten,
	Ben Hutchings

From: Dan Carpenter <dan.carpenter@oracle.com>

[ Upstream commit 1376b0a2160319125c3a2822e8c09bd283cd8141 ]

There is a '>' vs '<' typo so this loop is a no-op.

Fixes: d35dcc89fc93 ("staging: comedi: quatech_daqp_cs: fix daqp_ao_insn_write()")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/staging/comedi/drivers/quatech_daqp_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index b3bbec0a0d23..f89a863ea04c 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -649,7 +649,7 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
 	/* Make sure D/A update mode is direct update */
 	outb(0, dev->iobase + DAQP_AUX);
 
-	for (i = 0; i > insn->n; i++) {
+	for (i = 0; i < insn->n; i++) {
 		val = data[0];
 		val &= 0x0fff;
 		val ^= 0x0800;		/* Flip the sign */
-- 
2.18.0

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

* Re: [PATCH stable 3.9 to 3.16] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write()
  2018-07-10 17:02 [PATCH stable 3.9 to 3.16] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write() Ian Abbott
@ 2018-11-09 23:44 ` Ben Hutchings
  2018-11-12 11:56   ` Ian Abbott
  0 siblings, 1 reply; 7+ messages in thread
From: Ben Hutchings @ 2018-11-09 23:44 UTC (permalink / raw)
  To: Ian Abbott, stable; +Cc: Greg Kroah-Hartman, Dan Carpenter, H Hartley Sweeten

[-- Attachment #1: Type: text/plain, Size: 1553 bytes --]

On Tue, 2018-07-10 at 18:02 +0100, Ian Abbott wrote:
> From: Dan Carpenter <dan.carpenter@oracle.com>
> 
> [ Upstream commit 1376b0a2160319125c3a2822e8c09bd283cd8141 ]
> 
> There is a '>' vs '<' typo so this loop is a no-op.

Thanks, but this driver seems to have lots of other bugs in 3.16, like
it only ever accesses data[0] in this loop.  I don't think there's much
point in applying just this one.  But if you think it's worth fixing
then I can apply all the necessary fixes.

Ben.

> Fixes: d35dcc89fc93 ("staging: comedi: quatech_daqp_cs: fix daqp_ao_insn_write()")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/staging/comedi/drivers/quatech_daqp_cs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
> index b3bbec0a0d23..f89a863ea04c 100644
> --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
> +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
> @@ -649,7 +649,7 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
>  	/* Make sure D/A update mode is direct update */
>  	outb(0, dev->iobase + DAQP_AUX);
>  
> -	for (i = 0; i > insn->n; i++) {
> +	for (i = 0; i < insn->n; i++) {
>  		val = data[0];
>  		val &= 0x0fff;
>  		val ^= 0x0800;		/* Flip the sign */
-- 
Ben Hutchings
Knowledge is power.  France is bacon.



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH stable 3.9 to 3.16] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write()
  2018-11-09 23:44 ` Ben Hutchings
@ 2018-11-12 11:56   ` Ian Abbott
  2018-11-12 12:36     ` [PATCH 1/3] staging: comedi: quatech_daqp_cs: fix bug in daqp_ao_insn_write() Ian Abbott
  2019-01-02 17:48     ` [PATCH stable 3.9 to 3.16] " Ben Hutchings
  0 siblings, 2 replies; 7+ messages in thread
From: Ian Abbott @ 2018-11-12 11:56 UTC (permalink / raw)
  To: Ben Hutchings, stable
  Cc: Greg Kroah-Hartman, Dan Carpenter, H Hartley Sweeten

On 09/11/18 23:44, Ben Hutchings wrote:
> On Tue, 2018-07-10 at 18:02 +0100, Ian Abbott wrote:
>> From: Dan Carpenter <dan.carpenter@oracle.com>
>>
>> [ Upstream commit 1376b0a2160319125c3a2822e8c09bd283cd8141 ]
>>
>> There is a '>' vs '<' typo so this loop is a no-op.
> 
> Thanks, but this driver seems to have lots of other bugs in 3.16, like
> it only ever accesses data[0] in this loop.  I don't think there's much
> point in applying just this one.  But if you think it's worth fixing
> then I can apply all the necessary fixes.
> 
> Ben.

It restores some basic functionality for daqp_ao_insn_write() that was 
broken.  The most common case to be handled is insn->n == 1, as that is 
what the comedi_data_write() function in the user-space Comedilib 
library sets.

However, it may be worth applying e024181b02ed ("staging: comedi: 
quatech_daqp_cs: fix bug in daqp_ao_insn_write()") and (with a small 
amount of backporting) e031642eccc0 ("staging: comedi: quatech_daqp_cs: 
use comedi_timeout() in ao (*insn_write)") before this one.  I'll append 
a patch series as replies to this email.

> 
>> Fixes: d35dcc89fc93 ("staging: comedi: quatech_daqp_cs: fix daqp_ao_insn_write()")
>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>> Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
>> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> ---
>>   drivers/staging/comedi/drivers/quatech_daqp_cs.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
>> index b3bbec0a0d23..f89a863ea04c 100644
>> --- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
>> +++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
>> @@ -649,7 +649,7 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
>>   	/* Make sure D/A update mode is direct update */
>>   	outb(0, dev->iobase + DAQP_AUX);
>>   
>> -	for (i = 0; i > insn->n; i++) {
>> +	for (i = 0; i < insn->n; i++) {
>>   		val = data[0];
>>   		val &= 0x0fff;
>>   		val ^= 0x0800;		/* Flip the sign */


-- 
-=( Ian Abbott <abbotti@mev.co.uk> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-

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

* [PATCH 1/3] staging: comedi: quatech_daqp_cs: fix bug in daqp_ao_insn_write()
  2018-11-12 11:56   ` Ian Abbott
@ 2018-11-12 12:36     ` Ian Abbott
  2018-11-12 12:36       ` [PATCH 2/3] staging: comedi: quatech_daqp_cs: use comedi_timeout() in ao (*insn_write) Ian Abbott
  2018-11-12 12:36       ` [PATCH 3/3] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write() Ian Abbott
  2019-01-02 17:48     ` [PATCH stable 3.9 to 3.16] " Ben Hutchings
  1 sibling, 2 replies; 7+ messages in thread
From: Ian Abbott @ 2018-11-12 12:36 UTC (permalink / raw)
  To: Ben Hutchings, stable
  Cc: Greg Kroah-Hartman, Dan Carpenter, H Hartley Sweeten, Ian Abbott

From: H Hartley Sweeten <hsweeten@visionengravers.com>

commit e024181b02ed6b833358bede3f2d0c52cb5fb6bc upstream.

The comedi core expects (*insn_write) functions to write insn->n values
to the hardware and return the number of values written.

Currently, this function only writes the first value. Fix it to work
like the core expects.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/staging/comedi/drivers/quatech_daqp_cs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index b3bbec0a0d23..dde91c0c0418 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -640,7 +640,6 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
 {
 	struct daqp_private *devpriv = dev->private;
 	unsigned int chan = CR_CHAN(insn->chanspec);
-	unsigned int val;
 	int i;
 
 	if (devpriv->stop)
@@ -650,7 +649,8 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
 	outb(0, dev->iobase + DAQP_AUX);
 
 	for (i = 0; i > insn->n; i++) {
-		val = data[0];
+		unsigned val = data[i];
+
 		val &= 0x0fff;
 		val ^= 0x0800;		/* Flip the sign */
 		val |= (chan << 12);
-- 
2.19.1

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

* [PATCH 2/3] staging: comedi: quatech_daqp_cs: use comedi_timeout() in ao (*insn_write)
  2018-11-12 12:36     ` [PATCH 1/3] staging: comedi: quatech_daqp_cs: fix bug in daqp_ao_insn_write() Ian Abbott
@ 2018-11-12 12:36       ` Ian Abbott
  2018-11-12 12:36       ` [PATCH 3/3] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write() Ian Abbott
  1 sibling, 0 replies; 7+ messages in thread
From: Ian Abbott @ 2018-11-12 12:36 UTC (permalink / raw)
  To: Ben Hutchings, stable
  Cc: Greg Kroah-Hartman, Dan Carpenter, H Hartley Sweeten, Ian Abbott

From: H Hartley Sweeten <hsweeten@visionengravers.com>

commit e031642eccc040648b09cfc7d632e2e8d0b6f94f upstream.

The data link between the D/A data port and the D/A converter is a serial
link. The serial link requires about 8ms to complete a transfer. Use the
comedi_timeout() helper to ensure that there is not a previous transfer
still happening before trying to write new data to the channel.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[ija: Backported to 3.16: No 'readback' member in subdevice.]
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 .../staging/comedi/drivers/quatech_daqp_cs.c  | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index dde91c0c0418..870751db03de 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -633,6 +633,19 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 	return 0;
 }
 
+static int daqp_ao_empty(struct comedi_device *dev,
+			 struct comedi_subdevice *s,
+			 struct comedi_insn *insn,
+			 unsigned long context)
+{
+	unsigned int status;
+
+	status = inb(dev->iobase + DAQP_AUX);
+	if ((status & DAQP_AUX_DA_BUFFER) == 0)
+		return 0;
+	return -EBUSY;
+}
+
 static int daqp_ao_insn_write(struct comedi_device *dev,
 			      struct comedi_subdevice *s,
 			      struct comedi_insn *insn,
@@ -650,6 +663,12 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
 
 	for (i = 0; i > insn->n; i++) {
 		unsigned val = data[i];
+		int ret;
+
+		/* D/A transfer rate is about 8ms */
+		ret = comedi_timeout(dev, s, insn, daqp_ao_empty, 0);
+		if (ret)
+			return ret;
 
 		val &= 0x0fff;
 		val ^= 0x0800;		/* Flip the sign */
-- 
2.19.1

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

* [PATCH 3/3] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write()
  2018-11-12 12:36     ` [PATCH 1/3] staging: comedi: quatech_daqp_cs: fix bug in daqp_ao_insn_write() Ian Abbott
  2018-11-12 12:36       ` [PATCH 2/3] staging: comedi: quatech_daqp_cs: use comedi_timeout() in ao (*insn_write) Ian Abbott
@ 2018-11-12 12:36       ` Ian Abbott
  1 sibling, 0 replies; 7+ messages in thread
From: Ian Abbott @ 2018-11-12 12:36 UTC (permalink / raw)
  To: Ben Hutchings, stable
  Cc: Greg Kroah-Hartman, Dan Carpenter, H Hartley Sweeten, Ian Abbott

From: Dan Carpenter <dan.carpenter@oracle.com>

commit 1376b0a2160319125c3a2822e8c09bd283cd8141 upstream.

There is a '>' vs '<' typo so this loop is a no-op.

Fixes: d35dcc89fc93 ("staging: comedi: quatech_daqp_cs: fix daqp_ao_insn_write()")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/staging/comedi/drivers/quatech_daqp_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index 870751db03de..21f4e7ef14c6 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -661,7 +661,7 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
 	/* Make sure D/A update mode is direct update */
 	outb(0, dev->iobase + DAQP_AUX);
 
-	for (i = 0; i > insn->n; i++) {
+	for (i = 0; i < insn->n; i++) {
 		unsigned val = data[i];
 		int ret;
 
-- 
2.19.1

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

* Re: [PATCH stable 3.9 to 3.16] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write()
  2018-11-12 11:56   ` Ian Abbott
  2018-11-12 12:36     ` [PATCH 1/3] staging: comedi: quatech_daqp_cs: fix bug in daqp_ao_insn_write() Ian Abbott
@ 2019-01-02 17:48     ` Ben Hutchings
  1 sibling, 0 replies; 7+ messages in thread
From: Ben Hutchings @ 2019-01-02 17:48 UTC (permalink / raw)
  To: Ian Abbott, stable; +Cc: Greg Kroah-Hartman, Dan Carpenter, H Hartley Sweeten

[-- Attachment #1: Type: text/plain, Size: 1392 bytes --]

On Mon, 2018-11-12 at 11:56 +0000, Ian Abbott wrote:
> On 09/11/18 23:44, Ben Hutchings wrote:
> > On Tue, 2018-07-10 at 18:02 +0100, Ian Abbott wrote:
> > > From: Dan Carpenter <dan.carpenter@oracle.com>
> > > 
> > > [ Upstream commit 1376b0a2160319125c3a2822e8c09bd283cd8141 ]
> > > 
> > > There is a '>' vs '<' typo so this loop is a no-op.
> > 
> > Thanks, but this driver seems to have lots of other bugs in 3.16, like
> > it only ever accesses data[0] in this loop.  I don't think there's much
> > point in applying just this one.  But if you think it's worth fixing
> > then I can apply all the necessary fixes.
> > 
> > Ben.
> 
> It restores some basic functionality for daqp_ao_insn_write() that was 
> broken.  The most common case to be handled is insn->n == 1, as that is 
> what the comedi_data_write() function in the user-space Comedilib 
> library sets.
> 
> However, it may be worth applying e024181b02ed ("staging: comedi: 
> quatech_daqp_cs: fix bug in daqp_ao_insn_write()") and (with a small 
> amount of backporting) e031642eccc0 ("staging: comedi: quatech_daqp_cs: 
> use comedi_timeout() in ao (*insn_write)") before this one.  I'll append 
> a patch series as replies to this email.

I've queued these up for the next update, thanks.

Ben.

-- 
Ben Hutchings
Absolutum obsoletum. (If it works, it's out of date.) - Stafford Beer



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2019-01-02 17:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-10 17:02 [PATCH stable 3.9 to 3.16] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write() Ian Abbott
2018-11-09 23:44 ` Ben Hutchings
2018-11-12 11:56   ` Ian Abbott
2018-11-12 12:36     ` [PATCH 1/3] staging: comedi: quatech_daqp_cs: fix bug in daqp_ao_insn_write() Ian Abbott
2018-11-12 12:36       ` [PATCH 2/3] staging: comedi: quatech_daqp_cs: use comedi_timeout() in ao (*insn_write) Ian Abbott
2018-11-12 12:36       ` [PATCH 3/3] staging: comedi: quatech_daqp_cs: fix no-op loop daqp_ao_insn_write() Ian Abbott
2019-01-02 17:48     ` [PATCH stable 3.9 to 3.16] " Ben Hutchings

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.