All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: keescook@chromium.org, joe@perches.com, linux@horizon.com,
	akpm@linux-foundation.org, dan.carpenter@oracle.com,
	davem@davemloft.net, eldad@fogrefinery.com, jbeulich@suse.com,
	jkosina@suse.cz, linux-kernel@vger.kernel.org,
	rdunlap@infradead.org
Subject: Re: [PATCH] vsprintf: drop comment claiming %n is ignored
Date: Sat, 14 Sep 2013 04:05:21 +0100	[thread overview]
Message-ID: <20130914030521.GZ13318@ZenIV.linux.org.uk> (raw)
In-Reply-To: <201309141149.HGF39054.QLJVHFtMFOSOOF@I-love.SAKURA.ne.jp>

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...

  reply	other threads:[~2013-09-14  3:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-11 19:30 [PATCH] vsprintf: drop comment claiming %n is ignored Kees Cook
2013-09-11 20:06 ` Joe Perches
2013-09-11 20:18   ` Kees Cook
2013-09-11 20:20     ` Joe Perches
2013-09-11 20:30       ` KOSAKI Motohiro
2013-09-11 20:28     ` Joe Perches
2013-09-13 19:53       ` George Spelvin
2013-09-13 22:27         ` Joe Perches
2013-09-13 23:03           ` Kees Cook
2013-09-13 23:23             ` Joe Perches
2013-09-16  2:53               ` George Spelvin
2013-09-14  2:17             ` Al Viro
2013-09-14  2:49             ` Tetsuo Handa
2013-09-14  3:05               ` Al Viro [this message]
2013-09-14  3:48                 ` Al Viro
2013-09-14  4:53                   ` Al Viro
2013-09-14  5:26                     ` Joe Perches
2013-09-12  7:03     ` Jan Beulich
2013-09-12  7:31       ` Kees Cook
2013-09-12  7:51         ` Jan Beulich
2013-09-12  7:57       ` Dan Carpenter
2013-09-13 19:49       ` George Spelvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130914030521.GZ13318@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=eldad@fogrefinery.com \
    --cc=jbeulich@suse.com \
    --cc=jkosina@suse.cz \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@horizon.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=rdunlap@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.