USB: EHCI: Add alias for Broadcom INSNREG
authorKees Cook <keescook@chromium.org>
Wed, 18 Aug 2021 17:30:18 +0000 (10:30 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Aug 2021 20:28:28 +0000 (22:28 +0200)
Refactor struct ehci_regs to avoid accessing beyond the end of
port_status. This change results in no difference in the final
object code.

Avoids several warnings when building with -Warray-bounds:

drivers/usb/host/ehci-brcm.c: In function 'ehci_brcm_reset':
drivers/usb/host/ehci-brcm.c:113:32: warning: array subscript 16 is above array bounds of 'u32[15]' {aka 'unsigned int[15]'} [-Warray-bounds]
  113 |  ehci_writel(ehci, 0x00800040, &ehci->regs->port_status[0x10]);
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from drivers/usb/host/ehci.h:274,
                 from drivers/usb/host/ehci-brcm.c:15:
./include/linux/usb/ehci_def.h:132:7: note: while referencing 'port_status'
  132 |   u32 port_status[HCS_N_PORTS_MAX];
      |       ^~~~~~~~~~~

Note that the documentation around this proprietary register was
confusing. If "USB_EHCI_INSNREG00" is at port_status[0x0f], its offset
would be 0x80 (not 0x90). The comments have been adjusted to fix this
apparent typo.

Fixes: 9df231511bd6 ("usb: ehci: Add new EHCI driver for Broadcom STB SoC's")
Cc: Al Cooper <alcooperx@gmail.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Cc: bcm-kernel-feedback-list@broadcom.com
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210818173018.2259231-3-keescook@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/ehci-brcm.c
include/linux/usb/ehci_def.h

index 3e0ebe8cc649ce4a7ed3c198676c3d7cbd547056..d3626bfa966b4d281857a85ec3bf00d186c5d2b1 100644 (file)
@@ -108,10 +108,9 @@ static int ehci_brcm_reset(struct usb_hcd *hcd)
        /*
         * SWLINUX-1705: Avoid OUT packet underflows during high memory
         *   bus usage
-        * port_status[0x0f] = Broadcom-proprietary USB_EHCI_INSNREG00 @ 0x90
         */
-       ehci_writel(ehci, 0x00800040, &ehci->regs->port_status[0x10]);
-       ehci_writel(ehci, 0x00000001, &ehci->regs->port_status[0x12]);
+       ehci_writel(ehci, 0x00800040, &ehci->regs->brcm_insnreg[1]);
+       ehci_writel(ehci, 0x00000001, &ehci->regs->brcm_insnreg[3]);
 
        return ehci_setup(hcd);
 }
@@ -223,11 +222,9 @@ static int __maybe_unused ehci_brcm_resume(struct device *dev)
        /*
         * SWLINUX-1705: Avoid OUT packet underflows during high memory
         *   bus usage
-        * port_status[0x0f] = Broadcom-proprietary USB_EHCI_INSNREG00
-        * @ 0x90
         */
-       ehci_writel(ehci, 0x00800040, &ehci->regs->port_status[0x10]);
-       ehci_writel(ehci, 0x00000001, &ehci->regs->port_status[0x12]);
+       ehci_writel(ehci, 0x00800040, &ehci->regs->brcm_insnreg[1]);
+       ehci_writel(ehci, 0x00000001, &ehci->regs->brcm_insnreg[3]);
 
        ehci_resume(hcd, false);
 
index dcbe2b0685690c50a0b4fafe5d0f2b0bbb657f4b..c892c5bc663809f49569ea7f06a8c3ac1e80fbae 100644 (file)
@@ -176,16 +176,23 @@ struct ehci_regs {
 #define USBMODE_CM_HC  (3<<0)          /* host controller mode */
 #define USBMODE_CM_IDLE        (0<<0)          /* idle state */
        };
-       u32             reserved4;
 
 /* Moorestown has some non-standard registers, partially due to the fact that
  * its EHCI controller has both TT and LPM support. HOSTPCx are extensions to
  * PORTSCx
  */
-       /* HOSTPC: offset 0x84 */
-       u32             hostpc[HCS_N_PORTS_MAX];
+       union {
+               struct {
+                       u32     reserved4;
+                       /* HOSTPC: offset 0x84 */
+                       u32     hostpc[HCS_N_PORTS_MAX];
 #define HOSTPC_PHCD    (1<<22)         /* Phy clock disable */
 #define HOSTPC_PSPD    (3<<25)         /* Port speed detection */
+               };
+
+               /* Broadcom-proprietary USB_EHCI_INSNREG00 @ 0x80 */
+               u32     brcm_insnreg[4];
+       };
 
        u32             reserved5[2];