From: Al Viro <viro@ZenIV.linux.org.uk>
To: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ipc: Remove uses of return value of seq_printf/seq_puts
Date: Wed, 18 Feb 2015 00:27:51 +0000 [thread overview]
Message-ID: <20150218002751.GP29656@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1424218184.25416.11.camel@perches.com>
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)
break;
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))
break;
}
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;
break;
}
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.
next prev parent reply other threads:[~2015-02-18 0:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-17 19:44 [PATCH] ipc: Remove uses of return value of seq_printf/seq_puts Joe Perches
2015-02-17 22:52 ` Andrew Morton
2015-02-17 23:02 ` Joe Perches
2015-02-17 23:16 ` Al Viro
2015-02-18 0:09 ` Joe Perches
2015-02-18 0:27 ` Al Viro [this message]
2015-02-18 0:55 ` Joe Perches
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=20150218002751.GP29656@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=akpm@linux-foundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.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.