Skip to contentSkip to conversation

usb: dwc3: gadget: Move null pinter check after window closed

PATCH Superseded Albert Wang 2 participants 2 messages May 12, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: dwc3: gadget: Move null pinter check after window closed

After inspecting further, we do see the locking is implicit, with the main gotcha being the unlock/re-lock. That creates a window for a race to happen. This change moves the NULL check to be adjacent to where to it's used and after the window is "closed".

Fixes 26288448120b ("usb: dwc3: gadget: Fix null pointer exception")

---
v2: Remove redundant 'else' and add additional comments and more
descriptive commit text

 drivers/usb/dwc3/gadget.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/usb/dwc3/gadget.c +8 -3
index 19477f4bbf54..fda58951cf27 100644
@@ -3366,14 +3366,19 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep,
 	struct dwc3		*dwc = dep->dwc;
 	bool			no_started_trb = true;
 
-	if (!dep->endpoint.desc)
-		return no_started_trb;
-
+	/*
+	 * This function eventually leads to dwc3_giveback() which unlocks
+	 * the dwc->lock and relocks afterwards. This actually creates a
+	 * a window for a race to happen.
+	 */
 	dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);
 
 	if (dep->flags & DWC3_EP_END_TRANSFER_PENDING)
 		goto out;
 
+	if (!dep->endpoint.desc)
+		return no_started_trb;
+
 	if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
 		list_empty(&dep->started_list) &&
 		(list_empty(&dep->pending_list) || status == -EXDEV))
Signature · 1 line
2.36.0.550.gb090851708-goog
maintainer
#1 lore raw
Quoted 8 lines · Albert Wang

After inspecting further, we do see the locking is implicit, with the main gotcha being the unlock/re-lock. That creates a window for a race to happen. This change moves the NULL check to be adjacent to where to it's used and after the window is "closed".

Fixes 26288448120b ("usb: dwc3: gadget: Fix null pointer exception")

No blank line between Fixes: and signed-off-by please.

Quoted 3 lines

---
v2: Remove redundant 'else' and add additional comments and more
descriptive commit text

I see two v2 copies on the lists for this commit.

Please send a v3, never duplicate the versions, that just causes confusion, right?

thanks,

greg k-h