From e831127fd1dff8926d689250bd80f8501ca0f03a Mon Sep 17 00:00:00 2001 From: LeoLiu-oc Date: Wed, 3 Dec 2025 18:44:46 +0800 Subject: [PATCH] usb: hcd-pci: Optimize driver name checking condition zhaoxin inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IDAIBZ CVE: NA ------------------------- This patch optimizes the condition checking in the for_each_companion function in hcd-pci.c. The changes merge the driver existence check (!drv) with the subsequent driver name comparisons into a single if statement, making the code more concise and maintaining the same functionality. This cleanup helps improve code readability while preserving the original logic flow. Fixes: 37a864a7ba41 ("USB:Fix kernel NULL pointer when unbind UHCI form vfio-pci") Signed-off-by: LeoLiu-oc --- drivers/usb/core/hcd-pci.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index d4234f81b791..1f52ae7ec865 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c @@ -63,12 +63,10 @@ static void for_each_companion(struct pci_dev *pdev, struct usb_hcd *hcd, continue; drv = companion->driver; - if (!drv) - continue; - - if (strncmp(drv->name, "uhci_hcd", sizeof("uhci_hcd") - 1) && - strncmp(drv->name, "ohci-pci", sizeof("ohci-pci") - 1) && - strncmp(drv->name, "ehci-pci", sizeof("ehci-pci") - 1)) + if (drv && + strncmp(drv->name, "uhci_hcd", sizeof("uhci_hcd") - 1) && + strncmp(drv->name, "ohci-pci", sizeof("ohci-pci") - 1) && + strncmp(drv->name, "ehci-pci", sizeof("ehci-pci") - 1)) continue; /* -- Gitee