From: Ben Hutchings <ben@decadent.org.uk>
To: David Miller <davem@davemloft.net>, rweikusat@mobileactivedefense.com
Cc: hannes@stressinduktion.org, edumazet@google.com,
dhowells@redhat.com, ying.xue@windriver.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, joseph.salisbury@canonical.com
Subject: Re: [PATCH] af_unix: Don't set err in unix_stream_read_generic unless there was an error
Date: Wed, 17 Feb 2016 00:24:51 +0000 [thread overview]
Message-ID: <1455668691.1143.18.camel@decadent.org.uk> (raw)
In-Reply-To: <20160216.125157.1927195719504877809.davem@davemloft.net>
[-- Attachment #1: Type: text/plain, Size: 1882 bytes --]
On Tue, 2016-02-16 at 12:51 -0500, David Miller wrote:
> From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
> Date: Mon, 08 Feb 2016 18:47:19 +0000
>
> > The present unix_stream_read_generic contains various code sequences of
> > the form
> >
> > err = -EDISASTER;
> > if ()
> > goto out;
> >
> > This has the unfortunate side effect of possibly causing the error code
> > to bleed through to the final
> >
> > out:
> > return copied ? : err;
> >
> > and then to be wrongly returned if no data was copied because the caller
> > didn't supply a data buffer, as demonstrated by the program available at
> >
> > http://pad.lv/1540731
> >
> > Change it such that err is only set if an error condition was detected.
> >
> > Fixes: 3822b5c2fc62 ("af_unix: Revert 'lock_interruptible' in stream receive code")
> > Reported-by: Joseph Salisbury <joseph.salisbury@canonical.com>
> > Signed-off-by: Rainer Weikusat <rweikusat@mobileactivedefense.com>
>
> Applied, thanks Rainer.
>
> And BTW I disagree with some of the feedback I saw in these threads
> about "if (x) goto out;" being unreadable and that it should be avoided.
That's not what I said.
> That's completely wrong.
>
> Fact is, we've all been reading code of that form for multiple decades.
> So it's the style we are _MOST_ familiar with, and it is therefore the
> style that is the easiest and clearest for kernel developers to understand.
[...]
I agree that 'if (err) goto cleanup;' is widely used and is generally
understandable (though more creative uses of goto are often not).
My objection was to 'err = -EFOO; if (cond) goto cleanup;'. That is definitely not clear and it hides mistakes like this.
Ben.
--
Ben Hutchings
Lowery's Law:
If it jams, force it. If it breaks, it needed replacing anyway.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]
next prev parent reply other threads:[~2016-02-17 0:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-05 18:50 [V4.4-rc6 Regression] af_unix: Revert 'lock_interruptible' in stream receive code Joseph Salisbury
2016-02-05 19:59 ` Rainer Weikusat
2016-02-05 20:06 ` Joseph Salisbury
2016-02-05 21:18 ` Rainer Weikusat
2016-02-05 22:04 ` Rainer Weikusat
2016-02-05 21:44 ` Rainer Weikusat
2016-02-05 23:03 ` Eric Dumazet
2016-02-07 18:43 ` Rainer Weikusat
2016-02-07 20:39 ` Rainer Weikusat
2016-02-07 22:24 ` Rainer Weikusat
2016-02-08 3:35 ` Eric Dumazet
2016-02-05 22:30 ` [PATCH] af_unix: Don't set err in unix_stream_read_generic unless there was an error Rainer Weikusat
2016-02-07 19:20 ` Rainer Weikusat
2016-02-08 15:33 ` Rainer Weikusat
2016-02-08 18:05 ` Rainer Weikusat
2016-02-08 18:47 ` Rainer Weikusat
2016-02-16 17:51 ` David Miller
2016-02-17 0:24 ` Ben Hutchings [this message]
2016-02-17 1:07 ` David Miller
2016-02-08 18:33 ` Sergei Shtylyov
2016-02-11 21:31 ` Joseph Salisbury
2016-02-12 13:31 ` Rainer Weikusat
2016-02-13 0:18 ` Ben Hutchings
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=1455668691.1143.18.camel@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=hannes@stressinduktion.org \
--cc=joseph.salisbury@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rweikusat@mobileactivedefense.com \
--cc=stable@vger.kernel.org \
--cc=ying.xue@windriver.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®