public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] usb: gadget: return -ENOMEM on allocation failure
@ 2014-05-21 12:26 Dan Carpenter
  2014-05-22  5:53 ` Andrzej Pietrasiewicz
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2014-05-21 12:26 UTC (permalink / raw)
  To: kernel-janitors

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)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] usb: gadget: return -ENOMEM on allocation failure
  2014-05-21 12:26 [patch] usb: gadget: return -ENOMEM on allocation failure Dan Carpenter
@ 2014-05-22  5:53 ` Andrzej Pietrasiewicz
  0 siblings, 0 replies; 2+ messages in thread
From: Andrzej Pietrasiewicz @ 2014-05-22  5:53 UTC (permalink / raw)
  To: kernel-janitors

W dniu 21.05.2014 14:26, Dan Carpenter pisze:
> 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>

Acked-by: Andrzej Pietrasiewicz <andrzej.p@samsung.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)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-22  5:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-21 12:26 [patch] usb: gadget: return -ENOMEM on allocation failure Dan Carpenter
2014-05-22  5:53 ` Andrzej Pietrasiewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox