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

From: Al Viro
Date: Tue Feb 17 2015 - 19:28:00 EST

On Tue, Feb 17, 2015 at 04:09:44PM -0800, Joe Perches wrote:
> On Tue, 2015-02-17 at 23:16 +0000, Al Viro wrote:
> > 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.
> Does SEQ_SKIP still have value?

Yes, it does, but it's not an error - it's an equivalent of "empty the buffer
before returning". Basically, it's "I've decided that this entry shouldn't
produce anything". Look at the caller:
error = m->op->show(m, p);
if (error < 0)
if (unlikely(error)) {
error = 0;
m->count = 0;
Negatives are hard errors. Positives (without distinction) are equivalent
to zero, except that we discard anything that might've been produced by
this call of ->show(). Another call site (one when we are trying to pack
more into buffer that already has some records in it) is
size_t offs = m->count;
err = m->op->show(m, p);
if (seq_has_overflowed(m) || err) {
m->count = offs;
if (likely(err <= 0))
IOW, here we treat positive as "discard everything produced by this call of
->show(), ignore seq_has_overflowed() it might have triggered". Might as
well have done
if (err > 0) {
m->count = offs; /* seq_has_overflowed() is false now */
err = 0;
if (seq_has_overflowed(m) || err < 0) {
m->count = offs;
except that it'd cost more that way.

In principle, we could've provided seq_discard(m), but that would've required
keeping a snapshot of ->count in another field of struct seq_file, and that -
for a very rarely used thing. And keep in mind that hard errors need to
be reported anyway, so it's not as if we could realistically make ->show()
return void.
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