Skip to contentSkip to conversation

usb: cdns3: change place of NULL check in cdns3_gadget_ep_enable()

PATCH In review Andrey Strachuk 3 participants 3 messages Jul 28, 2022 – Aug 19, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/1 usb: cdns3: change place of NULL check in cdns3_gadget_ep_enable()

If 'ep' is NULL, result of ep_to_cdns3_ep(ep) is invalid and priv_ep->cdns3_dev causes panic.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
---
 drivers/usb/cdns3/cdns3-gadget.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/cdns3/cdns3-gadget.c +4 -1
index 5c15c48952a6..51de7457a3b8 100644
@@ -2284,11 +2284,14 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep,
 	int ret = 0;
 	int val;
 
+	if (!ep)
+		return -EINVAL;
+
 	priv_ep = ep_to_cdns3_ep(ep);
 	priv_dev = priv_ep->cdns3_dev;
 	comp_desc = priv_ep->endpoint.comp_desc;
 
-	if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
+	if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
 		dev_dbg(priv_dev->dev, "usbss: invalid parameters\n");
 		return -EINVAL;
 	}
Signature · 1 line
2.25.1
#3 lore raw
In reply to Andrey Strachuk
Quoted 10 lines · Andrey Strachuk

If 'ep' is NULL, result of ep_to_cdns3_ep(ep) is invalid and priv_ep->cdns3_dev causes panic.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
---
 drivers/usb/cdns3/cdns3-gadget.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

No information on what changed from v1 to v2 :(

drivers/usb/cdns3/cdns3-gadget.c static int cdns3_gadget_ep_enable(struct usb_ep *ep, · line 2288

Quoted 11 lines
drivers/usb/cdns3/cdns3-gadget.c +2 -0
index 5c15c48952a6..51de7457a3b8 100644
@@ -2284,11 +2284,14 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep,
 	int ret = 0;
 	int val;
 
+	if (!ep)
+		return -EINVAL;

How can ep ever be NULL at all? Why does this need to be checked?

thanks,

greg k-h