Skip to contentSkip to conversation

use kstrtoul, etc

PATCH In review Julia Lawall 5 participants 13 messages Nov 6, 2011 – Nov 9, 2011

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover use kstrtoul, etc

These patches replace calls to strict_strtoul, etc by the corresponding calls to kstrtoul. The complete semantic patch that makes these changes is as follows. This semantic patch checks that the types are as expected, which was always the case for these files.

// <smpl>
@@
expression a,b;
{int,long} *c;
@@

-strict_strtol
+kstrtol
(a,b,c)

@@
expression a,b;
long long *c;
@@

-strict_strtoll
+kstrtoll
(a,b,c)

@@
typedef ulong;
expression a,b;
{ulong,unsigned long,unsigned int,size_t} *c;
@@

-strict_strtoul
+kstrtoul
(a,b,c)

@@
expression a,b;
unsigned long long *c;
@@

-strict_strtoull
+kstrtoull
(a,b,c)

@@
expression a,b;
u64 *c;
@@

-strict_strtoull
+kstrtou64
(a,b,c)

@@
@@

(
+BAD(
strict_strtoull(...)
+)
|
+BAD(
strict_strtoul(...)
+)
|
+BAD(
strict_strtol(...)
+)
|
+BAD(
strict_strtoll(...)
+)
)
// </smpl>

#1 lore raw

PATCH 1/5 net/batman-adv: use kstrtoul, etc

From: Julia Lawall <[email protected]>

Use kstrtoul, etc instead of the now deprecated strict_strtoul, etc.

A semantic patch rule for the kstrtoul case is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,b;
{int,long} *c;
@@

-strict_strtoul
+kstrtoul
(a,b,c)
// </smpl>

---
 net/batman-adv/bat_sysfs.c      |    4 ++--
 net/batman-adv/gateway_common.c |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
