All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Borkmann <danborkmann@iogearbox.net>
To: Ben Hutchings <bhutchings@solarflare.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
	davem@davemloft.net, netdev@vger.kernel.org
Subject: Re: [PATCH net-next 1/2] packet: clean up error variable assignments
Date: Wed, 24 Oct 2012 09:47:01 +0200	[thread overview]
Message-ID: <CAD6jFUSAkXjFK1tjEAw8tG1YueatRF-kCyjpv61N-3TD-fMtvg@mail.gmail.com> (raw)
In-Reply-To: <1351033824.5283.80.camel@deadeye.wl.decadent.org.uk>

On Wed, Oct 24, 2012 at 1:10 AM, Ben Hutchings
<bhutchings@solarflare.com> wrote:
> On Tue, 2012-10-23 at 19:05 +0200, Eric Dumazet wrote:
>> On Tue, 2012-10-23 at 13:56 +0200, Daniel Borkmann wrote:
>> > This patch performs clean-ups of packet's err variables where appropriate.
>> > In particular, errnos are *only* assigned in error cases, which saves
>> > useless instructions in non-error cases and makes the code more readable
>> > in terms of which error type belongs to which evaluated error condition.
>> > Also, in some cases an errno was set, but not used until the next assignment.
>>
>> I see no value in this patch.
>>
>> Setting err before a test is a common way to handle error cases and
>> generates smaller code in linux kernel.
>>
>> Better live with it than trying to change it ?
>>
>> err = -ENOMEM;
>> match = kzalloc(xxxx);
>> if (!match)
>>       goto error;
>>
>>
>> is smaller (source code & generated code) than :
>>
>> match = kzalloc(xxxx);
>> if (!match) {
>>       err = -ENOMEM;
>>       goto error;
>> }
>>
>> An immediate load is basically free, but code size matters.
>
> In my experience gcc is generally able to perform this optimisation
> itself, at least for x86.  Setting 'err' only after checking for failure
> seems clearer, but I think this is really a matter of taste.

It might also be more likely in case code gets removed, that the
relating 'err' will be removed as well. If I remember correctly, I've
seen one or two cases where there was an assignment with no 'return'
in between the next assignment of 'err'. But probably spatch could
detect such cases as well.

      reply	other threads:[~2012-10-24  7:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-23 11:56 [PATCH net-next 1/2] packet: clean up error variable assignments Daniel Borkmann
2012-10-23 17:05 ` Eric Dumazet
2012-10-23 17:25   ` Daniel Borkmann
2012-10-23 23:10   ` Ben Hutchings
2012-10-24  7:47     ` Daniel Borkmann [this message]

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=CAD6jFUSAkXjFK1tjEAw8tG1YueatRF-kCyjpv61N-3TD-fMtvg@mail.gmail.com \
    --to=danborkmann@iogearbox.net \
    --cc=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@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.