* kobject sample code
@ 2014-12-09 2:20 John de la Garza
2014-12-09 9:26 ` Paul Bolle
0 siblings, 1 reply; 5+ messages in thread
From: John de la Garza @ 2014-12-09 2:20 UTC (permalink / raw)
To: kernelnewbies
I'm looking at samples/kobject/kobject-example.c
at line 39 foo is read:
sscanf(buf, "%du", &foo);
foo is an int so why is it read using %du not %d?
^ permalink raw reply [flat|nested] 5+ messages in thread
* kobject sample code
2014-12-09 2:20 kobject sample code John de la Garza
@ 2014-12-09 9:26 ` Paul Bolle
2014-12-13 18:01 ` John de la Garza
0 siblings, 1 reply; 5+ messages in thread
From: Paul Bolle @ 2014-12-09 9:26 UTC (permalink / raw)
To: kernelnewbies
On Mon, 2014-12-08 at 21:20 -0500, John de la Garza wrote:
> I'm looking at samples/kobject/kobject-example.c
>
> at line 39 foo is read:
>
> sscanf(buf, "%du", &foo);
>
> foo is an int so why is it read using %du not %d?
My reading of lib/vsprintf.c:vsscanf() is that a "%du" format expects
"buf" to contain an integer followed by a literal 'u' char. Is that your
reading too?
Paul Bolle
^ permalink raw reply [flat|nested] 5+ messages in thread
* kobject sample code
2014-12-09 9:26 ` Paul Bolle
@ 2014-12-13 18:01 ` John de la Garza
2014-12-17 21:31 ` Paul Bolle
0 siblings, 1 reply; 5+ messages in thread
From: John de la Garza @ 2014-12-13 18:01 UTC (permalink / raw)
To: kernelnewbies
On Tue, Dec 09, 2014 at 10:26:03AM +0100, Paul Bolle wrote:
> On Mon, 2014-12-08 at 21:20 -0500, John de la Garza wrote:
> > I'm looking at samples/kobject/kobject-example.c
> >
> > at line 39 foo is read:
> >
> > sscanf(buf, "%du", &foo);
> >
> > foo is an int so why is it read using %du not %d?
>
> My reading of lib/vsprintf.c:vsscanf() is that a "%du" format expects
> "buf" to contain an integer followed by a literal 'u' char. Is that your
> reading too?
>
After reading the code and the man page for vsscanf, it seems like
it is not expecting the 'u', but rather ignores it.
vsscanf is a bit complicated for me, so I may be missing something.
^ permalink raw reply [flat|nested] 5+ messages in thread
* kobject sample code
2014-12-13 18:01 ` John de la Garza
@ 2014-12-17 21:31 ` Paul Bolle
2014-12-17 23:35 ` Rastislav Barlik
0 siblings, 1 reply; 5+ messages in thread
From: Paul Bolle @ 2014-12-17 21:31 UTC (permalink / raw)
To: kernelnewbies
On Sat, 2014-12-13 at 13:01 -0500, John de la Garza wrote:
> On Tue, Dec 09, 2014 at 10:26:03AM +0100, Paul Bolle wrote:
> > On Mon, 2014-12-08 at 21:20 -0500, John de la Garza wrote:
> > > I'm looking at samples/kobject/kobject-example.c
> > >
> > > at line 39 foo is read:
> > >
> > > sscanf(buf, "%du", &foo);
> > >
> > > foo is an int so why is it read using %du not %d?
> >
> > My reading of lib/vsprintf.c:vsscanf() is that a "%du" format expects
> > "buf" to contain an integer followed by a literal 'u' char. Is that your
> > reading too?
> >
> After reading the code and the man page for vsscanf, it seems like
> it is not expecting the 'u', but rather ignores it.
The manpage _probably_ describes intended behavior. But I'm not sure
whether the kernel's vsscanf() tries to emulate it all that faithfully.
(And, besides, that manpage would gain quite a bit with a few examples.)
Anyhow, the net effect of "%du" appears to be to ignore any non digit
trailing input. So I think you're reading the code correctly.
> vsscanf is a bit complicated for me, so I may be missing something.
I wouldn't have bothered replying if I had not noticed
https://lkml.org/lkml/2014/12/17/386 . You might like to have a look at
that patch. My primary observation is that its commit explanation is not
very helpful. (That's why I CC-ed Ratislav.)
Paul Bolle
^ permalink raw reply [flat|nested] 5+ messages in thread
* kobject sample code
2014-12-17 21:31 ` Paul Bolle
@ 2014-12-17 23:35 ` Rastislav Barlik
0 siblings, 0 replies; 5+ messages in thread
From: Rastislav Barlik @ 2014-12-17 23:35 UTC (permalink / raw)
To: kernelnewbies
On Wed, 17 Dec 2014 22:31:21 +0100
Paul Bolle <pebolle@tiscali.nl> wrote:
> On Sat, 2014-12-13 at 13:01 -0500, John de la Garza wrote:
> > On Tue, Dec 09, 2014 at 10:26:03AM +0100, Paul Bolle wrote:
> > > On Mon, 2014-12-08 at 21:20 -0500, John de la Garza wrote:
> > > > I'm looking at samples/kobject/kobject-example.c
> > > >
> > > > at line 39 foo is read:
> > > >
> > > > sscanf(buf, "%du", &foo);
> > > >
> > > > foo is an int so why is it read using %du not %d?
> > >
> > > My reading of lib/vsprintf.c:vsscanf() is that a "%du" format
> > > expects "buf" to contain an integer followed by a literal 'u'
> > > char. Is that your reading too?
> > >
> > After reading the code and the man page for vsscanf, it seems like
> > it is not expecting the 'u', but rather ignores it.
>
> The manpage _probably_ describes intended behavior. But I'm not sure
> whether the kernel's vsscanf() tries to emulate it all that
> faithfully. (And, besides, that manpage would gain quite a bit with a
> few examples.) Anyhow, the net effect of "%du" appears to be to
> ignore any non digit trailing input. So I think you're reading the
> code correctly.
>
> > vsscanf is a bit complicated for me, so I may be missing something.
>
> I wouldn't have bothered replying if I had not noticed
> https://lkml.org/lkml/2014/12/17/386 . You might like to have a look
> at that patch. My primary observation is that its commit explanation
> is not very helpful. (That's why I CC-ed Ratislav.)
>
> Paul Bolle
My understanding is that sscanf() would ignore any trailing input
anyway. So I think that "%du" is just a typo and should have been "%d"
instead. There should also be check for return value from sscanf().
I send a patch which uses kstrtoint() as it is preferred to single
variable sscanf().
--
Kind regards
Rastislav Barlik
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-12-17 23:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-09 2:20 kobject sample code John de la Garza
2014-12-09 9:26 ` Paul Bolle
2014-12-13 18:01 ` John de la Garza
2014-12-17 21:31 ` Paul Bolle
2014-12-17 23:35 ` Rastislav Barlik
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).