Skip to contentSkip to conversation

usb: dwc3: qcom: use IS_REACHABLE(CONFIG_USB) for hub speed lookup

PATCH New Pengpeng Hou 2 participants 2 messages Dec 4

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Fixes c06795f114a6 ("usb: dwc3: qcom: fix gadget-only builds")
Fixes b958b03c82d2 ("usb: dwc3: qcom: Snapshot driver for backwards compatibilty")

---
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
index 189f5447aa786ce1e9ee89dd6efa215f3e956a5c..47a0f717fd53e49ecb966949b913b7c2fbaea59b 100644
@@ -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
index a2608416e04ecb8d3421421082ddbf7cae582de5..6501c00090c886b333599c0fee4dc919c16f2b68 100644
@@ -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

#1 lore raw
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 --

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
index 189f5447aa786..47a0f717fd53e 100644
@@ -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
index a2608416e04ec..6501c00090c88 100644

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