All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Trond.Myklebust@netapp.com
Cc: linux-nfs@vger.kernel.org
Subject: kstrtox: convert net/sunrpc/
Date: Fri, 1 Apr 2011 00:36:25 +0300	[thread overview]
Message-ID: <20110331213625.GA3637@p183.telecom.by> (raw)

* fix a bug in rpc_parse_scope_id() where successfull parsing of
  scope ID was an error.
  
  I'm not sure whether ID=0 should be banned, though.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 net/sunrpc/addr.c     |   20 ++++++++------------
 net/sunrpc/auth.c     |   15 ++++++---------
 net/sunrpc/xprtsock.c |    8 +++++---
 3 files changed, 19 insertions(+), 24 deletions(-)

--- a/net/sunrpc/addr.c
+++ b/net/sunrpc/addr.c
@@ -173,15 +173,15 @@ static int rpc_parse_scope_id(const char *buf, const size_t buflen,
 	len = (buf + buflen) - delim - 1;
 	p = kstrndup(delim + 1, len, GFP_KERNEL);
 	if (p) {
-		unsigned long scope_id = 0;
 		struct net_device *dev;
+		u32 scope_id;
 
 		dev = dev_get_by_name(&init_net, p);
 		if (dev != NULL) {
 			scope_id = dev->ifindex;
 			dev_put(dev);
 		} else {
-			if (strict_strtoul(p, 10, &scope_id) == 0) {
+			if (kstrtou32(p, 10, &scope_id) < 0) {
 				kfree(p);
 				return 0;
 			}
@@ -299,7 +299,7 @@ EXPORT_SYMBOL_GPL(rpc_sockaddr2uaddr);
  * @sap: buffer into which to plant socket address
  * @salen: size of buffer
  *
- * @uaddr does not have to be '\0'-terminated, but strict_strtoul() and
+ * @uaddr does not have to be '\0'-terminated, but kstrto*() and
  * rpc_pton() require proper string termination to be successful.
  *
  * Returns the size of the socket address if successful; otherwise
@@ -309,8 +309,8 @@ size_t rpc_uaddr2sockaddr(const char *uaddr, const size_t uaddr_len,
 			  struct sockaddr *sap, const size_t salen)
 {
 	char *c, buf[RPCBIND_MAXUADDRLEN + sizeof('\0')];
-	unsigned long portlo, porthi;
-	unsigned short port;
+	u8 portlo, porthi;
+	u16 port;
 
 	if (uaddr_len > RPCBIND_MAXUADDRLEN)
 		return 0;
@@ -321,21 +321,17 @@ size_t rpc_uaddr2sockaddr(const char *uaddr, const size_t uaddr_len,
 	c = strrchr(buf, '.');
 	if (unlikely(c == NULL))
 		return 0;
-	if (unlikely(strict_strtoul(c + 1, 10, &portlo) != 0))
-		return 0;
-	if (unlikely(portlo > 255))
+	if (unlikely(kstrtou8(c + 1, 10, &portlo) != 0))
 		return 0;
 
 	*c = '\0';
 	c = strrchr(buf, '.');
 	if (unlikely(c == NULL))
 		return 0;
-	if (unlikely(strict_strtoul(c + 1, 10, &porthi) != 0))
-		return 0;
-	if (unlikely(porthi > 255))
+	if (unlikely(kstrtou8(c + 1, 10, &porthi) != 0))
 		return 0;
 
-	port = (unsigned short)((porthi << 8) | portlo);
+	port = (porthi << 8) | portlo;
 
 	*c = '\0';
 	if (rpc_pton(buf, strlen(buf), sap, salen) == 0)
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -41,24 +41,21 @@ static unsigned long number_cred_unused;
 #define MAX_HASHTABLE_BITS (14)
 static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp)
 {
-	unsigned long num;
-	unsigned int nbits;
+	unsigned int num, nbits;
 	int ret;
 
 	if (!val)
-		goto out_inval;
-	ret = strict_strtoul(val, 0, &num);
-	if (ret == -EINVAL)
-		goto out_inval;
+		return -EINVAL;
+	ret = kstrtouint(val, 0, &num);
+	if (ret < 0)
+		return ret;
 	nbits = fls(num);
 	if (num > (1U << nbits))
 		nbits++;
 	if (nbits > MAX_HASHTABLE_BITS || nbits < 2)
-		goto out_inval;
+		return -EINVAL;
 	*(unsigned int *)kp->arg = nbits;
 	return 0;
-out_inval:
-	return -EINVAL;
 }
 
 static int param_get_hashtbl_sz(char *buffer, const struct kernel_param *kp)
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -2502,13 +2502,15 @@ static int param_set_uint_minmax(const char *val,
 		const struct kernel_param *kp,
 		unsigned int min, unsigned int max)
 {
-	unsigned long num;
+	unsigned int num;
 	int ret;
 
 	if (!val)
 		return -EINVAL;
-	ret = strict_strtoul(val, 0, &num);
-	if (ret == -EINVAL || num < min || num > max)
+	ret = kstrtouint(val, 0, &num);
+	if (ret < 0)
+		return ret;
+	if (num < min || num > max)
 		return -EINVAL;
 	*((unsigned int *)kp->arg) = num;
 	return 0;

             reply	other threads:[~2011-03-31 21:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-31 21:36 Alexey Dobriyan [this message]
2011-04-01 16:57 ` kstrtox: convert net/sunrpc/ Chuck Lever
2011-04-02 11:17   ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110331213625.GA3637@p183.telecom.by \
    --to=adobriyan@gmail.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.