printk: return number of input bytes, not output bytes.

If we printk() a string, the return value would reflect the number of bytes
actually written, which would typically be more than the number of bytes
requested (because of added loglevel and/or timestamp prefixes).

The /dev/kmsg driver in drivers/char/mem.c would then proceed to lie about
how many input bytes it had actually processed, because it would return the
value returned by printk(), upper bounded by the requested number of bytes
to write.  Thus if you tried to write more than 1023 bytes at a time to
/dev/kmsg, the return value of write() to userspace would lie about how many
bytes actually got written, so buffering would get messed up and a few
bytes would be lost from the middle of the buffer.

Let's change printk() to do what people might expect, and return the number
of input bytes consumed rather than the number of output bytes produced.  As
far as I can see, nobody actually looks at the return value of printk except
the /dev/kmsg driver, so this should be harmless.

Change-Id: I7f9fa89b57c3518b801f524a3984b005f83a6755
1 file changed