public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint()
@ 2015-06-23 20:47 Luis de Bethencourt
  2015-06-23 22:53 ` Dan Carpenter
  0 siblings, 1 reply; 7+ messages in thread
From: Luis de Bethencourt @ 2015-06-23 20:47 UTC (permalink / raw)
  To: linux-kernel
  Cc: William Hubbs, Chris Brannon, Kirk Reiser, Samuel Thibault,
	Greg Kroah-Hartman, Domagoj Trsan, Melike Yurtoglu, speakup,
	devel

Use the newer and nicer kstrtoint(), because simple_strtoul() is now obsolete.

Signed-off-by: Luis de Bethencourt <luis@debethencourt.com>
---
 drivers/staging/speakup/varhandlers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/speakup/varhandlers.c b/drivers/staging/speakup/varhandlers.c
index 1b0d1c0..131da42 100644
--- a/drivers/staging/speakup/varhandlers.c
+++ b/drivers/staging/speakup/varhandlers.c
@@ -324,7 +324,7 @@ char *spk_s2uchar(char *start, char *dest)
 {
 	int val = 0;
 
-	val = simple_strtoul(skip_spaces(start), &start, 10);
+	kstrtoint(skip_spaces(start), 10, &val);
 	if (*start == ',')
 		start++;
 	*dest = (u_char)val;
-- 
2.1.0


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

* Re: [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint()
  2015-06-23 20:47 [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint() Luis de Bethencourt
@ 2015-06-23 22:53 ` Dan Carpenter
  2015-06-23 23:15   ` Luis de Bethencourt
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2015-06-23 22:53 UTC (permalink / raw)
  To: Luis de Bethencourt
  Cc: linux-kernel, devel, Kirk Reiser, Greg Kroah-Hartman, speakup,
	Melike Yurtoglu, Domagoj Trsan, Samuel Thibault, Chris Brannon

Nope.  Your patch is totally wrong (buggy).  Please be more careful in
the future.

regards,
dan carpenter


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

* Re: [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint()
  2015-06-23 22:53 ` Dan Carpenter
@ 2015-06-23 23:15   ` Luis de Bethencourt
  2015-06-24  5:23     ` Sudip Mukherjee
  0 siblings, 1 reply; 7+ messages in thread
From: Luis de Bethencourt @ 2015-06-23 23:15 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: linux-kernel, devel, Kirk Reiser, Greg Kroah-Hartman, speakup,
	Melike Yurtoglu, Domagoj Trsan, Samuel Thibault, Chris Brannon

On Wed, Jun 24, 2015 at 01:53:33AM +0300, Dan Carpenter wrote:
> Nope.  Your patch is totally wrong (buggy).  Please be more careful in
> the future.
> 
> regards,
> dan carpenter
> 

I saw other commits replace the obsolete simple_strtoul() this way and the
documentation makes it look like it is a 1 to 1 replacement.

Sorry about this. I will investigate further to understand why this is buggy
and be more careful in the future.

Thanks for the review,
Luis

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

* Re: [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint()
  2015-06-23 23:15   ` Luis de Bethencourt
@ 2015-06-24  5:23     ` Sudip Mukherjee
  2015-06-24 10:19       ` Luis de Bethencourt
  0 siblings, 1 reply; 7+ messages in thread
From: Sudip Mukherjee @ 2015-06-24  5:23 UTC (permalink / raw)
  To: Luis de Bethencourt
  Cc: Dan Carpenter, devel, Kirk Reiser, Greg Kroah-Hartman, speakup,
	Melike Yurtoglu, linux-kernel, Domagoj Trsan, Samuel Thibault,
	Chris Brannon

On Wed, Jun 24, 2015 at 12:15:52AM +0100, Luis de Bethencourt wrote:
> On Wed, Jun 24, 2015 at 01:53:33AM +0300, Dan Carpenter wrote:
> > Nope.  Your patch is totally wrong (buggy).  Please be more careful in
> > the future.
> > 
> > regards,
> > dan carpenter
> > 
> 
> I saw other commits replace the obsolete simple_strtoul() this way and the
> documentation makes it look like it is a 1 to 1 replacement.
> 
> Sorry about this. I will investigate further to understand why this is buggy
> and be more careful in the future.
simple_strtoul returns unsigned long and kstrtoint gives int.
documentation says to use kstrtoul.

regards
sudip

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

* Re: [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint()
  2015-06-24  5:23     ` Sudip Mukherjee
@ 2015-06-24 10:19       ` Luis de Bethencourt
  2015-06-24 17:46         ` Luis de Bethencourt
  0 siblings, 1 reply; 7+ messages in thread
From: Luis de Bethencourt @ 2015-06-24 10:19 UTC (permalink / raw)
  To: Sudip Mukherjee
  Cc: Dan Carpenter, devel, Kirk Reiser, Greg Kroah-Hartman, speakup,
	Melike Yurtoglu, linux-kernel, Domagoj Trsan, Samuel Thibault,
	Chris Brannon

On Wed, Jun 24, 2015 at 10:53:30AM +0530, Sudip Mukherjee wrote:
> On Wed, Jun 24, 2015 at 12:15:52AM +0100, Luis de Bethencourt wrote:
> > On Wed, Jun 24, 2015 at 01:53:33AM +0300, Dan Carpenter wrote:
> > > Nope.  Your patch is totally wrong (buggy).  Please be more careful in
> > > the future.
> > > 
> > > regards,
> > > dan carpenter
> > > 
> > 
> > I saw other commits replace the obsolete simple_strtoul() this way and the
> > documentation makes it look like it is a 1 to 1 replacement.
> > 
> > Sorry about this. I will investigate further to understand why this is buggy
> > and be more careful in the future.
> simple_strtoul returns unsigned long and kstrtoint gives int.
> documentation says to use kstrtoul.
> 
> regards
> sudip

Hello again Sudip :)

