Skip to content

Commit

Permalink
V4L/DVB: drivers/media: Use memdup_user
Browse files Browse the repository at this point in the history
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: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Julia Lawall authored and Mauro Carvalho Chehab committed Aug 2, 2010
1 parent 3e9442c commit c6cfe05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
10 changes: 3 additions & 7 deletions drivers/media/dvb/dvb-core/dvb_demux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1130,13 +1130,9 @@ static int dvbdmx_write(struct dmx_demux *demux, const char __user *buf, size_t
if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE))
return -EINVAL;

p = kmalloc(count, GFP_USER);
if (!p)
return -ENOMEM;
if (copy_from_user(p, buf, count)) {
kfree(p);
return -EFAULT;
}
p = memdup_user(buf, count);
if (IS_ERR(p))
return PTR_ERR(p);
if (mutex_lock_interruptible(&dvbdemux->mutex)) {
kfree(p);
return -ERESTARTSYS;
Expand Down
13 changes: 4 additions & 9 deletions drivers/media/video/dabusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,16 +706,11 @@ static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg
switch (cmd) {

case IOCTL_DAB_BULK:
pbulk = kmalloc(sizeof (bulk_transfer_t), GFP_KERNEL);
pbulk = memdup_user((void __user *)arg,
sizeof(bulk_transfer_t));

if (!pbulk) {
ret = -ENOMEM;
break;
}

if (copy_from_user (pbulk, (void __user *) arg, sizeof (bulk_transfer_t))) {
ret = -EFAULT;
kfree (pbulk);
if (IS_ERR(pbulk)) {
ret = PTR_ERR(pbulk);
break;
}

Expand Down

0 comments on commit c6cfe05

Please sign in to comment.