mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Joe Perches <joe@perches.com>
Cc: Michal Simek <michal.simek@xilinx.com>,
	linux-kernel@vger.kernel.org,
	Markus Elfring <elfring@users.sourceforge.net>
Subject: Re: [PATCH v2] net: ll_temac: Use one return statement instead of two
Date: Tue, 12 May 2015 07:23:30 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.02.1505120719210.2075@localhost6.localdomain6> (raw)
In-Reply-To: <1431360053.2884.31.camel@perches.com>



On Mon, 11 May 2015, Joe Perches wrote:

> On Mon, 2015-05-11 at 17:48 +0200, Julia Lawall wrote:
> > > > A coccinelle script might be rather more complicated
> > > > than the simpler grep above, but perhaps the script
> > > > could be a bit more complete as it could likely look
> > > > at more code indentation styles.
> > >
> > > Julia: Any comment?
> > 
> > Here is what I had in mind:
> > 
> > if (...) {
> >   ... when != goto l;
> >   return C;
> > }
> > return C;
> > 
> > C is a constant, to avoid that its value depends on the code in the ...
> 
> Sure but I think that would miss several instances like:
> 
> 	switch (<foo>) {
> 		...
> 	default:
> 		return <bar>;
> 	}
> 	return <bar>;

Switch Coccinelle is not very good at...

> or the similar
> 
> 	if (foo) {
> 		if (qux)
> 			return <bar>;
> 	} else {
> 		return <baz>;
> 	}
> 
> 	return <baz>;

It seems improbable, but I could look for that.  Unfortunately, I don't 
see a way to deal with arbitrarily nested ifs.  Basically, the control 
flow from one return doesn't go to the other.  It goes from the return to 
the outside of the function.  I guess something could be done by renaming 
all of the returns to function calls, but that tends to make a mess.  It 
could be done to see if such cases are worth considering though.

Another similar and popular construction is:

if (...) {
  ...
  goto l;
}
l:

julia

  reply	other threads:[~2015-05-12  5:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-11 14:05 Michal Simek
2015-05-11 14:42 ` Joe Perches
2015-05-11 15:26   ` Michal Simek
2015-05-11 15:39     ` Joe Perches
2015-05-11 15:44       ` Michal Simek
2015-05-11 15:48         ` Julia Lawall
2015-05-11 16:00           ` Joe Perches
2015-05-12  5:23             ` Julia Lawall [this message]
2015-05-11 16:10         ` Joe Perches
2015-05-11 16:12           ` Michal Simek
2015-05-11 15:42     ` Julia Lawall
2015-05-11 18:16 ` David Miller

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=alpine.DEB.2.02.1505120719210.2075@localhost6.localdomain6 \
    --to=julia.lawall@lip6.fr \
    --cc=elfring@users.sourceforge.net \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@xilinx.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®