Re: [PATCH 1/1] usb: acpi: fix undefined behavior in USB_ACPI_LOCATION_VALID

From: Greg KH

Date: Wed May 27 2026 - 04:03:12 EST


On Tue, May 26, 2026 at 07:43:37PM +0200, Igor Cudnik wrote:
> USB_ACPI_LOCATION_VALID uses a signed left shift into the sign
> bit. Shifting a signed value into the sign bit is undefined behavior.
> Use BIT(31) instead.

SHouldn't this be UBIT(31) instead, if you were really worried about
this shift?

>
> Found by cppcheck:
> drivers/usb/core/usb-acpi.c:221:24: error:
> Shifting signed 32-bit value by 31 bits is undefined behaviour

Is this really a bug? Look at how this is used, is the generated code
"wrong"?

> [shiftTooManyBitsSigned]
>
> Fixes: f3ac348e6e045 ("usb: usb-acpi: Set port connect type of not connectable ports correctly")

Is this fixing a real bug? Or just papering over a buggy tool?

thanks,

greg k-h