usb: gadget: udc: net2280: Fix NULL pointer dereference in net2280_free_request
PATCH 1/1 usb: gadget: udc: net2280: Fix NULL pointer dereference in net2280_free_request
When the function net2280_free_request is called with a NULL _ep pointer, the function still tries to dereference _ep before returning. This leads to a NULL pointer dereference and possible kernel panic.
This bug can be triggered when a USB endpoint is removed unexpectedly and the driver attempts to free resources associated with it.
Move the NULL check before calling container_of to ensure that the function does not attempt to dereference a NULL pointer. This prevents the kernel from crashing when either _ep or _req is NULL.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by Mikhail Arkhipov <[email protected]>
--- drivers/usb/gadget/udc/net2280.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/net2280.c +2 -3
@@ -582,13 +582,12 @@ static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req)struct net2280_ep *ep;struct net2280_request *req; - ep = container_of(_ep, struct net2280_ep, ep);if (!_ep || !_req) { -dev_err (&ep->dev->pdev->dev,"%s: Invalid ep=%p or req=%p\n" , - __func__, _ep, _req); +dev_err (NULL ,"%s: Invalid ep=%p or req=%p\n" , __func__, _ep, _req);return ; } + ep = container_of(_ep, struct net2280_ep, ep); req = container_of(_req, struct net2280_request, req);WARN_ON (!list_empty (&req->queue));if (req->td)
Signature · 1 line
2.39.3 (Apple Git-146)