netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Håkon Løvdal" <hlovdal@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: mfmooney@gmail.com, joe@perches.com, aquini@linux.com,
	kernel-janitors@vger.kernel.org, fubar@us.ibm.com,
	andy@greyhouse.net, shemminger@vyatta.com,
	netdev@vger.kernel.org, nikai@nikai.net
Subject: Re: [PATCH] net/bonding: adjust codingstyle for bond_3ad files
Date: Mon, 9 May 2011 02:08:41 +0200	[thread overview]
Message-ID: <BANLkTimao-Zyk6ypW3UxzqtsgmQ-6qvYng@mail.gmail.com> (raw)
In-Reply-To: <20110508.161012.258121848.davem@davemloft.net>

On 9 May 2011 01:10, David Miller <davem@davemloft.net> wrote:
> From: Håkon Løvdal <hlovdal@gmail.com>
> Date: Mon, 9 May 2011 01:08:44 +0200
>
>> On 7 May 2011 21:35, matt mooney <mfmooney@gmail.com> wrote:
>>> But isn't the preferred style to have a single exit point?
>>
>> This is generally considered to be a bad advice, see
>> http://stackoverflow.com/questions/1701686/why-should-methods-have-a-single-entry-and-exit-points/1701721#1701721
>> for instance.
>
> That article totally ignores the issue of locking and how hard it is
> to get right without single exit points, and how unlocking in
> multiple spots bloats up the code.
>
> Definitely don't take that article's advice when working on the
> kernel.
>

I think we agree, but my answer was probably too short, unclear and
imprecise. In the case of locking and single exit points in the kernel,
they are (almost always) reached through goto/labels, and this is a fine
way of handling exiting a function, e.g.


void bond_3ad_state_machine_handler(struct work_struct *work)
{
        struct bonding *bond = container_of(work, struct bonding,
                                            ad_work.work);
        struct port *port;
        struct aggregator *aggregator;

        read_lock(&bond->lock);

        if (bond->kill_timers)
                goto out;

        //check if there are any slaves
        if (bond->slave_cnt == 0)
              goto re_arm;

        ...

re_arm:
        queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
out:
        read_unlock(&bond->lock);
}


I often advocate usage of goto to achive this kind of style.

What I assosiate with "writing a function as single exit style" would
be something like the following (and usually littered with
temporary remember-this-for-later variables).


void bond_3ad_state_machine_handler(struct work_struct *work)
{
        struct bonding *bond = container_of(work, struct bonding,
                                            ad_work.work);
        struct port *port;
        struct aggregator *aggregator;

        read_lock(&bond->lock);

        if (! bond->kill_timers) {

                //check if there are any slaves
                if (bond->slave_cnt != 0) {
                        ...
                }
                queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
        }
        read_unlock(&bond->lock);
}


And this was what I trying to reccommend against (and which the
stackoverflow question is about). So most probably my assosiasion was too
implicit to make my reply useful. That was not the intention, hopefully
this followup clears up a little.

BR Håkon Løvdal

  reply	other threads:[~2011-05-09  0:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-07  1:27 [PATCH] net/bonding: adjust codingstyle for bond_3ad files Rafael Aquini
2011-05-07  1:51 ` Joe Perches
2011-05-07 17:31   ` Rafael Aquini
2011-05-07 18:02     ` Joe Perches
2011-05-07 19:35       ` matt mooney
2011-05-07 20:24         ` Joe Perches
2011-05-08 23:08         ` Håkon Løvdal
2011-05-08 23:10           ` David Miller
2011-05-09  0:08             ` Håkon Løvdal [this message]
2011-05-09  0:12               ` David Miller
2011-05-09  1:30                 ` Håkon Løvdal
2011-05-07 21:25       ` Jay Vosburgh
2011-05-07 21:37         ` Rafael Aquini
  -- strict thread matches above, loose matches on Subject: below --
2011-05-10  0:08 Rafael Aquini
2011-05-10  0:15 ` Joe Perches
2011-05-10  2:00 ` Jay Vosburgh
2011-05-10  2:11   ` Joe Perches
2011-05-10 12:22   ` Rafael Aquini
2011-05-06 11:50 Rafael Aquini
2011-05-06 13:01 ` Nicolas Kaiser
2011-05-06 14:56   ` Rafael Aquini

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=BANLkTimao-Zyk6ypW3UxzqtsgmQ-6qvYng@mail.gmail.com \
    --to=hlovdal@gmail.com \
    --cc=andy@greyhouse.net \
    --cc=aquini@linux.com \
    --cc=davem@davemloft.net \
    --cc=fubar@us.ibm.com \
    --cc=joe@perches.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=mfmooney@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikai@nikai.net \
    --cc=shemminger@vyatta.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;
as well as URLs for NNTP newsgroup(s).