Skip to contentSkip to conversation

ALSA: usb-audio: caiaq: fix endianness bug in snd_usb_caiaq_maschine_dispatch

PATCH In review Eldad Zack 3 participants 3 messages Apr 29, 2013 – Apr 30, 2013

Subsystems (2)
lore
Share & tools
lore

Eldad Zack

author
#0 lore raw

PATCH 1/1 ALSA: usb-audio: caiaq: fix endianness bug in snd_usb_caiaq_maschine_dispatch

Current code does this:

be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1])

Which is effectively (neglecting the index):

be16_to_cpu(be16_to_cpu(*((u16 *) buf)))

This means the int16 in the buffer is not converted at all.

Daniel Mack confirmed that the driver works on little endian CPUs, leading to the conclusion that the device-side structure is actually little endian.
This changes the code to use le16_to_cpu().

Caught by sparse.

---
 sound/usb/caiaq/input.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
sound/usb/caiaq/input.c +5 -5
index efc70ae..4b3fb91 100644
@@ -488,13 +488,13 @@ static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *cdev,
 					unsigned int len)
 {
 	unsigned int i, pad_id;
-	uint16_t pressure;
+	__le16 *pressure = (__le16 *) buf;
 
 	for (i = 0; i < MASCHINE_PADS; i++) {
-		pressure = be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]);
-		pad_id = pressure >> 12;
-
-		input_report_abs(cdev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff);
+		pad_id = le16_to_cpu(*pressure) >> 12;
+		input_report_abs(cdev->input_dev, MASCHINE_PAD(pad_id),
+				 le16_to_cpu(*pressure) & 0xfff);
+		pressure++;
 	}
 
 	input_sync(cdev->input_dev);
Signature · 1 line
1.8.1.5
maintainer
#1 lore raw
Quoted 15 lines · Eldad Zack

Current code does this:

be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1])

Which is effectively (neglecting the index):

be16_to_cpu(be16_to_cpu(*((u16 *) buf)))

This means the int16 in the buffer is not converted at all.

Daniel Mack confirmed that the driver works on little endian CPUs, leading to the conclusion that the device-side structure is actually little endian.
This changes the code to use le16_to_cpu().

Quoted 4 lines

Caught by sparse.

Appearantly, nobody (including me) has ever used the pad controls of this particular device on a BE machine. So I think it might not even be worth Cc'ing stable.

Thanks for catching this, anyway!

Daniel

Quoted 28 lines
---
 sound/usb/caiaq/input.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
sound/usb/caiaq/input.c +5 -5
index efc70ae..4b3fb91 100644
@@ -488,13 +488,13 @@ static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *cdev,
 					unsigned int len)
 {
 	unsigned int i, pad_id;
-	uint16_t pressure;
+	__le16 *pressure = (__le16 *) buf;
 
 	for (i = 0; i < MASCHINE_PADS; i++) {
-		pressure = be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]);
-		pad_id = pressure >> 12;
-
-		input_report_abs(cdev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff);
+		pad_id = le16_to_cpu(*pressure) >> 12;
+		input_report_abs(cdev->input_dev, MASCHINE_PAD(pad_id),
+				 le16_to_cpu(*pressure) & 0xfff);
+		pressure++;
 	}
 
 	input_sync(cdev->input_dev);
#2 lore raw

At Mon, 29 Apr 2013 21:20:43 +0200,

Quoted 17 lines · Daniel Mack
Quoted 15 lines · Eldad Zack

Current code does this:

be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1])

Which is effectively (neglecting the index):

be16_to_cpu(be16_to_cpu(*((u16 *) buf)))

This means the int16 in the buffer is not converted at all.

Daniel Mack confirmed that the driver works on little endian CPUs, leading to the conclusion that the device-side structure is actually little endian.
This changes the code to use le16_to_cpu().

Quoted 8 lines
Quoted 4 lines

Caught by sparse.

Appearantly, nobody (including me) has ever used the pad controls of this particular device on a BE machine. So I think it might not even be worth Cc'ing stable.

OK. Applied as is now.
Thanks.

Takashi

Quoted 37 lines

Thanks for catching this, anyway!

Daniel

Quoted 28 lines
---
 sound/usb/caiaq/input.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
sound/usb/caiaq/input.c +5 -5
index efc70ae..4b3fb91 100644
@@ -488,13 +488,13 @@ static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *cdev,
 					unsigned int len)
 {
 	unsigned int i, pad_id;
-	uint16_t pressure;
+	__le16 *pressure = (__le16 *) buf;
 
 	for (i = 0; i < MASCHINE_PADS; i++) {
-		pressure = be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]);
-		pad_id = pressure >> 12;
-
-		input_report_abs(cdev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff);
+		pad_id = le16_to_cpu(*pressure) >> 12;
+		input_report_abs(cdev->input_dev, MASCHINE_PAD(pad_id),
+				 le16_to_cpu(*pressure) & 0xfff);
+		pressure++;
 	}
 
 	input_sync(cdev->input_dev);