Btrfs: use memdup_user helpers
authorJulia Lawall <julia@diku.dk>
Fri, 29 Oct 2010 19:14:18 +0000 (15:14 -0400)
committerChris Mason <chris.mason@oracle.com>
Fri, 29 Oct 2010 19:14:18 +0000 (15:14 -0400)
commit2354d08fe9aeec3e451b85cb5387a6b28dbca0b1
tree7a3f43dfac81fc54faf231400a4b871ca24bb031
parent18e503d695ff8ff9a43768555aa74575bf6b77f3
Btrfs: use memdup_user helpers

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>
Cc: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/ioctl.c