All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/4] sctp: use memdup_user to copy data from userspace
@ 2010-05-26  9:51 Shan Wei
  0 siblings, 0 replies; only message in thread
From: Shan Wei @ 2010-05-26  9:51 UTC (permalink / raw)
  To: linux-sctp

Use common function to simply code.

Signed-off-by: Shan Wei <shanwei@cn.fujitsu.com>
---
 net/sctp/socket.c |   22 ++++++----------------
 1 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index ca44917..96cc3f9 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -3201,14 +3201,9 @@ static int sctp_setsockopt_hmac_ident(struct sock *sk,
 	if (optlen < sizeof(struct sctp_hmacalgo))
 		return -EINVAL;
 
-	hmacs = kmalloc(optlen, GFP_KERNEL);
-	if (!hmacs)
-		return -ENOMEM;
-
-	if (copy_from_user(hmacs, optval, optlen)) {
-		err = -EFAULT;
-		goto out;
-	}
+	hmacs= memdup_user(optval, optlen);
+	if (IS_ERR(hmacs))
+		return PTR_ERR(hmacs);
 
 	idents = hmacs->shmac_num_idents;
 	if (idents = 0 || idents > SCTP_AUTH_NUM_HMACS ||
@@ -3243,14 +3238,9 @@ static int sctp_setsockopt_auth_key(struct sock *sk,
 	if (optlen <= sizeof(struct sctp_authkey))
 		return -EINVAL;
 
-	authkey = kmalloc(optlen, GFP_KERNEL);
-	if (!authkey)
-		return -ENOMEM;
-
-	if (copy_from_user(authkey, optval, optlen)) {
-		ret = -EFAULT;
-		goto out;
-	}
+	authkey= memdup_user(optval, optlen);
+	if (IS_ERR(authkey))
+		return PTR_ERR(authkey);
 
 	if (authkey->sca_keylength > optlen - sizeof(struct sctp_authkey)) {
 		ret = -EINVAL;
-- 
1.7.0





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-05-26  9:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-26  9:51 [PATCH 4/4] sctp: use memdup_user to copy data from userspace Shan Wei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.