From: Marek Vasut Date: Fri, 28 Jan 2022 03:39:09 +0000 (+0100) Subject: usb: gadget: ci: Avoid null pointer dereference X-Git-Url: http://git.dujemihanovic.xyz/img/sics.gif?a=commitdiff_plain;h=1f54025d70c4c9e6ec8d82d8b69b0d66a7bbbdc1;p=u-boot.git 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. Signed-off-by: Marek Vasut Cc: Peter Chen Cc: Li Jun Cc: Peng Fan --- diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index 226a9e6d67..542684c1c3 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -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);