[RFC 1/1] drivers/scsi/bfa/bfad_debugfs.c: replace 2 kzalloc/copy_from_user to memdup_user

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(memdup_user can be used to replace kmalloc/copy_from_user. Not sure if it's ok with kzalloc ...)

Cc: linux-scsi@xxxxxxxxxxxxxxx
Cc: Anil Gurumurthy <anil.gurumurthy@xxxxxxxxxx>
Cc: "James E.J. Bottomley" <JBottomley@xxxxxxxxxxxxx>
Signed-off-by: Fabian Frederick <fabf@xxxxxxxxx>
---
 drivers/scsi/bfa/bfad_debugfs.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
index 8e83d04..07b9e36 100644
--- a/drivers/scsi/bfa/bfad_debugfs.c
+++ b/drivers/scsi/bfa/bfad_debugfs.c
@@ -260,17 +260,12 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
 	unsigned long flags;
 	void *kern_buf;
 
-	kern_buf = kzalloc(nbytes, GFP_KERNEL);
+	kern_buf = memdup_user((void __user *)buf, nbytes);
 
-	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;
+	if (IS_ERR(kern_buf)) {
+		printk(KERN_INFO "bfad[%d]: Failed to copy buffer\n",
+		       bfad->inst_no);
+		return PTR_ERR(kern_buf);
 	}
 
 	rc = sscanf(kern_buf, "%x:%x", &addr, &len);
@@ -336,17 +331,12 @@ bfad_debugfs_write_regwr(struct file *file, const char __user *buf,
 	unsigned long flags;
 	void *kern_buf;
 
-	kern_buf = kzalloc(nbytes, GFP_KERNEL);
+	kern_buf = memdup_user((void __user *)buf, nbytes);
 
-	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;
+	if (IS_ERR(kern_buf)) {
+		printk(KERN_INFO "bfad[%d]: Failed to copy buffer\n",
+		       bfad->inst_no);
+		return PTR_ERR(kern_buf);
 	}
 
 	rc = sscanf(kern_buf, "%x:%x", &addr, &val);
-- 
1.8.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux