linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c-dev: Use memdup_user
@ 2011-08-13  8:17 Thomas Meyer
       [not found] ` <1313223430.16820.14.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Meyer @ 2011-08-13  8:17 UTC (permalink / raw)
  To: khali, linux-i2c, Linux Kernel Mailing List

From: Thomas Meyer <thomas@m3y3r.de>

 Use kmemdup_user rather than duplicating its implementation
 This is a little bit restricted to reduce false positives

 The semantic patch that makes this output is available
 in scripts/coccinelle/api/memdup_user.cocci.

 More information about semantic patching is available at
 http://coccinelle.lip6.fr/

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---

diff -u -p a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
--- a/drivers/i2c/i2c-dev.c 2011-04-14 10:34:17.670994023 +0200
+++ b/drivers/i2c/i2c-dev.c 2011-08-01 22:08:25.888046385 +0200
@@ -251,15 +251,10 @@ static noinline int i2cdev_ioctl_rdrw(st
 	if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
 		return -EINVAL;
 
-	rdwr_pa = kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), GFP_KERNEL);
-	if (!rdwr_pa)
-		return -ENOMEM;
-
-	if (copy_from_user(rdwr_pa, rdwr_arg.msgs,
-			   rdwr_arg.nmsgs * sizeof(struct i2c_msg))) {
-		kfree(rdwr_pa);
-		return -EFAULT;
-	}
+	rdwr_pa = memdup_user(rdwr_arg.msgs,
+			      rdwr_arg.nmsgs * sizeof(struct i2c_msg));
+	if (IS_ERR(rdwr_pa))
+		return PTR_ERR(rdwr_pa);
 
 	data_ptrs = kmalloc(rdwr_arg.nmsgs * sizeof(u8 __user *), GFP_KERNEL);
 	if (data_ptrs == NULL) {

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

* Re: [PATCH] i2c-dev: Use memdup_user
       [not found] ` <1313223430.16820.14.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2012-01-07 10:00   ` Jean Delvare
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2012-01-07 10:00 UTC (permalink / raw)
  To: Thomas Meyer; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Linux Kernel Mailing List

Hi Thomas,

Sorry for the late reply.

On Sat, 13 Aug 2011 10:17:06 +0200, Thomas Meyer wrote:
> From: Thomas Meyer <thomas-VsYtu1Qij5c@public.gmane.org>
> 
>  Use kmemdup_user rather than duplicating its implementation
>  This is a little bit restricted to reduce false positives
> 
>  The semantic patch that makes this output is available
>  in scripts/coccinelle/api/memdup_user.cocci.
> 
>  More information about semantic patching is available at
>  http://coccinelle.lip6.fr/
> 
> Signed-off-by: Thomas Meyer <thomas-VsYtu1Qij5c@public.gmane.org>

Applied, thanks.

-- 
Jean Delvare

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

end of thread, other threads:[~2012-01-07 10:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-13  8:17 [PATCH] i2c-dev: Use memdup_user Thomas Meyer
     [not found] ` <1313223430.16820.14.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2012-01-07 10:00   ` Jean Delvare

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).