Skip to contentSkip to conversation

usb: dwc3: Check that the request is valid in dwc3_gadget_giveback()

PATCH New Vignesh Raghavendra 2 participants 3 messages Feb 14, 2020 – Feb 17, 2020

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

PATCH 1/1 usb: dwc3: Check that the request is valid in dwc3_gadget_giveback()

From: Jean-Jacques Hiblot <[email protected]>

This fixes potential issues reported by klokworks:
Pointer 'req' returned from call to function 'next_request' at line 531 and 538 may be NULL and will be dereferenced in dwc3_gadget_giveback()

---
 drivers/usb/dwc3/gadget.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/dwc3/gadget.c +3 -0
index 4353dffb6b12..12de3b1da663 100644
@@ -227,6 +227,9 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 {
 	struct dwc3			*dwc = dep->dwc;
 
+	if (!req)
+		return;
+
 	if (req->queued) {
 		dep->busy_slot++;
 		/*
Signature · 1 line
2.25.0
#1 lore raw

PATCH 1/1 usb: dwc3: Check that the request is valid in dwc3_gadget_giveback()

Quoted 5 lines · Vignesh Raghavendra

From: Jean-Jacques Hiblot <[email protected]>

This fixes potential issues reported by klokworks:
Pointer 'req' returned from call to function 'next_request' at line 531 and 538 may be NULL and will be dereferenced in dwc3_gadget_giveback()

Shouldn't you rather handle the issue in dwc3_remove_requests() ? Also, please explain what conditions trigger this issue, i.e. when req becomes NULL.

#2 lore raw

PATCH 1/1 usb: dwc3: Check that the request is valid in dwc3_gadget_giveback()

Quoted 11 lines · Marek Vasut
Quoted 5 lines · Vignesh Raghavendra

From: Jean-Jacques Hiblot <[email protected]>

This fixes potential issues reported by klokworks:
Pointer 'req' returned from call to function 'next_request' at line 531 and 538 may be NULL and will be dereferenced in dwc3_gadget_giveback()

Shouldn't you rather handle the issue in dwc3_remove_requests() ? Also, please explain what conditions trigger this issue, i.e. when req becomes NULL.

There is already a check for list_empty() before calling next_request() in dwc3_remove_requests() which makes sure that 'req' will not be NULL. So this report is a false positive.

Please ignore the patch.. Sorry for the trouble

Signature · 2 lines
Regards
Vignesh