Skip to contentSkip to conversation

drivers: message: fusion: Use memdup_user function

PATCH New Alexandru Gheorghiu 1 participant 1 message Mar 19, 2013 LSI Logic MPT fusion drivers (FC/SAS/SPI)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: message: fusion: Use memdup_user function

Used memdup_user function instead of kmalloc and copy_from_user. Patch found using coccinelle.

---
 drivers/message/fusion/mptctl.c |   13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/message/fusion/mptctl.c +3 -10
index b383b69..2669e83 100644
@@ -1268,19 +1268,12 @@ mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
 	else
 		return -EFAULT;
 
-	karg = kmalloc(data_size, GFP_KERNEL);
-	if (karg == NULL) {
-		printk(KERN_ERR MYNAM "%s::mpt_ioctl_iocinfo() @%d - no memory available!\n",
-				__FILE__, __LINE__);
-		return -ENOMEM;
-	}
-
-	if (copy_from_user(karg, uarg, data_size)) {
+	karg = memdup_user(uarg, data_size);
+	if (IS_ERR(karg)) {
 		printk(KERN_ERR MYNAM "%s@%d::mptctl_getiocinfo - "
 			"Unable to read in mpt_ioctl_iocinfo struct @ %p\n",
 				__FILE__, __LINE__, uarg);
-		kfree(karg);
-		return -EFAULT;
+		return PTR_ERR(karg);
 	}
 
 	if (((iocnum = mpt_verify_adapter(karg->hdr.iocnum, &ioc)) < 0) ||
Signature · 1 line
1.7.9.5