usb: dwc3: qcom: check for hcd in dwc3_qcom_read_usb2_speed
Subsystems (3)
PATCH v3 1/1 usb: dwc3: qcom: check for hcd in dwc3_qcom_read_usb2_speed
Currently dwc->xhci is not cleared if xhci_plat_probe() fails. During system suspend, dwc3_qcom_read_usb2_speed() checks dwc->xhci and assumes xhci is initialised. Since the probe failed, hcd will be null, and the subsequent access results in a NULL pointer dereference
Unable to handle kernel NULL pointer dereference at
virtual address 0000000000000058
Call trace: dwc3_qcom_pm_suspend dpm_run_callback device_suspend dpm_suspend dpm_suspend_start suspend_devices_and_enter pm_suspend
Explicitly check the hcd pointer in dwc3_qcom_read_usb2_speed before accessing it.
---
Changes in v3:
- Initialised udev to null, as suggested by sashiko bot.
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Added null pointer check in dwc3-qcom.c instead of marking xhci as null in host.c
- Link to v1: https://lore.kernel.org/all/[email protected]
drivers/usb/dwc3/dwc3-qcom.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/dwc3/dwc3-qcom.c +3 -4
@@ -231,7 +231,7 @@ static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom)static enum usb_device_speed dwc3_qcom_read_usb2_speed (struct dwc3_qcom *qcom,int port_index) { -struct usb_device *udev; +struct usb_device *udev =NULL ;struct usb_hcd __maybe_unused *hcd;struct dwc3 *dwc = &qcom->dwc;
@@ -241,9 +241,8 @@ static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom, i hcd =platform_get_drvdata (dwc->xhci);#ifdef CONFIG_USB - udev =usb_hub_find_child (hcd->self.root_hub, port_index +1 ); -#else - udev =NULL ; +if (hcd) + udev =usb_hub_find_child (hcd->self.root_hub, port_index +1 );#endif if (!udev)return USB_SPEED_UNKNOWN ;
Signature · 1 line
2.34.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 17 lines
Currently
dwc->xhciis not cleared ifxhci_plat_probe()fails. During system suspend,dwc3_qcom_read_usb2_speed()checksdwc->xhciand assumes xhci is initialised. Since the probe failed, hcd will be null, and the subsequent access results in a NULL pointer dereferenceUnable to handle kernel NULL pointer dereference atvirtual address 0000000000000058
Call trace: dwc3_qcom_pm_suspend dpm_run_callback device_suspend dpm_suspend dpm_suspend_start suspend_devices_and_enter pm_suspend
Quoted 5 lines
Explicitly check the hcd pointer in
dwc3_qcom_read_usb2_speedbefore accessing it.Fixes 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")Signed-off-by Prashanth K <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 17 lines · Prashanth K
Currently
dwc->xhciis not cleared ifxhci_plat_probe()fails. During system suspend,dwc3_qcom_read_usb2_speed()checksdwc->xhciand assumes xhci is initialised. Since the probe failed, hcd will be null, and the subsequent access results in a NULL pointer dereferenceUnable to handle kernel NULL pointer dereference atvirtual address 0000000000000058
Call trace: dwc3_qcom_pm_suspend dpm_run_callback device_suspend dpm_suspend dpm_suspend_start suspend_devices_and_enter pm_suspend
Quoted 5 lines
Explicitly check the hcd pointer in
dwc3_qcom_read_usb2_speedbefore accessing it.Fixes 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")Signed-off-by Prashanth K <[email protected]>
Peter
Quoted 41 lines
---
Changes in v3:
- Initialised udev to null, as suggested by sashiko bot.
- Link to v2: https://lore.kernel.org/all/[email protected]/Changes in v2:
- Added null pointer check indwc3-qcom.cinstead of marking xhci as null inhost.c
- Link to v1: https://lore.kernel.org/all/[email protected]drivers/usb/dwc3/dwc3-qcom.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/usb/dwc3/dwc3-qcom.c +3
-4@@ -231,7 +231,7 @@ static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom)static enum usb_device_speed dwc3_qcom_read_usb2_speed (struct dwc3_qcom *qcom,int port_index) { -struct usb_device *udev; +struct usb_device *udev =NULL ;struct usb_hcd __maybe_unused *hcd;struct dwc3 *dwc = &qcom->dwc;@@ -241,9 +241,8 @@ static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom, i hcd =platform_get_drvdata (dwc->xhci);#ifdef CONFIG_USB - udev =usb_hub_find_child (hcd->self.root_hub, port_index +1 ); -#else - udev =NULL ; +if (hcd) + udev =usb_hub_find_child (hcd->self.root_hub, port_index +1 );#endif if (!udev)return USB_SPEED_UNKNOWN ;Signature · 1 line
2.34.1
Signature · 2 lines
Thanks, Peter Chen
Quoted 17 lines · Prashanth K
Currently
dwc->xhciis not cleared ifxhci_plat_probe()fails. During system suspend,dwc3_qcom_read_usb2_speed()checksdwc->xhciand assumes xhci is initialised. Since the probe failed, hcd will be null, and the subsequent access results in a NULL pointer dereferenceUnable to handle kernel NULL pointer dereference atvirtual address 0000000000000058
Call trace: dwc3_qcom_pm_suspend dpm_run_callback device_suspend dpm_suspend dpm_suspend_start suspend_devices_and_enter pm_suspend
Quoted 6 lines
Explicitly check the hcd pointer in
dwc3_qcom_read_usb2_speedbefore accessing it.Fixes 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")Signed-off-by Prashanth K <[email protected]>---
Can we add Cc stable?
Thanks,
Thinh