usb: acpi: fix undefined behavior in USB_ACPI_LOCATION_VALID
PATCH 1/1 usb: acpi: fix undefined behavior in USB_ACPI_LOCATION_VALID
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.
Found by cppcheck:
drivers/usb/core/usb-acpi.c:221:24: error:
Shifting signed 32-bit value by 31 bits is undefined behaviour [shiftTooManyBitsSigned]
--- drivers/usb/core/usb-acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/core/usb-acpi.c +1 -1
@@ -197,7 +197,7 @@ static int usb_acpi_add_usb4_devlink(struct usb_device *udev)* Private to usb-acpi, all the core needs to know is that * port_dev->location is non-zero when it has been set by the firmware. */ -#define USB_ACPI_LOCATION_VALID (1 << 31) +#define USB_ACPI_LOCATION_VALID BIT(31)static void usb_acpi_get_connect_type (struct usb_port *port_dev,acpi_handle *handle)
Signature · 1 line
2.53.0
Greg KH
maintainerQuoted 3 lines · Igor Cudnik
USB_ACPI_LOCATION_VALIDuses 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?
Quoted 4 lines
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"?
Quoted 3 lines
[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