2020-08-20 12:21:48

by Tang Bin

[permalink] [raw]
Subject: [PATCH] usb: hcd: fix the error check

In the function usb_add_hcd(), usb_phy_roothub_alloc()
can return NULL in some cases, so IS_ERR() doesn't meet
the requirements. Thus fix it.
Signed-off-by: Zhang Shengju <[email protected]>
Signed-off-by: Tang Bin <[email protected]>
---
drivers/usb/core/hcd.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index aa45840d8..b73a92ee1 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2633,8 +2633,9 @@ int usb_add_hcd(struct usb_hcd *hcd,

if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
- if (IS_ERR(hcd->phy_roothub))
- return PTR_ERR(hcd->phy_roothub);
+ if (IS_ERR_OR_NULL(hcd->phy_roothub))
+ return hcd->phy_roothub ?
+ PTR_ERR(hcd->phy_roothub) : -ENODEV;

retval = usb_phy_roothub_init(hcd->phy_roothub);
if (retval)
--
2.20.1.windows.1




2020-08-21 23:31:35

by Chen, Rong A

[permalink] [raw]
Subject: [usb] 33958ef53b: kmsg.ehci-pci#:#:#a.#:init#:#:#a.#fail

Greeting,

FYI, we noticed the following commit (built with gcc-9):

commit: 33958ef53b16a6a074e8d37692adac2f5c00fb80 ("[PATCH] usb: hcd: fix the error check")
url: https://github.com/0day-ci/linux/commits/Tang-Bin/usb-hcd-fix-the-error-check/20200820-202156
base: https://git.kernel.org/cgit/linux/kernel/git/gregkh/usb.git usb-testing

in testcase: suspend-stress
with following parameters:

mode: mem
iterations: 10



on test machine: 4 threads Ivy Bridge with 4G memory

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):




If you fix the issue, kindly add following tag
Reported-by: kernel test robot <[email protected]>



kern :info : [ 6.043957] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
kern :debug : [ 6.044199] initcall ehci_hcd_init+0x0/0xaf returned 0 after 234 usecs
kern :debug : [ 6.044424] calling ehci_pci_init+0x0/0x65 @ 1
kern :info : [ 6.044610] ehci-pci: EHCI PCI platform driver
kern :err : [ 6.045249] ehci-pci 0000:00:1a.0: init 0000:00:1a.0 fail, -19
kern :debug : [ 6.045668] IOAPIC[0]: Set routing entry (2-23 -> 0xef -> IRQ 23 Mode:1 Active:1 Dest:1)
kern :err : [ 6.046185] ehci-pci 0000:00:1d.0: init 0000:00:1d.0 fail, -19
kern :debug : [ 6.046415] initcall ehci_pci_init+0x0/0x65 returned 0 after 1760 usecs
kern :debug : [ 6.046641] calling ohci_hcd_mod_init+0x0/0x80 @ 1
kern :info : [ 6.046833] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
kern :debug : [ 6.047056] initcall ohci_hcd_mod_init+0x0/0x80 returned 0 after 216 usecs
kern :debug : [ 6.047297] calling ohci_pci_init+0x0/0x65 @ 1
kern :info : [ 6.047483] ohci-pci: OHCI PCI platform driver
kern :debug : [ 6.047679] initcall ohci_pci_init+0x0/0x65 returned 0 after 190 usecs
kern :debug : [ 6.047903] calling uhci_hcd_init+0x0/0x10d @ 1
kern :info : [ 6.048089] uhci_hcd: USB Universal Host Controller Interface driver
kern :debug : [ 6.048339] initcall uhci_hcd_init+0x0/0x10d returned 0 after 241 usecs
kern :debug : [ 6.048565] calling xhci_hcd_init+0x0/0x24 @ 1
kern :debug : [ 6.048754] initcall xhci_hcd_init+0x0/0x24 returned 0 after 1 usecs
kern :debug : [ 6.048976] calling xhci_pci_init+0x0/0x4e @ 1
kern :err : [ 6.049531] xhci_hcd 0000:00:14.0: init 0000:00:14.0 fail, -19
kern :debug : [ 6.049760] initcall xhci_pci_init+0x0/0x4e returned 0 after 577 usecs
kern :debug : [ 6.049985] calling ucsi_acpi_platform_driver_init+0x0/0x13 @ 1
kern :debug : [ 6.050222] initcall ucsi_acpi_platform_driver_init+0x0/0x13 returned 0 after 15 usecs
kern :debug : [ 6.050524] calling i8042_init+0x0/0x99 @ 1


To reproduce:

git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
bin/lkp install job.yaml # job file is attached in this email
bin/lkp run job.yaml



Thanks,
Rong Chen


Attachments:
(No filename) (2.91 kB)
config-5.9.0-rc1-00026-g33958ef53b16a (161.48 kB)
job-script (4.96 kB)
kmsg.xz (37.62 kB)
suspend-stress (1.98 kB)
job.yaml (4.00 kB)
Download all attachments

2020-08-24 03:15:48

by Peter Chen

[permalink] [raw]
Subject: Re: [PATCH] usb: hcd: fix the error check

On 20-08-20 20:20:38, Tang Bin wrote:
> In the function usb_add_hcd(), usb_phy_roothub_alloc()
> can return NULL in some cases, so IS_ERR() doesn't meet
> the requirements. Thus fix it.
> Signed-off-by: Zhang Shengju <[email protected]>
> Signed-off-by: Tang Bin <[email protected]>
> ---
> drivers/usb/core/hcd.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index aa45840d8..b73a92ee1 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -2633,8 +2633,9 @@ int usb_add_hcd(struct usb_hcd *hcd,
>
> if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
> hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
> - if (IS_ERR(hcd->phy_roothub))
> - return PTR_ERR(hcd->phy_roothub);
> + if (IS_ERR_OR_NULL(hcd->phy_roothub))
> + return hcd->phy_roothub ?
> + PTR_ERR(hcd->phy_roothub) : -ENODEV;

Many (old) host controller drivers, their PHYs are not seen by software.
We may not consider NULL as error.

--

Thanks,
Peter Chen