Skip to contentSkip to conversation

RDMA/ucma: Convert open-coded equivalent to memdup_user()

PATCH In review Roland Dreier 2 participants 2 messages Jul 27, 2012 1 message not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/ucma: Convert open-coded equivalent to memdup_user()

From: Roland Dreier <[email protected]>

Suggested by scripts/coccinelle/api/memdup_user.cocci.

---
 drivers/infiniband/core/ucma.c |   19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/infiniband/core/ucma.c +7 -12
index 893cb87..6bf8504 100644
@@ -1002,23 +1002,18 @@ static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
 	if (IS_ERR(ctx))
 		return PTR_ERR(ctx);
 
-	optval = kmalloc(cmd.optlen, GFP_KERNEL);
-	if (!optval) {
-		ret = -ENOMEM;
-		goto out1;
-	}
-
-	if (copy_from_user(optval, (void __user *) (unsigned long) cmd.optval,
-			   cmd.optlen)) {
-		ret = -EFAULT;
-		goto out2;
+	optval = memdup_user((void __user *) (unsigned long) cmd.optval,
+			     cmd.optlen);
+	if (IS_ERR(optval)) {
+		ret = PTR_ERR(optval);
+		goto out;
 	}
 
 	ret = ucma_set_option_level(ctx, cmd.level, cmd.optname, optval,
 				    cmd.optlen);
-out2:
 	kfree(optval);
-out1:
+
+out:
 	ucma_put_ctx(ctx);
 	return ret;
 }
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1343420939-13764-1-git-send-email-roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

Acked-by
#2 lore raw
Quoted 6 lines

From: Roland Dreier <[email protected]>

Suggested by scripts/coccinelle/api/memdup_user.cocci.

Quoted 39 lines
---
 drivers/infiniband/core/ucma.c |   19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/infiniband/core/ucma.c +7 -12
index 893cb87..6bf8504 100644
@@ -1002,23 +1002,18 @@ static ssize_t ucma_set_option(struct ucma_file *file,
 const char __user *inbuf,
 	if (IS_ERR(ctx))
 		return PTR_ERR(ctx);
 
-	optval = kmalloc(cmd.optlen, GFP_KERNEL);
-	if (!optval) {
-		ret = -ENOMEM;
-		goto out1;
-	}
-
-	if (copy_from_user(optval, (void __user *) (unsigned long) cmd.optval,
-			   cmd.optlen)) {
-		ret = -EFAULT;
-		goto out2;
+	optval = memdup_user((void __user *) (unsigned long) cmd.optval,
+			     cmd.optlen);
+	if (IS_ERR(optval)) {
+		ret = PTR_ERR(optval);
+		goto out;
 	}
 
 	ret = ucma_set_option_level(ctx, cmd.level, cmd.optname, optval,
 				    cmd.optlen);
-out2:
 	kfree(optval);
-out1:
+
+out:
 	ucma_put_ctx(ctx);
 	return ret;
Quoted 3 lines

}
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html