Skip to contentSkip to conversation

usb: gadget: ci: Avoid null pointer dereference

PATCH New Marek Vasut 1 participant 1 message Jan 28, 2022 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: ci: Avoid null pointer dereference

The ci_req->hw_buf can be NULL, test whether it is and if so, avoid accessing it. Else, the system may crash.

---
 drivers/usb/gadget/ci_udc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/gadget/ci_udc.c +4 -1
index 226a9e6d671..542684c1c30 100644
@@ -402,6 +402,9 @@ align:
 
 flush:
 	hwaddr = (unsigned long)ci_req->hw_buf;
+	if (!hwaddr)
+		return 0;
+
 	aligned_used_len = roundup(req->length, ARCH_DMA_MINALIGN);
 	flush_dcache_range(hwaddr, hwaddr + aligned_used_len);
 
@@ -415,7 +418,7 @@ static void ci_debounce(struct ci_req *ci_req, int in)
 	unsigned long hwaddr = (unsigned long)ci_req->hw_buf;
 	uint32_t aligned_used_len;
 
-	if (in)
+	if (in || !hwaddr)
 		return;
 
 	aligned_used_len = roundup(req->actual, ARCH_DMA_MINALIGN);
Signature · 1 line
2.34.1