net/batman-adv/bat_sysfs.c +2 -2
diff -u -p a/net/batman-adv/bat_sysfs.c b/net/batman-adv/bat_sysfs.c
@@ -174,7 +174,7 @@ static int store_uint_attr(const char *b
 	unsigned long uint_val;
 	int ret;
 
-	ret = strict_strtoul(buff, 10, &uint_val);
+	ret = kstrtoul(buff, 10, &uint_val);
 	if (ret) {
 		bat_info(net_dev,
 			 "%s: Invalid parameter received: %s\n",
@@ -239,7 +239,7 @@ static ssize_t store_vis_mode(struct kob
 	unsigned long val;
 	int ret, vis_mode_tmp = -1;
 
-	ret = strict_strtoul(buff, 10, &val);
+	ret = kstrtoul(buff, 10, &val);
 
 	if (((count == 2) && (!ret) && (val == VIS_TYPE_CLIENT_UPDATE)) ||
 	    (strncmp(buff, "client", 6) == 0) ||
net/batman-adv/gateway_common.c +2 -2
diff -u -p a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
@@ -97,7 +97,7 @@ static bool parse_gw_bandwidth(struct ne
 			*tmp_ptr = '\0';
 	}
 
-	ret = strict_strtol(buff, 10, &ldown);
+	ret = kstrtol(buff, 10, &ldown);
 	if (ret) {
 		bat_err(net_dev,
 			"Download speed of gateway mode invalid: %s\n",
@@ -122,7 +122,7 @@ static bool parse_gw_bandwidth(struct ne
 				*tmp_ptr = '\0';
 		}
 
-		ret = strict_strtol(slash_ptr + 1, 10, &lup);
+		ret = kstrtol(slash_ptr + 1, 10, &lup);
 		if (ret) {
 			bat_err(net_dev,
 				"Upload speed of gateway mode invalid: "
#3 lore raw

PATCH 2/5 net/sunrpc: use kstrtoul, etc

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Use kstrtoul, etc instead of the now deprecated strict_strtoul, etc.

A semantic patch rule for the kstrtoul case is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,b;
{int,long} *c;
@@

-strict_strtoul
+kstrtoul
(a,b,c)
// </smpl>

---
 net/sunrpc/addr.c     |    6 +++---
 net/sunrpc/auth.c     |    2 +-
 net/sunrpc/xprtsock.c |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
net/sunrpc/addr.c +3 -3
diff -u -p a/net/sunrpc/addr.c b/net/sunrpc/addr.c
@@ -182,7 +182,7 @@ static int rpc_parse_scope_id(const char
 			scope_id = dev->ifindex;
 			dev_put(dev);
 		} else {
-			if (strict_strtoul(p, 10, &scope_id) = 0) {
+			if (kstrtoul(p, 10, &scope_id) = 0) {
 				kfree(p);
 				return 0;
 			}
@@ -322,7 +322,7 @@ size_t rpc_uaddr2sockaddr(const char *ua
 	c = strrchr(buf, '.');
 	if (unlikely(c = NULL))
 		return 0;
-	if (unlikely(strict_strtoul(c + 1, 10, &portlo) != 0))
+	if (unlikely(kstrtoul(c + 1, 10, &portlo) != 0))
 		return 0;
 	if (unlikely(portlo > 255))
 		return 0;
@@ -331,7 +331,7 @@ size_t rpc_uaddr2sockaddr(const char *ua
 	c = strrchr(buf, '.');
 	if (unlikely(c = NULL))
 		return 0;
-	if (unlikely(strict_strtoul(c + 1, 10, &porthi) != 0))
+	if (unlikely(kstrtoul(c + 1, 10, &porthi) != 0))
 		return 0;
 	if (unlikely(porthi > 255))
 		return 0;
net/sunrpc/auth.c +1 -1
diff -u -p a/net/sunrpc/auth.c b/net/sunrpc/auth.c
@@ -47,7 +47,7 @@ static int param_set_hashtbl_sz(const ch
 
 	if (!val)
 		goto out_inval;
-	ret = strict_strtoul(val, 0, &num);
+	ret = kstrtoul(val, 0, &num);
 	if (ret = -EINVAL)
 		goto out_inval;
 	nbits = fls(num);
net/sunrpc/xprtsock.c +1 -1
diff -u -p a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
@@ -2925,7 +2925,7 @@ static int param_set_uint_minmax(const c
 
 	if (!val)
 		return -EINVAL;
-	ret = strict_strtoul(val, 0, &num);
+	ret = kstrtoul(val, 0, &num);
 	if (ret = -EINVAL || num < min || num > max)
 		return -EINVAL;
 	*((unsigned int *)kp->arg) = num;
#8 lore raw

PATCH 3/5 net/mac80211/debugfs.c: use kstrtoul, etc

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Use kstrtoul, etc instead of the now deprecated strict_strtoul, etc.

A semantic patch rule for the kstrtoul case is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,b;
{int,long} *c;
@@

-strict_strtoul
+kstrtoul
(a,b,c)
// </smpl>

---
 net/mac80211/debugfs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/debugfs.c +1 -1
diff -u -p a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
@@ -190,7 +190,7 @@ static ssize_t uapsd_max_sp_len_write(st
 		return -EFAULT;
 	buf[len] = '\0';
 
-	ret = strict_strtoul(buf, 0, &val);
+	ret = kstrtoul(buf, 0, &val);
 
 	if (ret)
 		return -EINVAL;
#11 lore raw

PATCH 4/5 net/rfkill/core.c: use kstrtoul, etc

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Use kstrtoul, etc instead of the now deprecated strict_strtoul, etc.

A semantic patch rule for the kstrtoul case is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,b;
{int,long} *c;
@@

-strict_strtoul
+kstrtoul
(a,b,c)
// </smpl>

---
 net/rfkill/core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/rfkill/core.c +2 -2
diff -u -p a/net/rfkill/core.c b/net/rfkill/core.c
@@ -644,7 +644,7 @@ static ssize_t rfkill_soft_store(struct
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
 
-	err = strict_strtoul(buf, 0, &state);
+	err = kstrtoul(buf, 0, &state);
 	if (err)
 		return err;
 
@@ -688,7 +688,7 @@ static ssize_t rfkill_state_store(struct
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
 
-	err = strict_strtoul(buf, 0, &state);
+	err = kstrtoul(buf, 0, &state);
 	if (err)
 		return err;
 
#12 lore raw

PATCH 5/5 net/dns_resolver/dns_key.c: use kstrtoul, etc

In reply to Julia Lawall

From: Julia Lawall <[email protected]>

Use kstrtoul, etc instead of the now deprecated strict_strtoul, etc.

A semantic patch rule for the kstrtoul case is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,b;
{int,long} *c;
@@

-strict_strtoul
+kstrtoul
(a,b,c)
// </smpl>

---
 net/dns_resolver/dns_key.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/dns_resolver/dns_key.c +1 -1
diff -u -p a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
@@ -118,7 +118,7 @@ dns_resolver_instantiate(struct key *key
 				if (opt_vlen <= 0)
 					goto bad_option_value;
 
-				ret = strict_strtoul(eq, 10, &derrno);
+				ret = kstrtoul(eq, 10, &derrno);
 				if (ret < 0)
 					goto bad_option_value;
 
#2 lore raw

Re: [B.A.T.M.A.N.] [PATCH 1/5] net/batman-adv: use kstrtoul, etc

In reply to Julia Lawall
Quoted 3 lines · On Sunday, November 06, 2011 21:26:46 Julia Lawall wrote:

From: Julia Lawall <[email protected]>

Use kstrtoul, etc instead of the now deprecated strict_strtoul, etc.

Thanks for the patch but we already have a patch lined up to address the issue. It will be submitted to net-next in the next week or so.

Regards,
Marek

#9 lore raw

Re: [PATCH 3/5] net/mac80211/debugfs.c: use kstrtoul, etc

In reply to Julia Lawall
Quoted 29 lines · Julia Lawall

From: Julia Lawall <[email protected]>

Use kstrtoul, etc instead of the now deprecated strict_strtoul, etc.

A semantic patch rule for the kstrtoul case is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,b;
{int,long} *c;
@@

(quoted diff) +1 -1
-strict_strtoul
+kstrtoul

 (a,b,c)
// </smpl>

---
 net/mac80211/debugfs.c |    2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c

net/mac80211/debugfs.c static ssize_t uapsd_max_sp_len_write(st · line 196

Quoted 8 lines
net/mac80211/debugfs.c +1 -1
@@ -190,7 +190,7 @@ static ssize_t uapsd_max_sp_len_write(st
                return -EFAULT;
        buf[len] = '\0';
 
-       ret = strict_strtoul(buf, 0, &val);
+       ret = kstrtoul(buf, 0, &val);
 
        if (ret)
                return -EINVAL;

maybe while cleaning it up change copy_from_user + strict_stroul/kstroul -> kstroul_from_user?

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

#10 lore raw

Re: [PATCH 3/5] net/mac80211/debugfs.c: use kstrtoul, etc

Quoted 35 lines · Eliad Peller
Quoted 34 lines · Julia Lawall

From: Julia Lawall <[email protected]>

Use kstrtoul, etc instead of the now deprecated strict_strtoul, etc.

A semantic patch rule for the kstrtoul case is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression a,b;
{int,long} *c;
@@

(quoted diff) +1 -1
-strict_strtoul
+kstrtoul

 (a,b,c)
// </smpl>

---
 net/mac80211/debugfs.c |    2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c

net/mac80211/debugfs.c +1 -1
@@ -190,7 +190,7 @@ static ssize_t uapsd_max_sp_len_write(st
                return -EFAULT;
        buf[len] = '\0';
 
-       ret = strict_strtoul(buf, 0, &val);
+       ret = kstrtoul(buf, 0, &val);
 
Quoted 6 lines

net/mac80211/debugfs.c static ssize_t uapsd_max_sp_len_write(st · line 196

Quoted 3 lines
net/mac80211/debugfs.c +0 -0
        if (ret)
                return -EINVAL;

maybe while cleaning it up change copy_from_user + strict_stroul/kstroul -> kstroul_from_user?

Thanks for the suggestion. I will look into it.

julia

#4 lore raw

Re: [PATCH 2/5] net/sunrpc: use kstrtoul, etc

In reply to Julia Lawall

Review

Quoted 7 lines · Julia Lawall

@@
expression a,b;
{int,long} *c;
@@

(quoted diff) +1 -1
-strict_strtoul
+kstrtoul

No, no, no!

In every case see the type or real data and use appropriate function. kstrtou8() for ports.
This program creates lots of bogus patches in this case.

Quoted 20 lines
net/sunrpc/addr.c +2 -2
@@ -322,7 +322,7 @@ size_t rpc_uaddr2sockaddr(const char *ua
 	c = strrchr(buf, '.');
 	if (unlikely(c = NULL))
 		return 0;
-	if (unlikely(strict_strtoul(c + 1, 10, &portlo) != 0))
+	if (unlikely(kstrtoul(c + 1, 10, &portlo) != 0))
 		return 0;
 	if (unlikely(portlo > 255))
 		return 0;
@@ -331,7 +331,7 @@ size_t rpc_uaddr2sockaddr(const char *ua
 	c = strrchr(buf, '.');
 	if (unlikely(c = NULL))
 		return 0;
-	if (unlikely(strict_strtoul(c + 1, 10, &porthi) != 0))
+	if (unlikely(kstrtoul(c + 1, 10, &porthi) != 0))
 		return 0;
 	if (unlikely(porthi > 255))
 		return 0;
#5 lore raw

Re: [PATCH 2/5] net/sunrpc: use kstrtoul, etc

Quoted 10 lines · Alexey Dobriyan

Review

Quoted 7 lines · Julia Lawall

@@
expression a,b;
{int,long} *c;
@@

(quoted diff) +1 -1
-strict_strtoul
+kstrtoul

No, no, no!

Sorry, this was not the real rule I used for the strtoul case. Instead I used the following:

@@
typedef ulong;
expression a,b;
{ulong,unsigned long,unsigned int,size_t} *c;
@@

-strict_strtoul
+kstrtoul
(a,b,c)

But now I have seen that there is a separate function for integers, so I have made a rule to use that function when the type is unsigned int.

Quoted 2 lines

In every case see the type or real data and use appropriate function. kstrtou8() for ports.

The type of the destination variable in all of these cases is unsigned long. But maybe that is not enough information to make the transformation in the right way.

julia

Quoted 27 lines

This program creates lots of bogus patches in this case.

Quoted 12 lines
net/sunrpc/addr.c +1 -1
@@ -322,7 +322,7 @@ size_t rpc_uaddr2sockaddr(const char *ua
 	c = strrchr(buf, '.');
 	if (unlikely(c = NULL))
 		return 0;
-	if (unlikely(strict_strtoul(c + 1, 10, &portlo) != 0))
+	if (unlikely(kstrtoul(c + 1, 10, &portlo) != 0))
 		return 0;
 	if (unlikely(portlo > 255))
 		return 0;

net/sunrpc/addr.c size_t rpc_uaddr2sockaddr(const char *ua · line 337

Quoted 8 lines
net/sunrpc/addr.c +1 -1
@@ -331,7 +331,7 @@ size_t rpc_uaddr2sockaddr(const char *ua
 	c = strrchr(buf, '.');
 	if (unlikely(c = NULL))
 		return 0;
-	if (unlikely(strict_strtoul(c + 1, 10, &porthi) != 0))
+	if (unlikely(kstrtoul(c + 1, 10, &porthi) != 0))
 		return 0;
 	if (unlikely(porthi > 255))
 		return 0;

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

#6 lore raw

Re: [PATCH 2/5] net/sunrpc: use kstrtoul, etc

Quoted 31 lines · Julia Lawall
Quoted 10 lines · Alexey Dobriyan

Review

Quoted 7 lines · Julia Lawall

@@
expression a,b;
{int,long} *c;
@@

(quoted diff) +1 -1
-strict_strtoul
+kstrtoul

No, no, no!

Sorry, this was not the real rule I used for the strtoul case. Instead I used the following:

@@
typedef ulong;
expression a,b;
{ulong,unsigned long,unsigned int,size_t} *c;
@@

(quoted diff) +1 -1
-strict_strtoul
+kstrtoul
  (a,b,c)

But now I have seen that there is a separate function for integers, so I have made a rule to use that function when the type is unsigned int.

Quoted 6 lines
Quoted 2 lines

In every case see the type or real data and use appropriate function. kstrtou8() for ports.

The type of the destination variable in all of these cases is unsigned long. But maybe that is not enough information to make the transformation in the right way.

That's because previous functions following libc didn't accept anything less than unsigned long.

For these conversion, one should literally look at every usecase and see what types data have for real (not unsigned long) and make conversion and remove explicit EINVAL checks if necesasry.

In sunrpc case: switch to kstrtou8 + remove "> 255" check.

This program doesn't and won't do that.

#7 lore raw

Re: [PATCH 2/5] net/sunrpc: use kstrtoul, etc

In reply to Julia Lawall

In looking through some examples, I see, e.g.:

if (strict_strtoul(buf, 10, &val) < 0)
return -EINVAL;
if (val < 1 || val > 2)
return -EINVAL;

In this case the only valid values are 1 and 2, which are much smaller than the u8 range. Is it useful to use kstrtou8 anyway? I see that kstrtou8 returns -ERANGE not -EINVAL when the value is out of bounds. If kstrtou8 is to be used, should the subsequent if (val < 1 || val > 2) now return -ERANGE to be consistent?

julia