bfa: replace 2 kzalloc/copy_from_user by memdup_user
authorFabian Frederick <fabf@skynet.be>
Fri, 14 Nov 2014 18:49:58 +0000 (19:49 +0100)
committerChristoph Hellwig <hch@lst.de>
Thu, 20 Nov 2014 08:11:29 +0000 (09:11 +0100)
This patch also removes unnecessary printk(KERN_INFO

Signed-off-by: Fabian Frederick <fabf@skynet.be>
Acked-by: Anil Gurumurthy <anil.gurumurthy@qlogic.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/scsi/bfa/bfad_debugfs.c

index 8e83d0474fe7c57560714dd488d4db1fcc1f4d15..74a307c0a2407c45af6ad42796d4944a3bec2bed 100644 (file)
@@ -260,18 +260,9 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
        unsigned long flags;
        void *kern_buf;
 
-       kern_buf = kzalloc(nbytes, GFP_KERNEL);
-
-       if (!kern_buf) {
-               printk(KERN_INFO "bfad[%d]: Failed to allocate buffer\n",
-                               bfad->inst_no);
-               return -ENOMEM;
-       }
-
-       if (copy_from_user(kern_buf, (void  __user *)buf, nbytes)) {
-               kfree(kern_buf);
-               return -ENOMEM;
-       }
+       kern_buf = memdup_user(buf, nbytes);
+       if (IS_ERR(kern_buf))
+               return PTR_ERR(kern_buf);
 
        rc = sscanf(kern_buf, "%x:%x", &addr, &len);
        if (rc < 2) {
@@ -336,18 +327,9 @@ bfad_debugfs_write_regwr(struct file *file, const char __user *buf,
        unsigned long flags;
        void *kern_buf;
 
-       kern_buf = kzalloc(nbytes, GFP_KERNEL);
-
-       if (!kern_buf) {
-               printk(KERN_INFO "bfad[%d]: Failed to allocate buffer\n",
-                               bfad->inst_no);
-               return -ENOMEM;
-       }
-
-       if (copy_from_user(kern_buf, (void  __user *)buf, nbytes)) {
-               kfree(kern_buf);
-               return -ENOMEM;
-       }
+       kern_buf = memdup_user(buf, nbytes);
+       if (IS_ERR(kern_buf))
+               return PTR_ERR(kern_buf);
 
        rc = sscanf(kern_buf, "%x:%x", &addr, &val);
        if (rc < 2) {