linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 RESEND] usb: Use memdup_user to reuse the code
@ 2015-12-11  5:40 Pathak, Rahul (R.)
  2015-12-30  9:15 ` Pathak, Rahul (R.)
  0 siblings, 1 reply; 3+ messages in thread
From: Pathak, Rahul (R.) @ 2015-12-11  5:40 UTC (permalink / raw)
  To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu,
	kborer@gmail.com, chasemetzger15@gmail.com,
	dan.carpenter@oracle.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, Babu, Viswanathan (V.)

From: Rahul Pathak <rpathak@visteon.com>

Fixing coccicheck warning which recommends to use memdup_user instead
to reimplement its code, using memdup_user simplifies the code

./drivers/usb/core/devio.c:1398:11-18: WARNING opportunity for memdup_user


Signed-off-by: Rahul Pathak <rpathak@visteon.com>

---

Changes after v1: setting isopkt=NULL for proper kfree() call

---
 drivers/usb/core/devio.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 38ae877c..844407c 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1395,11 +1395,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
 		number_of_packets = uurb->number_of_packets;
 		isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) *
 				   number_of_packets;
-		isopkt = kmalloc(isofrmlen, GFP_KERNEL);
-		if (!isopkt)
-			return -ENOMEM;
-		if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) {
-			ret = -EFAULT;
+		isopkt = memdup_user(iso_frame_desc, isofrmlen);
+		if (IS_ERR(isopkt)) {
+			ret = PTR_ERR(isopkt);
+			isopkt = NULL;
 			goto error;
 		}
 		for (totlen = u = 0; u < number_of_packets; u++) {
-- 
1.9.1

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

* Re: [PATCH v2 RESEND] usb: Use memdup_user to reuse the code
  2015-12-11  5:40 [PATCH v2 RESEND] usb: Use memdup_user to reuse the code Pathak, Rahul (R.)
@ 2015-12-30  9:15 ` Pathak, Rahul (R.)
  2016-01-04 15:16   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Pathak, Rahul (R.) @ 2015-12-30  9:15 UTC (permalink / raw)
  To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu,
	kborer@gmail.com, chasemetzger15@gmail.com,
	dan.carpenter@oracle.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org

Hello Greg,

This patch is not yet merged, its already been reviewed and acked by Alan.

Thanks
Rahul

On Thu, Dec 10, 2015 at 09:40:33PM -0800, Rahul Pathak wrote:
> From: Rahul Pathak <rpathak@visteon.com>
> 
> Fixing coccicheck warning which recommends to use memdup_user instead
> to reimplement its code, using memdup_user simplifies the code
> 
> ./drivers/usb/core/devio.c:1398:11-18: WARNING opportunity for memdup_user
> 
> 
> Signed-off-by: Rahul Pathak <rpathak@visteon.com>
> 
> ---
> 
> Changes after v1: setting isopkt=NULL for proper kfree() call
> 
> ---
>  drivers/usb/core/devio.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index 38ae877c..844407c 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1395,11 +1395,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
>  		number_of_packets = uurb->number_of_packets;
>  		isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) *
>  				   number_of_packets;
> -		isopkt = kmalloc(isofrmlen, GFP_KERNEL);
> -		if (!isopkt)
> -			return -ENOMEM;
> -		if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) {
> -			ret = -EFAULT;
> +		isopkt = memdup_user(iso_frame_desc, isofrmlen);
> +		if (IS_ERR(isopkt)) {
> +			ret = PTR_ERR(isopkt);
> +			isopkt = NULL;
>  			goto error;
>  		}
>  		for (totlen = u = 0; u < number_of_packets; u++) {
> -- 
> 1.9.1

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

* Re: [PATCH v2 RESEND] usb: Use memdup_user to reuse the code
  2015-12-30  9:15 ` Pathak, Rahul (R.)
@ 2016-01-04 15:16   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2016-01-04 15:16 UTC (permalink / raw)
  To: Pathak, Rahul (R.)
  Cc: gregkh@linuxfoundation.org, stern@rowland.harvard.edu,
	kborer@gmail.com, chasemetzger15@gmail.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org

On Wed, Dec 30, 2015 at 09:15:55AM +0000, Pathak, Rahul (R.) wrote:
> Hello Greg,
> 
> This patch is not yet merged, its already been reviewed and acked by Alan.
> 

Relax.  Everyone is on vacation.  This stuff is not life or death that
it must be done right away.

regards,
dan carpenter


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

end of thread, other threads:[~2016-01-04 15:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-11  5:40 [PATCH v2 RESEND] usb: Use memdup_user to reuse the code Pathak, Rahul (R.)
2015-12-30  9:15 ` Pathak, Rahul (R.)
2016-01-04 15:16   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).