diff mbox series

[-next] usb: dwc2: check return value after calling platform_get_resource()

Message ID 20210831084236.1359677-1-yangyingliang@huawei.com (mailing list archive)
State Accepted
Commit 856e6e8e0f9300befa87dde09edb578555c99a82
Headers show
Series [-next] usb: dwc2: check return value after calling platform_get_resource() | expand

Commit Message

Yang Yingliang Aug. 31, 2021, 8:42 a.m. UTC
It will cause null-ptr-deref if platform_get_resource() returns NULL,
we need check the return value.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/usb/dwc2/hcd.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 2a7828971d05..a215ec9e172e 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -5191,6 +5191,10 @@  int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
 	hcd->has_tt = 1;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		retval = -EINVAL;
+		goto error1;
+	}
 	hcd->rsrc_start = res->start;
 	hcd->rsrc_len = resource_size(res);