mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Dan Carpenter' <dan.carpenter@oracle.com>
Cc: 'Alaa Mohamed' <eng.alaamohamedsoliman.am@gmail.com>,
	"outreachy@lists.linux.dev" <outreachy@lists.linux.dev>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] staging: gdm724x: Fix Duplication of Side Effects
Date: Thu, 31 Mar 2022 10:49:24 +0000	[thread overview]
Message-ID: <acde5b1e8495431dac05403c593d4679@AcuMS.aculab.com> (raw)
In-Reply-To: <20220331104012.GM3293@kadam>

From: Dan Carpenter
> Sent: 31 March 2022 11:40
> 
> On Thu, Mar 31, 2022 at 10:29:04AM +0000, David Laight wrote:
> > From: Alaa Mohamed
> > > Sent: 31 March 2022 11:19
> > >
> > > Fix Duplication of Side Effects for GDM_TTY_READY(gdm) macro
> > > reported by checkpatch
> > > "CHECK: Macro argument reuse 'gdm' - possible side-effects?"
> > >
> > > Signed-off-by: Alaa Mohamed <eng.alaamohamedsoliman.am@gmail.com>
> > > ---
> > >  drivers/staging/gdm724x/gdm_tty.c | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
> > > index 04df6f9f5403..6f0274470e69 100644
> > > --- a/drivers/staging/gdm724x/gdm_tty.c
> > > +++ b/drivers/staging/gdm724x/gdm_tty.c
> > > @@ -27,7 +27,9 @@
> > >
> > >  #define MUX_TX_MAX_SIZE 2048
> > >
> > > -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
> > > +#define GDM_TTY_READY(_gdm) \
> > > +	({ typeof(_gdm) (gdm) = (_gdm); \
> > > +	(gdm && gdm->tty_dev && gdm->port.count); })
> >
> > Did you test this?
> >
> > see https://godbolt.org/z/cazPrrzPv
> >
> 
> I don't understand the link.  The patch should work as far as I can see.

If you call GDM_TTY_READY(gdm) the first line ends up as:
	struct xxx *gdm = gdm;
which shadows the parameter.
There's probably a warning about an uninitialised variable as well.

The 'gdm' and '_gdm' would need swapping over.
But, as you said, just:
#define GDM_TTY_READY(gdm) ((gdm) && (gdm)->tty_dev && (gdm)->port.count)
is fine - I'd add the () but not worry about multiple evaluation.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  reply	other threads:[~2022-03-31 10:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 10:18 Alaa Mohamed
2022-03-31 10:27 ` Dan Carpenter
2022-03-31 10:29 ` David Laight
2022-03-31 10:40   ` Dan Carpenter
2022-03-31 10:49     ` David Laight [this message]
2022-03-31 11:00       ` Dan Carpenter
2022-03-31 11:33 ` Greg KH

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=acde5b1e8495431dac05403c593d4679@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=dan.carpenter@oracle.com \
    --cc=eng.alaamohamedsoliman.am@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=outreachy@lists.linux.dev \
    /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

Powered by JetHome