All of lore.kernel.org
 help / color / mirror / Atom feed
* ALSA: usb-audio: caiaq: endianness bug
@ 2013-04-29 18:10 Eldad Zack
  2013-04-29 18:33 ` Daniel Mack
  0 siblings, 1 reply; 3+ messages in thread
From: Eldad Zack @ 2013-04-29 18:10 UTC (permalink / raw)
  To: Daniel Mack; +Cc: alsa-devel


Hi Daniel,

I think I found a endian usage issue in the caiaq driver. I have a patch 
to fix it (below), but it assumes that the driver works currently on 
little endian CPUs - I don't have a device to test it with.

Cheers,
Eldad

-- >8 --
Subject: [PATCH] ALSA: usb-audio: caiaq: fix endianness bug

Current code does this:

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

Which is effectively:

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

This means the int16 in the buffer is not converted at all.
Assuming the device-side structure is actually little endian,
change the code to use le16_to_cpu().

Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
 sound/usb/caiaq/input.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c
index efc70ae..2f4ae4d 100644
--- a/sound/usb/caiaq/input.c
+++ b/sound/usb/caiaq/input.c
@@ -488,13 +488,12 @@ 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);
-- 
1.8.1.5

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

* Re: ALSA: usb-audio: caiaq: endianness bug
  2013-04-29 18:10 ALSA: usb-audio: caiaq: endianness bug Eldad Zack
@ 2013-04-29 18:33 ` Daniel Mack
  2013-04-29 19:04   ` Eldad Zack
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Mack @ 2013-04-29 18:33 UTC (permalink / raw)
  To: Eldad Zack; +Cc: alsa-devel

On 29.04.2013 20:10, Eldad Zack wrote:
> 
> Hi Daniel,
> 
> I think I found a endian usage issue in the caiaq driver. I have a patch 
> to fix it (below), but it assumes that the driver works currently on 
> little endian CPUs - I don't have a device to test it with.

I don't currently have any either, but your findings make sense. I just
know that the driver currently works on LE CPUs.

> Cheers,
> Eldad
> 
> -- >8 --
> Subject: [PATCH] ALSA: usb-audio: caiaq: fix endianness bug
> 
> Current code does this:
> 
>   be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1])
> 
> Which is effectively:
> 
>   be16_to_cpu(be16_to_cpu(*((u16 *) buf)))
> 
> This means the int16 in the buffer is not converted at all.
> Assuming the device-side structure is actually little endian,
> change the code to use le16_to_cpu().
> 
> Signed-off-by: Eldad Zack <eldad@fogrefinery.com>

Acked-by: Daniel Mack <zonque@gmail.com>

> ---
>  sound/usb/caiaq/input.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c
> index efc70ae..2f4ae4d 100644
> --- a/sound/usb/caiaq/input.c
> +++ b/sound/usb/caiaq/input.c
> @@ -488,13 +488,12 @@ 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);
> 

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

* Re: ALSA: usb-audio: caiaq: endianness bug
  2013-04-29 18:33 ` Daniel Mack
@ 2013-04-29 19:04   ` Eldad Zack
  0 siblings, 0 replies; 3+ messages in thread
From: Eldad Zack @ 2013-04-29 19:04 UTC (permalink / raw)
  To: Daniel Mack; +Cc: alsa-devel


On Mon, 29 Apr 2013, Daniel Mack wrote:

> On 29.04.2013 20:10, Eldad Zack wrote:
> > 
> > Hi Daniel,
> > 
> > I think I found a endian usage issue in the caiaq driver. I have a patch 
> > to fix it (below), but it assumes that the driver works currently on 
> > little endian CPUs - I don't have a device to test it with.
> 
> I don't currently have any either, but your findings make sense. I just
> know that the driver currently works on LE CPUs.

Thanks for the quick reply and the ack!

I'll update the commit message post a patch soon.

Cheers,
Eldad

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

end of thread, other threads:[~2013-04-29 19:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-29 18:10 ALSA: usb-audio: caiaq: endianness bug Eldad Zack
2013-04-29 18:33 ` Daniel Mack
2013-04-29 19:04   ` Eldad Zack

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.