lkml.org 
[lkml]   [2013]   [Sep]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] vsprintf: drop comment claiming %n is ignored
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...


\
 
 \ /
  Last update: 2013-09-14 05:21    [W:0.043 / U:1.380 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site