All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: 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:15:47 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2303230905520.2866@hadrien> (raw)
In-Reply-To: <20230323062853.GB155612@sumitra.com>



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.

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 :)

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.

julia


>
> PS: I was trying to implement your suggestion and was able to connect to
> what julia wrote here.
>
> For reference this is the link to your suggestion https://lore.kernel.org/outreachy/64154d438f0c8_28ae5229421@iweiny-mobl.notmuch/
>
> Regards,
> Sumitra
>
> > Ira
>

  reply	other threads:[~2023-03-23  8:15 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 [this message]
2023-03-23 16:25           ` Ira Weiny
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=alpine.DEB.2.22.394.2303230905520.2866@hadrien \
    --to=julia.lawall@inria.fr \
    --cc=ira.weiny@intel.com \
    --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.