Re: [PATCH v2] staging: speakup: remove simple_strtoul()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Greg,

Em 27-05-2018 09:46, Greg KH escreveu:
On Sat, May 26, 2018 at 04:03:35PM -0300, Gabriel Fedel wrote:
Replace simple_strtoul() with kstrtoul(), because simple_strtoul() is
obsolete.

kstrtoul and simple_strtoul are not equal, so some new code was
inserted:

It was necessary to pass to kstrtoul just number part (new variable num).

temp variable was setted manually (to position after cp number part).

Signed-off-by: Gabriel Fedel <fedel@xxxxxxxxxxxx>
---
Changes since first patch:

Fix C error
Change the way to use kstrtoul (on first patch just substitue simple_strtoul by
kstrtoul)

---
 drivers/staging/speakup/kobjects.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index f1f9022..50dc456 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -117,6 +117,7 @@ static ssize_t chars_chartab_store(struct kobject *kobj,
 	char *outptr = NULL;	/* Will hold keyword or desc. */
 	char *temp = NULL;
 	char *desc = NULL;
+	char *num = NULL; /* The number part of cp */
 	ssize_t retval = count;
 	unsigned long flags;
 	unsigned long index = 0;
@@ -154,7 +155,17 @@ static ssize_t chars_chartab_store(struct kobject *kobj,
 			continue;
 		}

-		index = simple_strtoul(cp, &temp, 10);
+		i = 0;
+		while (isdigit(*(cp + i)))
+			i = i + 1;
+		temp = cp + i;
+
+		num = kmalloc(i + 2, GFP_ATOMIC);
+		strscpy(num, cp, i + 1);
+
+		if (kstrtoul(num, 10, &index) != 0)
+			pr_warn("overflow or parsing error has occurred");

If you have to go through the string twice, that's a huge sign that
something is wrong.  This "conversion" is not correct at all :(
Thank you for review.
I can't see the problem with this code, Could you point me the error?


greg k-h

Gabiel
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux