Staging: rdma: Use memdup_user
authorKsenija Stanojevic <ksenija.stanojevic@gmail.com>
Fri, 9 Oct 2015 13:56:59 +0000 (15:56 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Oct 2015 03:35:21 +0000 (20:35 -0700)
Use memdup_user when user data is immediately copied into the
allocated region.

Issue found using coccinelle.

Signed-off-by: Ksenija Stanojevic<ksenija.stanojevic@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rdma/ipath/ipath_fs.c

index 25422a3a72387eb39bd5bac638bcf62a198373bd..796af686700739c8401bd49c9ea97d43f6c3d5de 100644 (file)
@@ -195,16 +195,9 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
                goto bail;
        }
 
-       tmp = kmalloc(count, GFP_KERNEL);
-       if (!tmp) {
-               ret = -ENOMEM;
-               goto bail;
-       }
-
-       if (copy_from_user(tmp, buf, count)) {
-               ret = -EFAULT;
-               goto bail_tmp;
-       }
+       tmp = memdup_user(buf, count);
+       if (IS_ERR(tmp))
+               return PTR_ERR(tmp);
 
        dd = file_inode(file)->i_private;
        if (ipath_eeprom_write(dd, pos, tmp, count)) {
This page took 0.026872 seconds and 5 git commands to generate.