[PATCH] drivers: message: fusion: Use memdup_user function

From: Alexandru Gheorghiu
Date: Tue Mar 19 2013 - 09:28:22 EST


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

Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@xxxxxxxxx>
---
drivers/message/fusion/mptctl.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index b383b69..2669e83 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -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) ||
--
1.7.9.5

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