Re: Fixing the printk's in drivers/block/*.c

Theodore Y. Ts'o (tytso@MIT.EDU)
Fri, 24 Jan 1997 12:09:39 -0500

Date: Thu, 23 Jan 1997 14:04:17 -0500
From: (Dale R. Worley)

Quite a number of printk's did not have ending newlines. In some
cases, this seemed to be an ordinary mistake (usually because the flow
of control did not ensure that a newline would be printed in the near
future), and I inserted one. In many cases, though, the message was
being output a section at a time. In these cases, I declared an
automatic buffer of 100 or 200 characters ("buffer") and an integer to
record how many characters were in it ("bufptr") and used sprintf() to
compose the message in the buffer.

Just for the record, everyone should be careful about declaring large
buffers as automatics, or using recursive functions --- the kernel stack
is only 4096 bytes long. An automatic buffer of 200 characters
"probably" wouldn't be a problem, but if numerous functions in a
function call chain all used an extra 200 bytes each, we could run into
a kernel stack overflow. (Remember, interrupts use whatever kernel
stack that they interrupted, as well.)

Whenever possible, it's a really good idea to re-order to code to try to
see if you can avoid the use of the automatic variable, especially in
cases like this.

(I sure hope the kernel sprintf
returns the number of characters output, like the standard says!)

It does.

- Ted