diff mbox series

[v2] usb: dwc3: qcom: Provide stubs for dwc3_qcom_read_usb2_speed function

Message ID 1659337215-20421-1-git-send-email-quic_kriskura@quicinc.com
State Superseded
Headers show
Series [v2] usb: dwc3: qcom: Provide stubs for dwc3_qcom_read_usb2_speed function | expand

Commit Message

Krishna Kurapati Aug. 1, 2022, 7 a.m. UTC
Dwc3 Qcom driver makes use of usb_hub_find_child API in its efforts
to get speed of connected devices (HS/LS/FS) and enable interrupts
accordingly. usb_hub_find_child API is a part of usb core compiled
either into the kernel or as a module (CONFIG_USB= Y or M). In some
builds (make randconfig for i386) CONFIG_USB is not enabled and the
usb core is not compiled resulting in linking errors.

Provide stubs for dwc3_qcom_read_usb2_speed function to use
usb_hub_find_child API only if CONFIG_USB is enabled. Else return
USB_SPEED_UNKNOWN.

Fixes: 6895ea55c385 (usb: dwc3: qcom: Configure wakeup interrupts during suspend)
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Suggested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Krishna Kurapati <quic_kriskura@quicinc.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
---
v2: Updated commit text to include cases when CONFIG_USB=m as well.

 drivers/usb/dwc3/dwc3-qcom.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Johan Hovold Aug. 2, 2022, 4:33 p.m. UTC | #1
On Mon, Aug 01, 2022 at 12:30:15PM +0530, Krishna Kurapati wrote:
> Dwc3 Qcom driver makes use of usb_hub_find_child API in its efforts
> to get speed of connected devices (HS/LS/FS) and enable interrupts
> accordingly.

> usb_hub_find_child API is a part of usb core compiled
> either into the kernel or as a module (CONFIG_USB= Y or M). In some
> builds (make randconfig for i386) CONFIG_USB is not enabled and the
> usb core is not compiled resulting in linking errors.

Please replace the above with something more succinct. Whether USB core
is built as a module or not is completely irrelevant. The problem is
that the qcom dwc3 driver can be built and used without host support. 

> Provide stubs for dwc3_qcom_read_usb2_speed function to use
> usb_hub_find_child API only if CONFIG_USB is enabled. Else return
> USB_SPEED_UNKNOWN.

The fact that you need to do this is an indication that something is
wrong with the current implementation. The glue driver shouldn't be
touching the host driver internal state directly like this.

As pointed out here:

	https://lore.kernel.org/all/20220802151404.1797-4-johan+linaro@kernel.org/

dwc3_qcom_read_usb2_speed() is indeed broken and currently triggers a
NULL-pointer dereference when the controller is used in peripheral mode.

But for now I guess something like this is needed even if we try to
avoid stubs in implementation files.

Johan
Johan Hovold Aug. 4, 2022, 3:20 p.m. UTC | #2
On Tue, Aug 02, 2022 at 06:33:36PM +0200, Johan Hovold wrote:
> On Mon, Aug 01, 2022 at 12:30:15PM +0530, Krishna Kurapati wrote:
> > Dwc3 Qcom driver makes use of usb_hub_find_child API in its efforts
> > to get speed of connected devices (HS/LS/FS) and enable interrupts
> > accordingly.
> 
> > usb_hub_find_child API is a part of usb core compiled
> > either into the kernel or as a module (CONFIG_USB= Y or M). In some
> > builds (make randconfig for i386) CONFIG_USB is not enabled and the
> > usb core is not compiled resulting in linking errors.
> 
> Please replace the above with something more succinct. Whether USB core
> is built as a module or not is completely irrelevant. The problem is
> that the qcom dwc3 driver can be built and used without host support. 
> 
> > Provide stubs for dwc3_qcom_read_usb2_speed function to use
> > usb_hub_find_child API only if CONFIG_USB is enabled. Else return
> > USB_SPEED_UNKNOWN.
> 
> The fact that you need to do this is an indication that something is
> wrong with the current implementation. The glue driver shouldn't be
> touching the host driver internal state directly like this.
> 
> As pointed out here:
> 
> 	https://lore.kernel.org/all/20220802151404.1797-4-johan+linaro@kernel.org/
> 
> dwc3_qcom_read_usb2_speed() is indeed broken and currently triggers a
> NULL-pointer dereference when the controller is used in peripheral mode.
> 
> But for now I guess something like this is needed even if we try to
> avoid stubs in implementation files.

This is how I think this should be fixed instead:

	https://lore.kernel.org/all/20220804151001.23612-4-johan+linaro@kernel.org/

and which keeps the ifdeffery minimal. I included the patch in v2 of the
series that addresses the other problems with this code.

Johan
Greg Kroah-Hartman Aug. 8, 2022, 1 p.m. UTC | #3
On Mon, Aug 01, 2022 at 12:30:15PM +0530, Krishna Kurapati wrote:
> Dwc3 Qcom driver makes use of usb_hub_find_child API in its efforts
> to get speed of connected devices (HS/LS/FS) and enable interrupts
> accordingly. usb_hub_find_child API is a part of usb core compiled
> either into the kernel or as a module (CONFIG_USB= Y or M). In some
> builds (make randconfig for i386) CONFIG_USB is not enabled and the
> usb core is not compiled resulting in linking errors.
> 
> Provide stubs for dwc3_qcom_read_usb2_speed function to use
> usb_hub_find_child API only if CONFIG_USB is enabled. Else return
> USB_SPEED_UNKNOWN.
> 
> Fixes: 6895ea55c385 (usb: dwc3: qcom: Configure wakeup interrupts during suspend)
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Suggested-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Krishna Kurapati <quic_kriskura@quicinc.com>
> Acked-by: Randy Dunlap <rdunlap@infradead.org>
> Tested-by: Randy Dunlap <rdunlap@infradead.org>
> ---
> v2: Updated commit text to include cases when CONFIG_USB=m as well.
> 
>  drivers/usb/dwc3/dwc3-qcom.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index c5e482f..bd8dc5a 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -299,6 +299,7 @@ static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom)
>  	icc_put(qcom->icc_path_apps);
>  }
>  
> +#ifdef CONFIG_USB

How is code for a USB host driver being built if CONFIG_USB is not
enabled?

Shouldn't this driver be split up cleaner to not be built at all if that
is not happening and this is a gadget-only configuration?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index c5e482f..bd8dc5a 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -299,6 +299,7 @@  static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom)
 	icc_put(qcom->icc_path_apps);
 }
 
+#ifdef CONFIG_USB
 static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom)
 {
 	struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
@@ -318,6 +319,12 @@  static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom)
 
 	return udev->speed;
 }
+#else
+static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom)
+{
+	return USB_SPEED_UNKNOWN;
+}
+#endif
 
 static void dwc3_qcom_enable_wakeup_irq(int irq, unsigned int polarity)
 {