2005-11-15 12:18:37

by Guillaume Chazarain

[permalink] [raw]
Subject: [-mm PATCH 1/2] printk return value: fix it

What's the true meaning of the printk return value?
Should it include the priority prefix length of 3? and what about the timing
information? In both cases it was broken:

strace -e write echo 1 > /dev/kmsg
=> write(1, "1\n", 2) = 5
strace -e write echo "<1>1" > /dev/kmsg
=> write(1, "<1>1\n", 5) = 8

The returned length was "length of input string + 3", I made it "length
of string output to the log buffer".

Note that I couldn't find any printk caller in the kernel interested by its
return value besides kmsg_write.

Signed-off-by: Guillaume Chazarain <[email protected]>
Acked-By: Tim Bird <[email protected]>

---
printk.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)



--
Guillaume



Attachments:
printk.diff (806.00 B)

2005-11-15 23:23:27

by Tim Bird

[permalink] [raw]
Subject: Re: [-mm PATCH 1/2] printk return value: fix it

Guillaume Chazarain wrote:
> What's the true meaning of the printk return value?
> Should it include the priority prefix length of 3? and what about the
> timing
> information? In both cases it was broken:
>
> strace -e write echo 1 > /dev/kmsg
> => write(1, "1\n", 2) = 5
> strace -e write echo "<1>1" > /dev/kmsg
> => write(1, "<1>1\n", 5) = 8
This is clearly a bug, but due to (almost) no one
ever checking the return value, it has gone unnoticed.

>
> The returned length was "length of input string + 3", I made it "length
> of string output to the log buffer".

I agree with this change. I think it fits with how
the size is returned from printf in user space,
which can be greater than the length of the format
string when values are replaced in the string. So
at least for printf, there is a precedent for returning a
number greater than the length of the submitted string.

-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Electronics
=============================