Re: [PATCH] vsprintf: drop comment claiming %n is ignored

From: Al Viro
Date: Fri Sep 13 2013 - 23:05:53 EST


On Sat, Sep 14, 2013 at 11:49:51AM +0900, Tetsuo Handa wrote:

> Even bad code which has never tested failure case, the authors should already
> know that "seq_printf() returns 0 on success case".

It is designed so that not testing failure case is normal approach for the
majority of users.

> - pos += seq_printf(s, "\tChannel number: %d\n", num_dma_channels);
> + seq_puts(s, "DMA engine status\n");
> + seq_printf(s, "\tChannel number: %d\n", num_dma_channels);
>
> - return pos;
> + return seq_overflow(s) : -1 : 0;
>
> for keeping the functionality.

ITYM "for keeping the bug". Read seq_read(), please. Any negative value
returned by ->show() is a hard error. It won't be retried with bigger
buffer; read(2) will *fail*. With -EINVAL, in your case.

We really, really should not return non-zero on overflow. Moreover, returning
a _positive_ value (SEQ_SKIP, normally, but any positive will do the same thing)
means "silently discard everything ->show() might have produced"

Again, the normal return value of ->show() is 0 and that includes the case of
overflow. THE ONLY reason to check for overflow early is when subsequent
output of ->show() takes long to generate and we want to skip that and
have seq_read() do realloc-and-call-show-again immediately. And in that
case the right fix is often to get saner iterator and stop shoving everything
into a single ->show() call...
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/