Re: UBSAN whinge in ihci-hub.c

From: Andrey Ryabinin
Date: Wed May 18 2016 - 11:02:23 EST


2016-05-18 17:40 GMT+03:00 Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>:

> All right, I'm getting very tired of all these bug reports. Besides,
> Andrey has a point: Unless you're Linus, arguing against the C standard
> is futile. (Even though the language dialect used in the kernel is not
> standard C.)
>
> Does this patch make UBSAN happy? The runtime overhead is minimal.
>

It does. However, you could fool ubsan way more easy:
u32 __iomem *hostpc_reg = ehci->regs->hostpc +
(wIndex & 0xff) - 1;



> Alan Stern
>
>
>
> Index: usb-4.x/drivers/usb/host/ehci-hub.c
> ===================================================================
> --- usb-4.x.orig/drivers/usb/host/ehci-hub.c
> +++ usb-4.x/drivers/usb/host/ehci-hub.c
> @@ -872,14 +872,17 @@ int ehci_hub_control(
> ) {
> struct ehci_hcd *ehci = hcd_to_ehci (hcd);
> int ports = HCS_N_PORTS (ehci->hcs_params);
> - u32 __iomem *status_reg = &ehci->regs->port_status[
> - (wIndex & 0xff) - 1];
> - u32 __iomem *hostpc_reg = &ehci->regs->hostpc[(wIndex & 0xff) - 1];
> + u32 __iomem *status_reg, *hostpc_reg;
> u32 temp, temp1, status;
> unsigned long flags;
> int retval = 0;
> unsigned selector;
>
> + temp = wIndex & 0xff;
> + temp -= (temp > 0);
> + status_reg = &ehci->regs->port_status[temp];
> + hostpc_reg = &ehci->regs->hostpc[temp];
> +
> /*
> * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
> * HCS_INDICATOR may say we can change LEDs to off/amber/green.
>