All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Petr Mladek <pmladek@suse.cz>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] seq_file: Fix seq_putc() to be consistent with seq_puts()
Date: Mon, 29 Sep 2014 16:47:12 +0100	[thread overview]
Message-ID: <20140929154711.GF7996@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20140929144121.GA30562@pathway.suse.cz>

On Mon, Sep 29, 2014 at 04:41:22PM +0200, Petr Mladek wrote:

> Hmm, this inconsistency seems to be in more functions. I would divide
> it into three categories:
> 
> a) Functions that writes valid data until the end of the buffer
>    and returns -1 when the operation makes it full (m->count ==
>    m->size) or when they are not able to write at all:
> 
> 	seq_bitmap()
> 	seq_bitmap_list()

> b) Functions that writes the full buffer but they report -1 only
>    when they cannot write at all:
> 
> 	set_putc()

> c) Functions that leave mess at the end of the buffer when they could
>    not write all data; they mark it as full and return -1 when this happens:
> 
> 	set_puts()
> 	seq_put_decimal_ull()
> 	seq_put_decimal_ll()
> 	seq_write()

... and they really should not return *anything*.

>   + always return error when seq_overflow() would return overflow;
>     in fact, the full buffer means that the last write operation
>     was most likely incomplete

No.  _Any_ caller that decides to report that error to its caller is fucking
broken.  We had some cases like that.

<greps>

Oh, lovely - notify_fdinfo() is broken.  Exactly that way - "we get an error,
better report it to caller".  Bad idea - overflow is *NOT* something ->show()
must report to seq_read().  In that case you just return 0.  Returning -1
means something very different - "have read(2) fail with EPERM".

fanotify_fdinfo(): ditto.

seq_puts() ones: drivers/parisc/ccio-dma.c:ccio_proc_bitmap_info() - bogus,
but harmless (it assumes for some reason that seq_puts() returns the number
of characters written; return values are added up and ignored).

drivers/regulator/dbx500-prcmu.c:
        err = seq_puts(s, "ux500-regulator status:\n");
        if (err < 0)
                dev_err(dev, "seq_puts overflow\n");
No, you don't - it's not an error.

drivers/watchdog/bcm_kona_wdt.c: EPERM-from-read() bug.

fs/dlm/debug_fs.c: ditto.

drivers/usb/gadget/udc/goku_udc.c: unique case of seq_puts() return value
used correctly.  I.e. "if it's already overflown, don't bother with
producing the rest of output, you'll be called again on bigger buffer
anyway; just return 0 and be done with it" hint.  And yes, it is the
only place in the tree that looks at return value of seq_puts() and uses
it correctly.

<greps for seq_printf>

arch/arm/plat-pxa/dma.c:59:     pos += seq_printf(s, "DMA channel %d requesters list :\n", chan);
Bogus.  seq_printf() returns 0 or -1, again with the same kind of semantics
("don't bother with more output, you've already overflown" hint).

arch/microblaze/kernel/cpu/mb.c: same bogosity, but there it at least
ignores the sum and just returns 0 in the end.  Why the hell add them
up is a mystery...

drivers/base/power/wakeup.c: called in a helper, returned to caller, which
promptly ignores it.

drivers/mtd/devices/docg3.c: bogus, overflow leads to read(2) returning
more or less random error.

drivers/parisc/ccio-dma.c: added up and ignored.
drivers/parisc/sba_iommu.c: added up and ignored.

conntrack ct_seq_show() and friends: used properly.

net/netfilter/nf_log.c: bogus, EPERM-from-read() kind.

OK, I'm convinced - we do need to make those suckers return nothing at all,
preventing the well-intentioned bugs of that sort.  There had been a discussion
of that a while ago, but it hadn't gone anywhere.  Time to end that
depravity, let's bury the body...

What we need is a helper along the lines of seq_already_overflown() that
could be used by the few places that really want that hint.  As in
	if (seq_already_overflown(m))
		return 0; // we'll be called again with bigger buffer anyway

And let's make seq_printf and friends return void.  Any breakage we miss
on grep will be caught by compiler.  Enough is enough.

  parent reply	other threads:[~2014-09-29 15:47 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-26 18:37 [PATCH] seq_file: Fix seq_putc() to be consistent with seq_puts() Steven Rostedt
2014-09-29 14:41 ` Petr Mladek
2014-09-29 15:25   ` Steven Rostedt
2014-09-29 15:46     ` Joe Perches
2014-09-29 16:11       ` Steven Rostedt
2014-09-29 16:23     ` Petr Mladek
2014-09-29 16:40       ` Steven Rostedt
2014-09-29 15:47   ` Al Viro [this message]
2014-09-29 16:08     ` Joe Perches
2014-09-29 16:15       ` Steven Rostedt
2014-09-29 16:30         ` Joe Perches
2014-09-29 16:42           ` Steven Rostedt
2014-09-29 16:55             ` Joe Perches
2014-09-29 23:08             ` [Cluster-devel] [PATCH 0/7] seq_printf cleanups Joe Perches
2014-09-29 23:08               ` Joe Perches
2014-09-29 23:08               ` Joe Perches
2014-09-29 23:08               ` [PATCH 1/7] seq_file: Rename static bool seq_overflow to public bool seq_is_full Joe Perches
2014-09-29 23:44                 ` Steven Rostedt
2014-09-29 23:48                   ` Joe Perches
2014-09-30 10:06                 ` Petr Mladek
2014-09-29 23:08               ` [PATCH 2/7] netfilter: Convert print_tuple functions to return void Joe Perches
2014-09-30 10:22                 ` Petr Mladek
2014-09-30 13:04                   ` Joe Perches
2014-09-29 23:08               ` [Cluster-devel] [PATCH 3/7] dlm: Use seq_is_full - remove seq_printf returns Joe Perches
2014-09-29 23:08                 ` Joe Perches
2014-09-30 10:34                 ` [Cluster-devel] " Petr Mladek
2014-09-30 10:34                   ` Petr Mladek
2014-10-27 20:17                   ` [Cluster-devel] " Steven Rostedt
2014-10-27 20:17                     ` Steven Rostedt
2014-10-27 20:25                     ` [Cluster-devel] " Joe Perches
2014-10-27 20:25                       ` Joe Perches
2014-10-29 12:21                     ` [Cluster-devel] " Petr Mladek
2014-10-29 12:21                       ` Petr Mladek
2014-09-29 23:08               ` [Cluster-devel] [PATCH 4/7] dlm: Use seq_puts, remove unnecessary trailing spaces Joe Perches
2014-09-29 23:08                 ` Joe Perches
2014-09-29 23:08               ` [PATCH 5/7] fs: Convert show_fdinfo functions to void Joe Perches
2014-10-28 14:11                 ` Steven Rostedt
2014-10-28 14:31                   ` Joe Perches
2014-10-28 14:43                     ` Steven Rostedt
2014-09-29 23:08               ` [PATCH 6/7] debugfs: Fix misuse of seq_printf return value Joe Perches
2014-10-28 14:58                 ` Steven Rostedt
2014-10-28 15:25                   ` Joe Perches
2014-10-28 15:42                     ` Steven Rostedt
2014-10-28 15:59                       ` Joe Perches
2014-11-07 19:03                 ` Greg Kroah-Hartman
2014-09-29 23:08               ` [PATCH 7/7] docg3: Fix miuse " Joe Perches
2014-09-29 23:08                 ` Joe Perches
2014-10-22  8:29                 ` Brian Norris
2014-10-22  8:29                   ` Brian Norris
2014-10-28 15:13                   ` Steven Rostedt
2014-10-28 15:13                     ` Steven Rostedt
2014-10-28 15:57                     ` Joe Perches
2014-10-28 15:57                       ` Joe Perches
2014-10-28 16:05                       ` Steven Rostedt
2014-10-28 16:05                         ` Steven Rostedt
2014-10-28 17:14                         ` Brian Norris
2014-10-28 17:14                           ` Brian Norris
2014-10-28 17:26                           ` Steven Rostedt
2014-10-28 17:26                             ` Steven Rostedt
2014-10-28 17:27                         ` Joe Perches
2014-10-28 17:27                           ` Joe Perches
2014-10-28 17:32                           ` Steven Rostedt
2014-10-28 17:32                             ` Steven Rostedt
2014-10-28 17:36                             ` Brian Norris
2014-10-28 17:36                               ` Brian Norris
2014-10-28 17:38                             ` Joe Perches
2014-10-28 17:38                               ` Joe Perches
2014-10-28 15:32               ` [Cluster-devel] [PATCH 0/7] seq_printf cleanups Steven Rostedt
2014-10-28 15:32                 ` Steven Rostedt
2014-10-28 15:32                 ` Steven Rostedt
2014-10-28 15:51                 ` [Cluster-devel] " Joe Perches
2014-10-28 15:51                   ` Joe Perches
2014-10-28 15:51                   ` Joe Perches
2014-10-06  3:33       ` [PATCH] seq_file: Fix seq_putc() to be consistent with seq_puts() Joe Perches
2014-09-29 16:09     ` Steven Rostedt
2014-09-29 16:41       ` Al Viro

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=20140929154711.GF7996@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.cz \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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.