From: Eldad Zack Subject: ALSA: usb-audio: caiaq: endianness bug Date: Mon, 29 Apr 2013 20:10:26 +0200 (CEST) Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-bk0-f42.google.com (mail-bk0-f42.google.com [209.85.214.42]) by alsa0.perex.cz (Postfix) with ESMTP id 05B87261605 for ; Mon, 29 Apr 2013 20:10:32 +0200 (CEST) Received: by mail-bk0-f42.google.com with SMTP id jf3so1020164bkc.15 for ; Mon, 29 Apr 2013 11:10:32 -0700 (PDT) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Daniel Mack Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org 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 --- 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