All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: Julia Lawall <julia.lawall@inria.fr>,
	Sumitra Sharma <sumitraartsy@gmail.com>
Cc: Ira Weiny <ira.weiny@intel.com>, <outreachy@lists.linux.dev>
Subject: Re: Warn on macros with flow control statements
Date: Thu, 23 Mar 2023 09:25:53 -0700	[thread overview]
Message-ID: <641c7d91a3a38_303059294c6@iweiny-mobl.notmuch> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2303230905520.2866@hadrien>

Julia Lawall wrote:
> 
> 
> On Wed, 22 Mar 2023, Sumitra Sharma wrote:
> 
> > On Fri, Mar 17, 2023 at 11:19:12PM -0700, Ira Weiny wrote:
> > > Julia Lawall wrote:
> > > > > Based on the flow control I would do something like this.  It is a bit more
> > > > > verbose but is very clear what is happening.
> > > > >
> > > >
> > > > Ira, what do you think of my suggestion of
> > > >
> > > > err = err || qlge_fill_seg_(...);
> > > >
> > > > It would avoid 40 lines of ifs, and would still avoid calling
> > > > qlge_fill_seg_ as soon as there is a failure.  On ther other hand, I don't
> > > > recall this being done elsewhere, so maybe all the ifs would be
> > > > preferable.
> > >
> > > Oh sorry.  I miss read your suggestion and I thought it was going to
> > > continue running qlge_fill_seg_() for all the other calls.  I read this
> > > as:
> > >
> > > err = err | qlge_fill_seg_(...);
> > >
> > > Not sure why.  Just late I guess.
> > >
> > > Yes your suggestion would work.  I do think it is a bit odd though.
> > >
> >
> > Hi Ira,
> >
> > I would like to know why do you think this is odd?
> 
> err = err || ... is not a very common pattern.  I looked through te full
> Linux kernel for them, and found a few.

I concede!  :-D

This is just not a pattern I'm used to so it looked odd to me.

> 
> You can see one in the function rtl8723_dequeue_writeport in
> staging/rtl8723bs/hal/rtl8723bs_xmit.c.  This one is completely useless,
> so it's another cleanup opportunity :)
>

Indeed.

> 
> Some others are in loops, like (scripts/dtc/checks.c):
> 
>         for (i = 0; i < c->num_prereqs; i++) {
>                 struct check *prq = c->prereq[i];
>                 error = error || run_check(prq, dti);
>                 if (prq->status != PASSED) {
>                         c->status = PREREQ;
>                         check_msg(c, dti, NULL, NULL, "Failed prerequisite '%s'",
>                                   c->prereq[i]->name);
>                 }
>         }
> 
> The complete set of files containing this pattern is:
> 
> drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c
> drivers/net/ethernet/intel/i40e/i40e_txrx.c
> drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
> scripts/dtc/checks.c
> kernel/rcu/tree.c
> arch/mips/pci/pci-legacy.c
> drivers/s390/block/dasd_devmap.c
> drivers/net/ethernet/intel/iavf/iavf_txrx.c
> 
> So not many.  But in your case the err = err || ... would be a lot omre
> concise than the version that has ifs everywhere and it owuld be a little
> more understandable than the version that hides the early returns in the
> macro definition.

Yes much better I think.  Sorry for the delay in getting back to you all.
Ira

  reply	other threads:[~2023-03-23 16:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16  8:08 Warn on macros with flow control statements Sumitra Sharma
2023-03-16  8:26 ` Julia Lawall
2023-03-17  7:23   ` Sumitra Sharma
2023-03-18  5:33 ` Ira Weiny
2023-03-18  6:05   ` Julia Lawall
2023-03-18  6:19     ` Ira Weiny
2023-03-23  6:28       ` Sumitra Sharma
2023-03-23  8:15         ` Julia Lawall
2023-03-23 16:25           ` Ira Weiny [this message]
2023-03-23 16:19         ` Ira Weiny

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=641c7d91a3a38_303059294c6@iweiny-mobl.notmuch \
    --to=ira.weiny@intel.com \
    --cc=julia.lawall@inria.fr \
    --cc=outreachy@lists.linux.dev \
    --cc=sumitraartsy@gmail.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 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.