drivers/mtd: Use memdup_user
commitdf1f1d1cb43b4ffdef5ba5f0623e2f73e94ce030
authorJulia Lawall <julia@diku.dk>
Sat, 22 May 2010 08:22:49 +0000 (22 10:22 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 22 May 2010 10:49:37 +0000 (22 11:49 +0100)
treefdef68b0b5230b9f49f7b26eee33aee4e4f042e3
parent39c5837d7968ffd68e1d3c79efba1631b7f513d9
drivers/mtd: Use memdup_user

Use memdup_user when user data is immediately copied into the
allocated region.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression from,to,size,flag;
position p;
identifier l1,l2;
@@

-  to = \(kmalloc@p\|kzalloc@p\)(size,flag);
+  to = memdup_user(from,size);
   if (
-      to==NULL
+      IS_ERR(to)
                 || ...) {
   <+... when != goto l1;
-  -ENOMEM
+  PTR_ERR(to)
   ...+>
   }
-  if (copy_from_user(to, from, size) != 0) {
-    <+... when != goto l2;
-    -EFAULT
-    ...+>
-  }
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtdchar.c