Skip to contentSkip to conversation

staging: lustre: use memdup_user to allocate memory and copy from user

PATCH New Dafna Hirschfeld 1 participant 1 message Feb 19, 2018 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: lustre: use memdup_user to allocate memory and copy from user

Replace a call to kmalloc and a call to copy_from_user with a call to memdup_user to simplify the code.
Issue found with coccicheck.

---
 drivers/staging/lustre/lnet/selftest/conctl.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/lustre/lnet/selftest/conctl.c +4 -6
index 34ba440..3c919a5 100644
@@ -648,12 +648,10 @@ static int lst_test_add_ioctl(struct lstio_test_args *args)
 		return -EINVAL;
 
 	if (args->lstio_tes_param) {
-		param = kmalloc(args->lstio_tes_param_len, GFP_KERNEL);
-		if (!param)
-			goto out;
-		if (copy_from_user(param, args->lstio_tes_param,
-				   args->lstio_tes_param_len)) {
-			rc = -EFAULT;
+		param = memdup_user(args->lstio_tes_param,
+				    args->lstio_tes_param_len);
+		if (IS_ERR(param)) {
+			rc = PTR_ERR(param);
 			goto out;
 		}
 	}
Signature · 1 line
2.7.4