netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] use kstrtoul, etc
@ 2011-11-06 13:26 Julia Lawall
  2011-11-06 13:26 ` [PATCH 1/5] net/batman-adv: " Julia Lawall
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Julia Lawall @ 2011-11-06 13:26 UTC (permalink / raw)
  To: David S. Miller; +Cc: kernel-janitors, netdev, linux-kernel

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>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/5] net/batman-adv: use kstrtoul, etc
  2011-11-06 13:26 [PATCH 0/5] use kstrtoul, etc Julia Lawall
@ 2011-11-06 13:26 ` Julia Lawall
       [not found]   ` <1320586010-21931-2-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
  2011-11-06 13:26 ` [PATCH 2/5] net/sunrpc: " Julia Lawall
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Julia Lawall @ 2011-11-06 13:26 UTC (permalink / raw)
  To: Marek Lindner
  Cc: kernel-janitors, Simon Wunderlich, David S. Miller, b.a.t.m.a.n,
	netdev, linux-kernel

From: Julia Lawall <julia@diku.dk>

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>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 net/batman-adv/bat_sysfs.c      |    4 ++--
 net/batman-adv/gateway_common.c |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff -u -p a/net/batman-adv/bat_sysfs.c b/net/batman-adv/bat_sysfs.c
--- 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) ||
diff -u -p a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
--- 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: "

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/5] net/sunrpc: use kstrtoul, etc
  2011-11-06 13:26 [PATCH 0/5] use kstrtoul, etc Julia Lawall
  2011-11-06 13:26 ` [PATCH 1/5] net/batman-adv: " Julia Lawall
@ 2011-11-06 13:26 ` Julia Lawall
       [not found]   ` <1320586010-21931-3-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
  2011-11-06 13:26 ` [PATCH 3/5] net/mac80211/debugfs.c: " Julia Lawall
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Julia Lawall @ 2011-11-06 13:26 UTC (permalink / raw)
  To: J. Bruce Fields
  Cc: kernel-janitors, Neil Brown, Trond Myklebust, David S. Miller,
	linux-nfs, netdev, linux-kernel

From: Julia Lawall <julia@diku.dk>

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>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 net/sunrpc/addr.c     |    6 +++---
 net/sunrpc/auth.c     |    2 +-
 net/sunrpc/xprtsock.c |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff -u -p a/net/sunrpc/addr.c b/net/sunrpc/addr.c
--- 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;
diff -u -p a/net/sunrpc/auth.c b/net/sunrpc/auth.c
--- 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);
diff -u -p a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
--- 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;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 3/5] net/mac80211/debugfs.c: use kstrtoul, etc
  2011-11-06 13:26 [PATCH 0/5] use kstrtoul, etc Julia Lawall
  2011-11-06 13:26 ` [PATCH 1/5] net/batman-adv: " Julia Lawall
  2011-11-06 13:26 ` [PATCH 2/5] net/sunrpc: " Julia Lawall
@ 2011-11-06 13:26 ` Julia Lawall
  2011-11-07 11:47   ` Eliad Peller
  2011-11-06 13:26 ` [PATCH 4/5] net/rfkill/core.c: " Julia Lawall
  2011-11-06 13:26 ` [PATCH 5/5] net/dns_resolver/dns_key.c: " Julia Lawall
  4 siblings, 1 reply; 13+ messages in thread
From: Julia Lawall @ 2011-11-06 13:26 UTC (permalink / raw)
  To: John W. Linville
  Cc: kernel-janitors, Johannes Berg, David S. Miller, linux-wireless,
	netdev, linux-kernel

From: Julia Lawall <julia@diku.dk>

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>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 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
--- 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;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 4/5] net/rfkill/core.c: use kstrtoul, etc
  2011-11-06 13:26 [PATCH 0/5] use kstrtoul, etc Julia Lawall
                   ` (2 preceding siblings ...)
  2011-11-06 13:26 ` [PATCH 3/5] net/mac80211/debugfs.c: " Julia Lawall
@ 2011-11-06 13:26 ` Julia Lawall
  2011-11-06 13:26 ` [PATCH 5/5] net/dns_resolver/dns_key.c: " Julia Lawall
  4 siblings, 0 replies; 13+ messages in thread