simple_strtoul returns an unsigned long, but in this case this is downcasted to
int val. If we use kstrtoul there would be a type warning since the function
expects the reference to an unsigned long. Which is why I used the related
kstrtoint.

Dan has said this is buggy. I have an idea why this might be. I am isolating
the code and playing with it before submitting a second version.

Thanks for the review.

Luis

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

* Re: [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint()
  2015-06-24 10:19       ` Luis de Bethencourt
@ 2015-06-24 17:46         ` Luis de Bethencourt
  2015-06-25  8:19           ` Dan Carpenter
  0 siblings, 1 reply; 7+ messages in thread
From: Luis de Bethencourt @ 2015-06-24 17:46 UTC (permalink / raw)
  To: Sudip Mukherjee
  Cc: Dan Carpenter, devel, Kirk Reiser, Greg Kroah-Hartman, speakup,
	Melike Yurtoglu, linux-kernel, Domagoj Trsan, Samuel Thibault,
	Chris Brannon

On Wed, Jun 24, 2015 at 12:19:27PM +0200, Luis de Bethencourt wrote:
> On Wed, Jun 24, 2015 at 10:53:30AM +0530, Sudip Mukherjee wrote:
> > On Wed, Jun 24, 2015 at 12:15:52AM +0100, Luis de Bethencourt wrote:
> > > On Wed, Jun 24, 2015 at 01:53:33AM +0300, Dan Carpenter wrote:
> > > > Nope.  Your patch is totally wrong (buggy).  Please be more careful in
> > > > the future.
> > > > 
> > > > regards,
> > > > dan carpenter
> > > > 
> > > 
> > > I saw other commits replace the obsolete simple_strtoul() this way and the
> > > documentation makes it look like it is a 1 to 1 replacement.
> > > 
> > > Sorry about this. I will investigate further to understand why this is buggy
> > > and be more careful in the future.
> > simple_strtoul returns unsigned long and kstrtoint gives int.
> > documentation says to use kstrtoul.
> > 
> > regards
> > sudip
> 
> Hello again Sudip :)
> 
> simple_strtoul returns an unsigned long, but in this case this is downcasted to
> int val. If we use kstrtoul there would be a type warning since the function
> expects the reference to an unsigned long. Which is why I used the related
> kstrtoint.
> 
> Dan has said this is buggy. I have an idea why this might be. I am isolating
> the code and playing with it before submitting a second version.
> 
> Thanks for the review.
> 
> Luis

Hi,

I've investigated the issue and found the two differences between
simple_stroull() and kstrtoull().

The prototypes for reference:
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);
int kstrtoul(const char *s, unsigned int base, unsigned long *res);

The first issue is that simple_strtoull() moves the endp pointer to right after
the character where the last digit used is. [0] kstrtoull() doesn't move any
pointers or tell us how many characters of the string it read.

Speakup uses this to convert a string including 3 numbers into 3 ascii codes.
For example "97 98 99", to get 'a', 'b', and 'c'. It loops 3 times using this
function moving the start (cp) to the endp of the previous iteration. [1]

The second issue is that kstrtoull() checks for the number to be alone in the
string. [2] Where rv equals the number of characters read.
	s += rv;
	if (*s == '\n')
		s++;
	if (*s) {
		return -EINVAL;
	}

So in our case before in speakup, after reading the first number s points to
the empty character between 97 and 98 and it returns -EINVAL.

IMHO there are 3 things I could do:
  - Split the initial string into 3, and use simple_strtoull()
  - Implement speakup's 3 number string into 3 chars differently.
  - Remain using simple_strtoull() and ignore the deprecated warnings.

What do you guys think?
I'm inclined towards the first if there is interest.

Thanks,
Luis


[0] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/x86/boot/string.c?id=b953c0d234bc72e8489d3bf51a276c5c4ec85345#n118
[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/staging/speakup/kobjects.c?id=b953c0d234bc72e8489d3bf51a276c5c4ec85345#n284
[2] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/lib/kstrtox.c?id=b953c0d234bc72e8489d3bf51a276c5c4ec85345#n91

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

* Re: [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint()
  2015-06-24 17:46         ` Luis de Bethencourt
@ 2015-06-25  8:19           ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2015-06-25  8:19 UTC (permalink / raw)
  To: Luis de Bethencourt
  Cc: Sudip Mukherjee, devel, Kirk Reiser, Greg Kroah-Hartman, speakup,
	Melike Yurtoglu, linux-kernel, Domagoj Trsan, Samuel Thibault,
	Chris Brannon

Probably once you start writing a patch you will figure it out.  :)

keymap_store() is a crap function.  We have the cp1 pointer that points
to the end of two back to back 3 char arrays.  The name cp1 is because
it is the second copy of the cp buffer which is a copy of the buf
buffer.  Since it is a backwards array we use cp1[-3] where normally we
would say array[0] and cp1[-1] to mean the last element in the array.

We need around 6 characters in cp1, but we are only garaunteed to have
2.  There is no checking.

Lots of checkpatch.pl warnings.

Just focus on cleaning up keymap_store() and hopefully at the end you
can just delete spk_s2uchar().

regards,
dan carpenter


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

end of thread, other threads:[~2015-06-25  8:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-23 20:47 [PATCH] staging: speakup: replace simple_strtoul() with kstrtoint() Luis de Bethencourt
2015-06-23 22:53 ` Dan Carpenter
2015-06-23 23:15   ` Luis de Bethencourt
2015-06-24  5:23     ` Sudip Mukherjee
2015-06-24 10:19       ` Luis de Bethencourt
2015-06-24 17:46         ` Luis de Bethencourt
2015-06-25  8:19           ` Dan Carpenter

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