* Re: [PATCH] kernel: acctc.c: Fixed else if not generally userful after a break or return warning [not found] <E1XX0bN-00032o-0x@feisty.vs19.net> @ 2014-09-25 4:31 ` Joe Perches [not found] ` <CAAm9=9QeO_VtdY+fJ5JbrBhN52z=JUeU09Nh3Mp04QWf+Qyygw@mail.gmail.com> 2014-09-25 5:03 ` [PATCH] checkpatch: Add exception to return then else test Joe Perches 0 siblings, 2 replies; 4+ messages in thread From: Joe Perches @ 2014-09-25 4:31 UTC (permalink / raw) To: Al Viro; +Cc: Elshad Mustafayev, LKML On Wed, Sep 24, 2014 at 11:13:45PM -0400, Elshad Mustafayev wrote: > > Fixed a coding style issue. [] > > diff --git a/kernel/acct.c b/kernel/acct.c [] > > @@ -376,9 +376,8 @@ static comp2_t encode_comp2_t(u64 value) > > if (exp > MAXEXP2) { > > /* Overflow. Return largest representable number instead. */ > > return (1ul << (MANTSIZE2+EXPSIZE2-1)) - 1; > > - } else { > > - return (value & (MAXFRACT2>>1)) | (exp << (MANTSIZE2-1)); > > } > > + return (value & (MAXFRACT2>>1)) | (exp << (MANTSIZE2-1)); > > Just what makes the replacement easier to follow? > if (foo) > return bar; > else > return baz; > is no less idiomatic than > if (foo) > return bar; > return baz; > > Al, really annoyed by how the words "coding style issue" are getting used as > a magic incantation... I agree. I'll see about updating checkpatch to avoid warning on if (foo) return bar; else return baz; ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <CAAm9=9QeO_VtdY+fJ5JbrBhN52z=JUeU09Nh3Mp04QWf+Qyygw@mail.gmail.com>]
* Re: [PATCH] kernel: acctc.c: Fixed else if not generally userful after a break or return warning [not found] ` <CAAm9=9QeO_VtdY+fJ5JbrBhN52z=JUeU09Nh3Mp04QWf+Qyygw@mail.gmail.com> @ 2014-09-25 5:00 ` Al Viro 2014-09-25 5:05 ` Joe Perches 0 siblings, 1 reply; 4+ messages in thread From: Al Viro @ 2014-09-25 5:00 UTC (permalink / raw) To: Elshad Mustafayev; +Cc: Joe Perches, linux-kernel On Thu, Sep 25, 2014 at 12:34:11AM -0400, Elshad Mustafayev wrote: > I am sorry if I disturbed you. I just follow the steps in kernel newbies to > get me in kernel development. It's not you, it's checkpatch.pl plus the fairly common tendency to give that thing a lot more respect than it deserves... Basically, it's OK as a tool that draws ones attention to a subset of code that might or might not be worth looking at; it gives both false positives and false negatives and as long as there's not too much of those, it's useful. Provided that it does *not* replace one's taste. I.e. "hey, it points to these lines; let's take a look, some of those might be worth some attention", rather than "The Most Holy Oracle Has Spoken; Do What It Says". ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kernel: acctc.c: Fixed else if not generally userful after a break or return warning 2014-09-25 5:00 ` Al Viro @ 2014-09-25 5:05 ` Joe Perches 0 siblings, 0 replies; 4+ messages in thread From: Joe Perches @ 2014-09-25 5:05 UTC (permalink / raw) To: Al Viro; +Cc: Elshad Mustafayev, linux-kernel On Thu, 2014-09-25 at 06:00 +0100, Al Viro wrote: > It's not you, it's checkpatch.pl plus the fairly common tendency to give > that thing a lot more respect than it deserves... > > Basically, it's OK as a tool that draws ones attention to a subset of > code that might or might not be worth looking at; it gives both false > positives and false negatives and as long as there's not too much of those, > it's useful. Provided that it does *not* replace one's taste. I.e. "hey, > it points to these lines; let's take a look, some of those might be > worth some attention", rather than "The Most Holy Oracle Has Spoken; > Do What It Says". Just so. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] checkpatch: Add exception to return then else test 2014-09-25 4:31 ` [PATCH] kernel: acctc.c: Fixed else if not generally userful after a break or return warning Joe Perches [not found] ` <CAAm9=9QeO_VtdY+fJ5JbrBhN52z=JUeU09Nh3Mp04QWf+Qyygw@mail.gmail.com> @ 2014-09-25 5:03 ` Joe Perches 1 sibling, 0 replies; 4+ messages in thread From: Joe Perches @ 2014-09-25 5:03 UTC (permalink / raw) To: Andrew Morton; +Cc: Elshad Mustafayev, LKML, Al Viro, Andy Whitcroft Add an exception to the return before else warning when the line following it is also a return like: if (foo) return bar; else return baz; This form of a test then return is at least as readable as if (foo) return bar; return baz; so don't emit a warning on the first form. Signed-off-by: Joe Perches <joe@perches.com> Reported-by: Al Viro <viro@ZenIV.linux.org.uk> --- > > Just what makes the replacement easier to follow? > > if (foo) > > return bar; > > else > > return baz; > > is no less idiomatic than > > if (foo) > > return bar; > > return baz; > > > > Al, really annoyed by how the words "coding style issue" are getting used as > > a magic incantation... > > I agree. > > I'll see about updating checkpatch to avoid warning on it scripts/checkpatch.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 74bba23..52a223e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2641,10 +2641,14 @@ sub process { next if ($realfile !~ /\.(h|c)$/); # check indentation of any line with a bare else +# (but not if it is a multiple line "if (foo) return bar; else return baz;") # if the previous line is a break or return and is indented 1 tab more... if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) { my $tabs = length($1) + 1; - if ($prevline =~ /^\+\t{$tabs,$tabs}(?:break|return)\b/) { + if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ || + ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ && + defined $lines[$linenr] && + $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) { WARN("UNNECESSARY_ELSE", "else is not generally useful after a break or return\n" . $hereprev); } ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-09-25 5:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <E1XX0bN-00032o-0x@feisty.vs19.net>
2014-09-25 4:31 ` [PATCH] kernel: acctc.c: Fixed else if not generally userful after a break or return warning Joe Perches
[not found] ` <CAAm9=9QeO_VtdY+fJ5JbrBhN52z=JUeU09Nh3Mp04QWf+Qyygw@mail.gmail.com>
2014-09-25 5:00 ` Al Viro
2014-09-25 5:05 ` Joe Perches
2014-09-25 5:03 ` [PATCH] checkpatch: Add exception to return then else test Joe Perches
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®