From: Julia Lawall @ 2011-11-06 13:26 UTC (permalink / raw)
  To: Johannes Berg
  Cc: kernel-janitors, John W. Linville, David S. Miller,
	linux-wireless, netdev, linux-kernel

From: Julia Lawall <julia@diku.dk>

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>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 net/rfkill/core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -u -p a/net/rfkill/core.c b/net/rfkill/core.c
--- 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;
 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 5/5] net/dns_resolver/dns_key.c: use kstrtoul, etc
  2011-11-06 13:26 [PATCH 0/5] use kstrtoul, etc Julia Lawall
                   ` (3 preceding siblings ...)
  2011-11-06 13:26 ` [PATCH 4/5] net/rfkill/core.c: " Julia Lawall
@ 2011-11-06 13:26 ` Julia Lawall
  4 siblings, 0 replies; 13+ messages in thread
From: Julia Lawall @ 2011-11-06 13:26 UTC (permalink / raw)
  To: David S. Miller; +Cc: kernel-janitors, netdev, linux-kernel

From: Julia Lawall <julia@diku.dk>

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>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 net/dns_resolver/dns_key.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
--- 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;
 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/5] net/batman-adv: use kstrtoul, etc
       [not found]   ` <1320586010-21931-2-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
@ 2011-11-06 14:16     ` Marek Lindner
  0 siblings, 0 replies; 13+ messages in thread
From: Marek Lindner @ 2011-11-06 14:16 UTC (permalink / raw)
  To: b.a.t.m.a.n-ZwoEplunGu2X36UT3dwllkB+6BGkLq7r
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Simon Wunderlich,
	Julia Lawall, David S. Miller

On Sunday, November 06, 2011 21:26:46 Julia Lawall wrote:
> From: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>
> 
> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/5] net/mac80211/debugfs.c: use kstrtoul, etc
  2011-11-06 13:26 ` [PATCH 3/5] net/mac80211/debugfs.c: " Julia Lawall
@ 2011-11-07 11:47   ` Eliad Peller
  2011-11-07 11:58     ` Julia Lawall
  0 siblings, 1 reply; 13+ messages in thread
From: Eliad Peller @ 2011-11-07 11:47 UTC (permalink / raw)
  To: Julia Lawall
  Cc: John W. Linville, kernel-janitors, Johannes Berg,
	David S. Miller, linux-wireless, netdev, linux-kernel

On Sun, Nov 6, 2011 at 3:26 PM, Julia Lawall <julia@diku.dk> wrote:
> From: Julia Lawall <julia@diku.dk>
>
> 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>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
>
> ---
>  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
> --- 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;
>

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

Eliad.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/5] net/mac80211/debugfs.c: use kstrtoul, etc
  2011-11-07 11:47   ` Eliad Peller
@ 2011-11-07 11:58     ` Julia Lawall
  0 siblings, 0 replies; 13+ messages in thread
From: Julia Lawall @ 2011-11-07 11:58 UTC (permalink / raw)
  To: Eliad Peller
  Cc: Julia Lawall, John W. Linville, kernel-janitors, Johannes Berg,
	David S. Miller, linux-wireless, netdev, linux-kernel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1159 bytes --]



On Mon, 7 Nov 2011, Eliad Peller wrote:

> On Sun, Nov 6, 2011 at 3:26 PM, Julia Lawall <julia@diku.dk> wrote:
>> From: Julia Lawall <julia@diku.dk>
>>
>> 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>
>>
>> Signed-off-by: Julia Lawall <julia@diku.dk>
>>
>> ---
>>  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
>> --- 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;
>>
>
> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/5] net/sunrpc: use kstrtoul, etc
       [not found]   ` <1320586010-21931-3-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
@ 2011-11-08 19:38     ` Alexey Dobriyan
  2011-11-08 20:19       ` Julia Lawall
  0 siblings, 1 reply; 13+ messages in thread
From: Alexey Dobriyan @ 2011-11-08 19:38 UTC (permalink / raw)
  To: Julia Lawall
  Cc: J. Bruce Fields, kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	Neil Brown, Trond Myklebust, David S. Miller,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Sun, Nov 06, 2011 at 02:26:47PM +0100, Julia Lawall wrote:
> @@
> expression a,b;
> {int,long} *c;
> @@
> 
> -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.

> --- a/net/sunrpc/addr.c
> +++ b/net/sunrpc/addr.c
> @@ -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;
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/5] net/sunrpc: use kstrtoul, etc
  2011-11-08 19:38     ` Alexey Dobriyan
