* [PATCH] Fix bytecount result from printk()
@ 2005-12-01 15:55 Mark Lord
2005-12-01 16:09 ` Linus Torvalds
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Mark Lord @ 2005-12-01 15:55 UTC (permalink / raw)
To: linux-kernel; +Cc: Linus Torvalds
[-- Attachment #1: Type: text/plain, Size: 1430 bytes --]
printk() returns a bytecount, which nothing actually appears to use.
This count is generated internally in vprintk(),
and is off-by-3 for one particular path through that function.
This patch fixes it to be consistent with how it is calculated
for the other paths through that same function (vprintk).
Whether or not the count should even exist in the first place
is still a question for examination -- nothing appears to use it.
On a related note, WHY does the LOG LEVEL format <6> not get
interpreted correctly for the first printk() after an oops report?
As in this example -- the <6> is printed, instead of being interpreted:
kernel: <6>note: insmod[31060] exited with preempt_count 1
Here's the off-by-3 fix patch.
Signed-off-by: Mark Lord <lkml@rtr.ca>
--- linux-2.6.15-rc3/kernel/printk.c.orig 2005-11-29 23:24:19.000000000 -0500
+++ linux/kernel/printk.c 2005-12-01 10:01:39.000000000 -0500
@@ -592,8 +592,8 @@
emit_log_char(default_message_loglevel
+ '0');
emit_log_char('>');
- }
- printed_len += 3;
+ } else
+ printed_len += 3;
}
log_level_unknown = 0;
if (!*p)
[-- Attachment #2: printk.patch --]
[-- Type: text/x-patch, Size: 358 bytes --]
--- linux-2.6.15-rc3/kernel/printk.c.orig 2005-11-29 23:24:19.000000000 -0500
+++ linux/kernel/printk.c 2005-12-01 10:01:39.000000000 -0500
@@ -592,8 +592,8 @@
emit_log_char(default_message_loglevel
+ '0');
emit_log_char('>');
- }
- printed_len += 3;
+ } else
+ printed_len += 3;
}
log_level_unknown = 0;
if (!*p)
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] Fix bytecount result from printk()
2005-12-01 15:55 [PATCH] Fix bytecount result from printk() Mark Lord
@ 2005-12-01 16:09 ` Linus Torvalds
2005-12-01 16:25 ` Mark Lord
2005-12-01 17:57 ` Dave Jones
2005-12-01 20:14 ` David S. Miller
2 siblings, 1 reply; 11+ messages in thread
From: Linus Torvalds @ 2005-12-01 16:09 UTC (permalink / raw)
To: Mark Lord; +Cc: linux-kernel
On Thu, 1 Dec 2005, Mark Lord wrote:
>
> On a related note, WHY does the LOG LEVEL format <6> not get
> interpreted correctly for the first printk() after an oops report?
It never gets interpreted except at the behinning of a line. Sounds like
the oops report perhaps prints a " " without a newline or something at the
end, so that the next message after that isn't a new line?
Linus
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Fix bytecount result from printk()
2005-12-01 16:09 ` Linus Torvalds
@ 2005-12-01 16:25 ` Mark Lord
0 siblings, 0 replies; 11+ messages in thread
From: Mark Lord @ 2005-12-01 16:25 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linux-kernel
Linus Torvalds wrote:
>
> On Thu, 1 Dec 2005, Mark Lord wrote:
>
>>On a related note, WHY does the LOG LEVEL format <6> not get
>>interpreted correctly for the first printk() after an oops report?
>
> It never gets interpreted except at the behinning of a line. Sounds like
> the oops report perhaps prints a " " without a newline or something at the
> end, so that the next message after that isn't a new line?
The oops report always ends with a simple newline: printk("\n");
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Fix bytecount result from printk()
2005-12-01 15:55 [PATCH] Fix bytecount result from printk() Mark Lord
2005-12-01 16:09 ` Linus Torvalds
@ 2005-12-01 17:57 ` Dave Jones
2005-12-01 20:15 ` David S. Miller
2005-12-02 2:04 ` Andrew Morton
2005-12-01 20:14 ` David S. Miller
2 siblings, 2 replies; 11+ messages in thread
From: Dave Jones @ 2005-12-01 17:57 UTC (permalink / raw)
To: Mark Lord; +Cc: linux-kernel, Linus Torvalds
On Thu, Dec 01, 2005 at 10:55:49AM -0500, Mark Lord wrote:
> printk() returns a bytecount, which nothing actually appears to use.
We do check it in a few places.
arch/x86_64/kernel/traps.c: i += printk(" "); \
arch/x86_64/kernel/traps.c: i += printk(" <%s> ", id);
arch/x86_64/kernel/traps.c: i += printk(" <EOE> ");
arch/x86_64/kernel/traps.c: i += printk(" <IRQ> ");
arch/x86_64/kernel/traps.c: i += printk(" <EOI> ");
drivers/char/mem.c: ret = printk("%s", tmp);
Dave
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] Fix bytecount result from printk()
2005-12-01 17:57 ` Dave Jones
@ 2005-12-01 20:15 ` David S. Miller
2005-12-02 1:23 ` Andi Kleen
2005-12-02 2:04 ` Andrew Morton
1 sibling, 1 reply; 11+ messages in thread
From: David S. Miller @ 2005-12-01 20:15 UTC (permalink / raw)
To: davej; +Cc: lkml, linux-kernel, torvalds
From: Dave Jones <davej@redhat.com>
Date: Thu, 1 Dec 2005 12:57:32 -0500
> On Thu, Dec 01, 2005 at 10:55:49AM -0500, Mark Lord wrote:
> > printk() returns a bytecount, which nothing actually appears to use.
>
> We do check it in a few places.
>
> arch/x86_64/kernel/traps.c: i += printk(" "); \
> arch/x86_64/kernel/traps.c: i += printk(" <%s> ", id);
> arch/x86_64/kernel/traps.c: i += printk(" <EOE> ");
> arch/x86_64/kernel/traps.c: i += printk(" <IRQ> ");
> arch/x86_64/kernel/traps.c: i += printk(" <EOI> ");
> drivers/char/mem.c: ret = printk("%s", tmp);
Wow, that's amazing. :)
I bet these can easily be removed, and since printk() is such
a core thing, simplifying it should trump whatever benfits
these few call sites have from getting a return byte count.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] Fix bytecount result from printk()
2005-12-01 20:15 ` David S. Miller
@ 2005-12-02 1:23 ` Andi Kleen
2005-12-01 21:09 ` Mark Lord
0 siblings, 1 reply; 11+ messages in thread
From: Andi Kleen @ 2005-12-02 1:23 UTC (permalink / raw)
To: David S. Miller; +Cc: lkml, linux-kernel, torvalds, davej
"David S. Miller" <davem@davemloft.net> writes:
> From: Dave Jones <davej@redhat.com>
> Date: Thu, 1 Dec 2005 12:57:32 -0500
>
> > On Thu, Dec 01, 2005 at 10:55:49AM -0500, Mark Lord wrote:
> > > printk() returns a bytecount, which nothing actually appears to use.
> >
> > We do check it in a few places.
> >
> > arch/x86_64/kernel/traps.c: i += printk(" "); \
> > arch/x86_64/kernel/traps.c: i += printk(" <%s> ", id);
> > arch/x86_64/kernel/traps.c: i += printk(" <EOE> ");
> > arch/x86_64/kernel/traps.c: i += printk(" <IRQ> ");
> > arch/x86_64/kernel/traps.c: i += printk(" <EOI> ");
> > drivers/char/mem.c: ret = printk("%s", tmp);
>
> Wow, that's amazing. :)
Taking the blame.
> I bet these can easily be removed, and since printk() is such
> a core thing, simplifying it should trump whatever benfits
> these few call sites have from getting a return byte count.
I used it for linewrapping in the oops output.
Actually I would expect more users from sprintf and snprintf
(e.g. common in /proc output to compute the return value of the read)
and that is exactly the same code path.
If you do the same grep for sn?printf I bet there will be much more hits.
-Andi
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] Fix bytecount result from printk()
2005-12-02 1:23 ` Andi Kleen
@ 2005-12-01 21:09 ` Mark Lord
2005-12-01 21:16 ` Andi Kleen
0 siblings, 1 reply; 11+ messages in thread
From: Mark Lord @ 2005-12-01 21:09 UTC (permalink / raw)
To: Andi Kleen; +Cc: David S. Miller, linux-kernel, torvalds, davej
Andi Kleen wrote:
> "David S. Miller" <davem@davemloft.net> writes:
..
>>Wow, that's amazing. :)
>
> Taking the blame.
>
>>I bet these can easily be removed, and since printk() is such
>>a core thing, simplifying it should trump whatever benfits
>>these few call sites have from getting a return byte count.
>
> I used it for linewrapping in the oops output.
...
> Actually I would expect more users from sprintf and snprintf
> (e.g. common in /proc output to compute the return value of the read)
> and that is exactly the same code path.
When I grep the 2.6.15-rc3 kernel tree, the *only* use of vprintk
seems to be for doing printk(). It does not seem to be used for
the sprintf/snprintf functions. Actually it is the other way around,
where vprintk() calls those functions.
So no problem there, and vprintk() really doesn't need to return anything.
Cheers
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Fix bytecount result from printk()
2005-12-01 21:09 ` Mark Lord
@ 2005-12-01 21:16 ` Andi Kleen
0 siblings, 0 replies; 11+ messages in thread
From: Andi Kleen @ 2005-12-01 21:16 UTC (permalink / raw)
To: Mark Lord; +Cc: Andi Kleen, David S. Miller, linux-kernel, torvalds, davej
> When I grep the 2.6.15-rc3 kernel tree, the *only* use of vprintk
> seems to be for doing printk(). It does not seem to be used for
> the sprintf/snprintf functions. Actually it is the other way around,
> where vprintk() calls those functions.
>
> So no problem there, and vprintk() really doesn't need to return anything.
That seems wrong. I'm pretty sure we don't have two different printf formatting engines.
-Andi
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Fix bytecount result from printk()
2005-12-01 17:57 ` Dave Jones
2005-12-01 20:15 ` David S. Miller
@ 2005-12-02 2:04 ` Andrew Morton
2005-12-02 2:22 ` Mark Lord
1 sibling, 1 reply; 11+ messages in thread
From: Andrew Morton @ 2005-12-02 2:04 UTC (permalink / raw)
To: Dave Jones; +Cc: lkml, linux-kernel, torvalds
Dave Jones <davej@redhat.com> wrote:
>
> On Thu, Dec 01, 2005 at 10:55:49AM -0500, Mark Lord wrote:
> > printk() returns a bytecount, which nothing actually appears to use.
>
> We do check it in a few places.
>
> arch/x86_64/kernel/traps.c: i += printk(" "); \
> arch/x86_64/kernel/traps.c: i += printk(" <%s> ", id);
> arch/x86_64/kernel/traps.c: i += printk(" <EOE> ");
> arch/x86_64/kernel/traps.c: i += printk(" <IRQ> ");
> arch/x86_64/kernel/traps.c: i += printk(" <EOI> ");
> drivers/char/mem.c: ret = printk("%s", tmp);
>
And if you don't fix kmsg_write(), this patch will actually break /dev/kmsg
- userspace complains about the write() return value.
Please review these patches, queued since 2.6.15-rc1-mm1:
ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.15-rc3/2.6.15-rc3-mm1/broken-out/printk-return-value-fix-it.patch
ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.15-rc3/2.6.15-rc3-mm1/broken-out/kmsg_write-dont-return-printk-return-value.patch
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Fix bytecount result from printk()
2005-12-01 15:55 [PATCH] Fix bytecount result from printk() Mark Lord
2005-12-01 16:09 ` Linus Torvalds
2005-12-01 17:57 ` Dave Jones
@ 2005-12-01 20:14 ` David S. Miller
2 siblings, 0 replies; 11+ messages in thread
From: David S. Miller @ 2005-12-01 20:14 UTC (permalink / raw)
To: lkml; +Cc: linux-kernel, torvalds
From: Mark Lord <lkml@rtr.ca>
Date: Thu, 01 Dec 2005 10:55:49 -0500
> Whether or not the count should even exist in the first place
> is still a question for examination -- nothing appears to use it.
I think it should be killed, in all of my Linux kernel
hacking I've never seen a user of this return value. :-)
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2005-12-02 2:22 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-01 15:55 [PATCH] Fix bytecount result from printk() Mark Lord
2005-12-01 16:09 ` Linus Torvalds
2005-12-01 16:25 ` Mark Lord
2005-12-01 17:57 ` Dave Jones
2005-12-01 20:15 ` David S. Miller
2005-12-02 1:23 ` Andi Kleen
2005-12-01 21:09 ` Mark Lord
2005-12-01 21:16 ` Andi Kleen
2005-12-02 2:04 ` Andrew Morton
2005-12-02 2:22 ` Mark Lord
2005-12-01 20:14 ` David S. Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox