From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [patch] usb: gadget: return -ENOMEM on allocation failure
Date: Wed, 21 May 2014 12:26:02 +0000 [thread overview]
Message-ID: <20140521122602.GA23396@mwanda> (raw)
The error handling is confusing in this function, but if you look
closely it is returning success after the allocation fails. I have
changed it to return -ENOMEM and re-written it to be more clear.
Fixes: 37a3a533429e ('usb: gadget: OS Feature Descriptors support')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 042c66b..8e70057 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1924,24 +1924,19 @@ fail:
int composite_os_desc_req_prepare(struct usb_composite_dev *cdev,
struct usb_ep *ep0)
{
- int ret = 0;
-
cdev->os_desc_req = usb_ep_alloc_request(ep0, GFP_KERNEL);
- if (!cdev->os_desc_req) {
- ret = PTR_ERR(cdev->os_desc_req);
- goto end;
- }
+ if (!cdev->os_desc_req)
+ return -ENOMEM;
/* OS feature descriptor length <= 4kB */
cdev->os_desc_req->buf = kmalloc(4096, GFP_KERNEL);
if (!cdev->os_desc_req->buf) {
- ret = PTR_ERR(cdev->os_desc_req->buf);
kfree(cdev->os_desc_req);
- goto end;
+ return -ENOMEM;
}
cdev->os_desc_req->complete = composite_setup_complete;
-end:
- return ret;
+
+ return 0;
}
void composite_dev_cleanup(struct usb_composite_dev *cdev)
next reply other threads:[~2014-05-21 12:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-21 12:26 Dan Carpenter [this message]
2014-05-22 5:53 ` [patch] usb: gadget: return -ENOMEM on allocation failure Andrzej Pietrasiewicz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140521122602.GA23396@mwanda \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox