public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v3] UBIFS: replace simple_strtoul() with kstrtoint()
       [not found] <1400641191-27877-1-git-send-email-zhenzhang.zhang@huawei.com>
@ 2014-05-21  3:00 ` Zhang Zhen
  2014-05-21  6:30   ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang Zhen @ 2014-05-21  3:00 UTC (permalink / raw)
  To: Adrian Hunter, Geert Uytterhoeven, Artem Bityutskiy
  Cc: MTD Maling List, Hu Jianyang

use the newer and more pleasant kstrtoint() to replace simple_strtoul(),
because simple_strtoul() is marked for obsoletion.

Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
Signed-off-by: hujianyang <hujianyang@huawei.com>
---
 drivers/mtd/ubi/build.c |  9 +++++----
 fs/ubifs/super.c        | 14 ++++++++++----
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 6e30a3c..489f5ef 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1190,11 +1190,12 @@ static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
 static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
 {
 	struct mtd_info *mtd;
-	int mtd_num;
-	char *endp;
+	int mtd_num, ret;

-	mtd_num = simple_strtoul(mtd_dev, &endp, 0);
-	if (*endp != '\0' || mtd_dev == endp) {
+	ret = kstrtoint(mtd_dev, 0, &mtd_num);
+	if (ret)
+		return ERR_PTR(-EINVAL);
+	if (*mtd_dev != '\0') {
 		/*
 		 * This does not look like an ASCII integer, probably this is
 		 * MTD device name.
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index a81c7b5..4831b60 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -1903,8 +1903,8 @@ const struct super_operations ubifs_super_operations = {
 static struct ubi_volume_desc *open_ubi(const char *name, int mode)
 {
 	struct ubi_volume_desc *ubi;
-	int dev, vol;
-	char *endptr;
+	int dev, vol, ret;
+	const char *endptr;

 	/* First, try to open using the device node path method */
 	ubi = ubi_open_volume_path(name, mode);
@@ -1922,7 +1922,10 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
 	if (!isdigit(name[3]))
 		return ERR_PTR(-EINVAL);

-	dev = simple_strtoul(name + 3, &endptr, 0);
+	endptr = name + 3;
+	ret = kstrtoint(endptr, 0, &dev);
+	if (ret)
+		return ERR_PTR(-EINVAL);

 	/* ubiY method */
 	if (*endptr == '\0')
@@ -1930,7 +1933,10 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)

 	/* ubiX_Y method */
 	if (*endptr == '_' && isdigit(endptr[1])) {
-		vol = simple_strtoul(endptr + 1, &endptr, 0);
+		endptr = endptr + 1;
+		ret = kstrtoint(endptr, 0, &vol);
+		if (ret)
+			return ERR_PTR(-EINVAL);
 		if (*endptr != '\0')
 			return ERR_PTR(-EINVAL);
 		return ubi_open_volume(dev, vol, mode);
-- 
1.8.1.2


.

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

* Re: [PATCH v3] UBIFS: replace simple_strtoul() with kstrtoint()
  2014-05-21  3:00 ` [PATCH v3] UBIFS: replace simple_strtoul() with kstrtoint() Zhang Zhen
@ 2014-05-21  6:30   ` Geert Uytterhoeven
  2014-05-21  9:00     ` Zhang Zhen
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2014-05-21  6:30 UTC (permalink / raw)
  To: Zhang Zhen; +Cc: Hu Jianyang, MTD Maling List, Adrian Hunter, Artem Bityutskiy

On Wed, May 21, 2014 at 5:00 AM, Zhang Zhen <zhenzhang.zhang@huawei.com> wrote:
> @@ -1922,7 +1922,10 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>         if (!isdigit(name[3]))
>                 return ERR_PTR(-EINVAL);
>
> -       dev = simple_strtoul(name + 3, &endptr, 0);
> +       endptr = name + 3;

As Adrian pointed out, endptr is used later, and it must point to the
character after the parsed number.

> +       ret = kstrtoint(endptr, 0, &dev);
> +       if (ret)
> +               return ERR_PTR(-EINVAL);
>
>         /* ubiY method */
>         if (*endptr == '\0')
> @@ -1930,7 +1933,10 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>
>         /* ubiX_Y method */
>         if (*endptr == '_' && isdigit(endptr[1])) {
> -               vol = simple_strtoul(endptr + 1, &endptr, 0);
> +               endptr = endptr + 1;
> +               ret = kstrtoint(endptr, 0, &vol);
> +               if (ret)
> +                       return ERR_PTR(-EINVAL);

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3] UBIFS: replace simple_strtoul() with kstrtoint()
  2014-05-21  6:30   ` Geert Uytterhoeven
@ 2014-05-21  9:00     ` Zhang Zhen
  0 siblings, 0 replies; 3+ messages in thread
From: Zhang Zhen @ 2014-05-21  9:00 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Hu Jianyang, MTD Maling List, Adrian Hunter, Artem Bityutskiy

On 2014/5/21 14:30, Geert Uytterhoeven wrote:
> On Wed, May 21, 2014 at 5:00 AM, Zhang Zhen <zhenzhang.zhang@huawei.com> wrote:
>> @@ -1922,7 +1922,10 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>>         if (!isdigit(name[3]))
>>                 return ERR_PTR(-EINVAL);
>>
>> -       dev = simple_strtoul(name + 3, &endptr, 0);
>> +       endptr = name + 3;
> 
> As Adrian pointed out, endptr is used later, and it must point to the
> character after the parsed number.
> 
Okay, it appears kstrtoint is not suitable to replace the simple_strtoul here.
The first argument of kstrto* can not point to the character after the parsed number.
>> +       ret = kstrtoint(endptr, 0, &dev);
>> +       if (ret)
>> +               return ERR_PTR(-EINVAL);
>>
>>         /* ubiY method */
>>         if (*endptr == '\0')
>> @@ -1930,7 +1933,10 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>>
>>         /* ubiX_Y method */
>>         if (*endptr == '_' && isdigit(endptr[1])) {
>> -               vol = simple_strtoul(endptr + 1, &endptr, 0);
>> +               endptr = endptr + 1;
>> +               ret = kstrtoint(endptr, 0, &vol);
>> +               if (ret)
>> +                       return ERR_PTR(-EINVAL);
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
> 
> 

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

end of thread, other threads:[~2014-05-21  9:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1400641191-27877-1-git-send-email-zhenzhang.zhang@huawei.com>
2014-05-21  3:00 ` [PATCH v3] UBIFS: replace simple_strtoul() with kstrtoint() Zhang Zhen
2014-05-21  6:30   ` Geert Uytterhoeven
2014-05-21  9:00     ` Zhang Zhen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox