Skip to contentSkip to conversation

USB: fix possible memory leak in pxa27x_udc

PATCH In review Marcin Slusarz 2 participants 2 messages Jun 22, 2008 – Jun 23, 2008 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: fix possible memory leak in pxa27x_udc

Fix memory leak when _ep is null.
http://bugzilla.kernel.org/show_bug.cgi?id=10660

---
 drivers/usb/gadget/pxa27x_udc.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/usb/gadget/pxa27x_udc.c +4 -1
index e02bfd4..e3a5d53 100644
@@ -650,8 +650,11 @@ pxa_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
 {
 	struct pxa27x_request *req;
 
+	if (!_ep)
+		return NULL;
+
 	req = kzalloc(sizeof *req, gfp_flags);
-	if (!req || !_ep)
+	if (!req)
 		return NULL;
 
 	INIT_LIST_HEAD(&req->queue);
Signature · 1 line
1.5.4.5
#1 lore raw

drivers/usb/gadget/pxa27x_udc.c pxa_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) · line 655

Quoted 9 lines · Marcin Slusarz
drivers/usb/gadget/pxa27x_udc.c +3 -0
@@ -650,8 +650,11 @@ pxa_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
 {
 	struct pxa27x_request *req;
 
+	if (!_ep)
+		return NULL;
+

Correct enough as it goes, except that it *can't* be null by virtue of how it's called. See <include/linux/usb/gadget.h> for:

static inline struct usb_request *usb_ep_alloc_request(struct usb_ep *ep,
gfp_t gfp_flags)

{
        return ep->ops->alloc_request(ep, gfp_flags);
}

If it were null it couldn't get here. A better fix would just remove the null check here (and possibly elsewhere).

- Dave

Quoted 9 lines
drivers/usb/gadget/pxa27x_udc.c +1 -1
 	req = kzalloc(sizeof *req, gfp_flags);
-	if (!req || !_ep)
+	if (!req)
 		return NULL;
 
 	INIT_LIST_HEAD(&req->queue);
Signature · 1 line
1.5.4.5