Re: [PATCH] ipc: Remove uses of return value of seq_printf/seq_puts

From: Al Viro
Date: Tue Feb 17 2015 - 18:16:42 EST

On Tue, Feb 17, 2015 at 02:52:46PM -0800, Andrew Morton wrote:
> On Tue, 17 Feb 2015 11:44:48 -0800 Joe Perches <joe@xxxxxxxxxxx> wrote:
> > These functions are soon going to return void
> That's news to me.
> > so remove the
> > return value uses.
> >
> > Convert the return value to test seq_has_overflowed() instead.
> Why not make seq_printf() return seq_has_overflowed()?

Because we are getting well-meaning folks who try to check that return value,
again and again, getting it wrong every time. Typical idiocies:
* return some kind of error out of ->show() on overflows. Pointless
*and* wrong - only hard errors (== fail read(2) with that) should be
reported that way; the caller does detect overflow and retires with bigger
buffer just fine.
* keep checking it after every sodding call of seq_...(), screwing
the cleanups up more often than not. Pointless, unless you are doing some
seriously expensive calculations to produce something you are going to print.
seq_...() are no-ops in case when overflow has already happened.

seq_had_overflowed() is only for situations when you really want to skip
a serious amount of work generating the data that would end up being
discarded and recalculated again when the caller grabs a bigger buffer and
calls you again. And more often than not it's an indication of ->show()
trying to do the work of iterator - e.g. when you have single_open() with
->show() printing the entire hash table of some sort all in one record.

Most of the time checking return value of seq_...() is better replaced with
not doing that. And "must check return value and Do Something(tm)" is too
strong habit for enough people to cause recurring trouble.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at