usb: dwc3: qcom: use IS_REACHABLE(CONFIG_USB) for hub speed lookup
Subsystems (3)
PATCH 1/1 usb: dwc3: qcom: use IS_REACHABLE(CONFIG_USB) for hub speed lookup
The Qualcomm DWC3 suspend path needs the attached USB2 device speed when selecting wake signals. The normal and legacy drivers both bypass the host-side query if USB host support is modular.
Use IS_REACHABLE so modular host consumers can make the query without introducing a built-in reference to a module.
The issue was found by our static-analysis tool and manually reviewed.
---
The original patch was prepared with Gemini. Codex assisted with this review and revision (Assisted-by: gpt 5).
Built both dwc3-qcom.o and dwc3-qcom-legacy.o on x86-64 with GCC and W=1, USB=m and USB_DWC3_QCOM=m. With the same configuration neither object referenced usb_hub_find_child before the change; both referenced it afterwards. No USB suspend or hardware test was run.
drivers/usb/dwc3/dwc3-qcom-legacy.c | 2 +- drivers/usb/dwc3/dwc3-qcom.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-qcom-legacy.c +1 -1
@@ -328,7 +328,7 @@ static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom, i*/ hcd =platform_get_drvdata (dwc->xhci); -#ifdef CONFIG_USB +#if IS_REACHABLE (CONFIG_USB ) udev =usb_hub_find_child (hcd->self.root_hub, port_index +1 );#else udev =NULL ;
drivers/usb/dwc3/dwc3-qcom.c +1 -1
@@ -240,7 +240,7 @@ static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom, i*/ hcd =platform_get_drvdata (dwc->xhci); -#ifdef CONFIG_USB +#if IS_REACHABLE (CONFIG_USB ) udev =usb_hub_find_child (hcd->self.root_hub, port_index +1 );#else udev =NULL ;
base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] usb: dwc3: qcom: unnecessary usbcore dependency in gadget-only builds --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] usb: dwc3: qcom: unnecessary usbcore dependency in gadget-only builds
--
commit 8d368bc1212d1c6dd44f3c214755c23434636cce
Author: Pengpeng Hou <[email protected]>
usb: dwc3: qcom: use IS_REACHABLE(CONFIG_USB) for hub speed lookup
This commit replaces #ifdef CONFIG_USB with #if IS_REACHABLE(CONFIG_USB) around the usb_hub_find_child() call in dwc3_qcom_read_usb2_speed() in both the normal and legacy Qualcomm DWC3 glue drivers.
Quoted 18 lines
drivers/usb/dwc3/dwc3-qcom-legacy.c +1
-1@@ -328,7 +328,7 @@ static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom, i*/ hcd =platform_get_drvdata (dwc->xhci); -#ifdef CONFIG_USB +#if IS_REACHABLE (CONFIG_USB ) udev =usb_hub_find_child (hcd->self.root_hub, port_index +1 );#else udev =NULL ;drivers/usb/dwc3/dwc3-qcom.c +0
-0
drivers/usb/dwc3/dwc3-qcom.c static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom, i · line 246
Quoted 8 lines
drivers/usb/dwc3/dwc3-qcom.c +1
-1@@ -240,7 +240,7 @@ static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom, i*/ hcd =platform_get_drvdata (dwc->xhci); -#ifdef CONFIG_USB +#if IS_REACHABLE (CONFIG_USB ) udev =usb_hub_find_child (hcd->self.root_hub, port_index +1 );#else udev =NULL ;
[Severity: Low]
Does this add an unnecessary module dependency on usbcore.ko in gadget-only DWC3 builds?
When CONFIG_USB=m, CONFIG_USB_DWC3=m, CONFIG_USB_DWC3_GADGET=y, and CONFIG_USB_DWC3_QCOM=m, both modules now reference usb_hub_find_child() even though DWC3 host support is compiled out and dwc->xhci is always NULL, preventing them from loading without usbcore.ko in an initramfs.
Guarding the lookup with IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE), matching dwc3_host_init() in drivers/usb/dwc3/core.h, avoids pulling in usbcore.ko in gadget-only builds while Kconfig still guarantees CONFIG_USB is reachable.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1