driverdev-devel.linuxdriverproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: devel@driverdev.osuosl.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ian Abbott <abbotti@mev.co.uk>,
	stable@vger.kernel.org
Subject: [PATCH 03/14] staging: comedi: adv_pci1710: Fix endian problem for AI command data
Date: Tue, 23 Feb 2021 14:30:44 +0000	[thread overview]
Message-ID: <20210223143055.257402-4-abbotti@mev.co.uk> (raw)
In-Reply-To: <20210223143055.257402-1-abbotti@mev.co.uk>

The analog input subdevice supports Comedi asynchronous commands that
use Comedi's 16-bit sample format.  However, the calls to
`comedi_buf_write_samples()` are passing the address of a 32-bit integer
variable.  On bigendian machines, this will copy 2 bytes from the wrong
end of the 32-bit value.  Fix it by changing the type of the variables
holding the sample value to `unsigned short`.  The type of the `val`
parameter of `pci1710_ai_read_sample()` is changed to `unsigned short *`
accordingly.  The type of the `val` variable in `pci1710_ai_insn_read()`
is also changed to `unsigned short` since its address is passed to
`pci1710_ai_read_sample()`.

Fixes: a9c3a015c12f ("staging: comedi: adv_pci1710: use comedi_buf_write_samples()")
Cc: <stable@vger.kernel.org> # 4.0+
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/adv_pci1710.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 692893c7e5c3..090607760be6 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -300,11 +300,11 @@ static int pci1710_ai_eoc(struct comedi_device *dev,
 static int pci1710_ai_read_sample(struct comedi_device *dev,
 				  struct comedi_subdevice *s,
 				  unsigned int cur_chan,
-				  unsigned int *val)
+				  unsigned short *val)
 {
 	const struct boardtype *board = dev->board_ptr;
 	struct pci1710_private *devpriv = dev->private;
-	unsigned int sample;
+	unsigned short sample;
 	unsigned int chan;
 
 	sample = inw(dev->iobase + PCI171X_AD_DATA_REG);
@@ -345,7 +345,7 @@ static int pci1710_ai_insn_read(struct comedi_device *dev,
 	pci1710_ai_setup_chanlist(dev, s, &insn->chanspec, 1, 1);
 
 	for (i = 0; i < insn->n; i++) {
-		unsigned int val;
+		unsigned short val;
 
 		/* start conversion */
 		outw(0, dev->iobase + PCI171X_SOFTTRG_REG);
@@ -395,7 +395,7 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
 {
 	struct comedi_cmd *cmd = &s->async->cmd;
 	unsigned int status;
-	unsigned int val;
+	unsigned short val;
 	int ret;
 
 	status = inw(dev->iobase + PCI171X_STATUS_REG);
@@ -455,7 +455,7 @@ static void pci1710_handle_fifo(struct comedi_device *dev,
 	}
 
 	for (i = 0; i < devpriv->max_samples; i++) {
-		unsigned int val;
+		unsigned short val;
 		int ret;
 
 		ret = pci1710_ai_read_sample(dev, s, s->async->cur_chan, &val);
-- 
2.30.0

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2021-02-23 14:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-23 14:30 [PATCH 00/14] staging: comedi: Fix some command data endian problems Ian Abbott
2021-02-23 14:30 ` [PATCH 01/14] staging: comedi: addi_apci_1032: Fix endian problem for COS sample Ian Abbott
2021-02-23 14:30 ` [PATCH 02/14] staging: comedi: addi_apci_1500: Fix endian problem for command sample Ian Abbott
2021-02-23 14:30 ` Ian Abbott [this message]
2021-02-23 14:30 ` [PATCH 04/14] staging: comedi: das6402: Fix endian problem for AI command data Ian Abbott
2021-02-23 14:30 ` [PATCH 05/14] staging: comedi: das800: " Ian Abbott
2021-02-23 14:30 ` [PATCH 06/14] staging: comedi: dmm32at: " Ian Abbott
2021-02-23 14:30 ` [PATCH 07/14] staging: comedi: me4000: " Ian Abbott
2021-02-23 14:30 ` [PATCH 08/14] staging: comedi: pcl711: " Ian Abbott
2021-02-23 14:30 ` [PATCH 09/14] staging: comedi: pcl818: " Ian Abbott
2021-02-23 14:30 ` [PATCH 10/14] staging: comedi: amplc_pc236_common: Use 16-bit 0 for interrupt data Ian Abbott
2021-02-23 14:30 ` [PATCH 11/14] staging: comedi: comedi_parport: " Ian Abbott
2021-02-23 14:30 ` [PATCH 12/14] staging: comedi: ni_6527: " Ian Abbott
2021-02-23 14:30 ` [PATCH 13/14] staging: comedi: ni_65xx: " Ian Abbott
2021-02-23 14:30 ` [PATCH 14/14] staging: comedi: pcl726: " Ian Abbott

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210223143055.257402-4-abbotti@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).