@ 2011-11-08 20:19       ` Julia Lawall
  2011-11-08 20:45         ` Alexey Dobriyan
  2011-11-09  6:15         ` Julia Lawall
  0 siblings, 2 replies; 13+ messages in thread
From: Julia Lawall @ 2011-11-08 20:19 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Julia Lawall, J. Bruce Fields, kernel-janitors, Neil Brown,
	Trond Myklebust, David S. Miller, linux-nfs, netdev,
	linux-kernel



On Tue, 8 Nov 2011, Alexey Dobriyan wrote:

> On Sun, Nov 06, 2011 at 02:26:47PM +0100, Julia Lawall wrote:
>> @@
>> expression a,b;
>> {int,long} *c;
>> @@
>>
>> -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.

> 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

> This program creates lots of bogus patches in this case.
>
>> --- a/net/sunrpc/addr.c
>> +++ b/net/sunrpc/addr.c
>> @@ -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;
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/5] net/sunrpc: use kstrtoul, etc
  2011-11-08 20:19       ` Julia Lawall
@ 2011-11-08 20:45         ` Alexey Dobriyan
  2011-11-09  6:15         ` Julia Lawall
  1 sibling, 0 replies; 13+ messages in thread
From: Alexey Dobriyan @ 2011-11-08 20:45 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Julia Lawall, J. Bruce Fields,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA, Neil Brown,
	Trond Myklebust, David S. Miller,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Tue, Nov 08, 2011 at 09:19:30PM +0100, Julia Lawall wrote:
> 
> 
> On Tue, 8 Nov 2011, Alexey Dobriyan wrote:
> 
> > On Sun, Nov 06, 2011 at 02:26:47PM +0100, Julia Lawall wrote:
> >> @@
> >> expression a,b;
> >> {int,long} *c;
> >> @@
> >>
> >> -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.
> 
> > 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/5] net/sunrpc: use kstrtoul, etc
  2011-11-08 20:19       ` Julia Lawall
  2011-11-08 20:45         ` Alexey Dobriyan
@ 2011-11-09  6:15         ` Julia Lawall
  1 sibling, 0 replies; 13+ messages in thread
From: Julia Lawall @ 2011-11-09  6:15 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: J. Bruce Fields, kernel-janitors, Neil Brown, Trond Myklebust,
	David S. Miller, linux-nfs, netdev, linux-kernel

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-11-09  6:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-06 13:26 [PATCH 0/5] use kstrtoul, etc Julia Lawall
2011-11-06 13:26 ` [PATCH 1/5] net/batman-adv: " Julia Lawall
     [not found]   ` <1320586010-21931-2-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
2011-11-06 14:16     ` Marek Lindner
2011-11-06 13:26 ` [PATCH 2/5] net/sunrpc: " Julia Lawall
     [not found]   ` <1320586010-21931-3-git-send-email-julia-dAYI7NvHqcQ@public.gmane.org>
2011-11-08 19:38     ` Alexey Dobriyan
2011-11-08 20:19       ` Julia Lawall
2011-11-08 20:45         ` Alexey Dobriyan
2011-11-09  6:15         ` Julia Lawall
2011-11-06 13:26 ` [PATCH 3/5] net/mac80211/debugfs.c: " Julia Lawall
2011-11-07 11:47   ` Eliad Peller
2011-11-07 11:58     ` Julia Lawall
2011-11-06 13:26 ` [PATCH 4/5] net/rfkill/core.c: " Julia Lawall
2011-11-06 13:26 ` [PATCH 5/5] net/dns_resolver/dns_key.c: " Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).