diff mbox series

[02/11] ALSA: usb-audio: Fix undefined behavior due to shift overflowing the constant

Message ID 20220405151517.29753-3-bp@alien8.de (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Borislav Petkov April 5, 2022, 3:15 p.m. UTC
From: Borislav Petkov <bp@suse.de>

Fix:

  sound/usb/midi.c: In function ‘snd_usbmidi_out_endpoint_create’:
  sound/usb/midi.c:1389:2: error: case label does not reduce to an integer constant
    case USB_ID(0xfc08, 0x0101): /* Unknown vendor Cable */
    ^~~~

See https://lore.kernel.org/r/YkwQ6%2BtIH8GQpuct@zn.tnic for the gory
details as to why it triggers with older gccs only.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: alsa-devel@alsa-project.org
---
 sound/usb/usbaudio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Takashi Iwai April 5, 2022, 3:32 p.m. UTC | #1
On Tue, 05 Apr 2022 17:15:08 +0200,
Borislav Petkov wrote:
> 
> From: Borislav Petkov <bp@suse.de>
> 
> Fix:
> 
>   sound/usb/midi.c: In function ‘snd_usbmidi_out_endpoint_create’:
>   sound/usb/midi.c:1389:2: error: case label does not reduce to an integer constant
>     case USB_ID(0xfc08, 0x0101): /* Unknown vendor Cable */
>     ^~~~
> 
> See https://lore.kernel.org/r/YkwQ6%2BtIH8GQpuct@zn.tnic for the gory
> details as to why it triggers with older gccs only.
> 
> Signed-off-by: Borislav Petkov <bp@suse.de>
> Cc: Jaroslav Kysela <perex@perex.cz>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: alsa-devel@alsa-project.org
> ---
>  sound/usb/usbaudio.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
> index 167834133b9b..2b3dd55e8ee0 100644
> --- a/sound/usb/usbaudio.h
> +++ b/sound/usb/usbaudio.h
> @@ -8,7 +8,7 @@
>   */
>  
>  /* handling of USB vendor/product ID pairs as 32-bit numbers */
> -#define USB_ID(vendor, product) (((vendor) << 16) | (product))
> +#define USB_ID(vendor, product) ((((unsigned int)vendor) << 16) | (product))

Parentheses are needed around vendor (as usual for a macro).
Could you resubmit with it?


Thanks.

Takashi
Borislav Petkov April 5, 2022, 4:06 p.m. UTC | #2
On Tue, Apr 05, 2022 at 05:32:48PM +0200, Takashi Iwai wrote:
> > +#define USB_ID(vendor, product) ((((unsigned int)vendor) << 16) | (product))
> 
> Parentheses are needed around vendor (as usual for a macro).
> Could you resubmit with it?

Or you can fix it up while applying. :)

Thx.
Takashi Iwai April 5, 2022, 4:16 p.m. UTC | #3
On Tue, 05 Apr 2022 18:06:19 +0200,
Borislav Petkov wrote:
> 
> On Tue, Apr 05, 2022 at 05:32:48PM +0200, Takashi Iwai wrote:
> > > +#define USB_ID(vendor, product) ((((unsigned int)vendor) << 16) | (product))
> > 
> > Parentheses are needed around vendor (as usual for a macro).
> > Could you resubmit with it?
> 
> Or you can fix it up while applying. :)

If you prefer, sure.


Takashi
diff mbox series

Patch

diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 167834133b9b..2b3dd55e8ee0 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -8,7 +8,7 @@ 
  */
 
 /* handling of USB vendor/product ID pairs as 32-bit numbers */
-#define USB_ID(vendor, product) (((vendor) << 16) | (product))
+#define USB_ID(vendor, product) ((((unsigned int)vendor) << 16) | (product))
 #define USB_ID_VENDOR(id) ((id) >> 16)
 #define USB_ID_PRODUCT(id) ((u16)(id))