Re: [PATCH] staging: gdm724x: Fix Duplication of Side Effects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 31, 2022 at 10:49:24AM +0000, David Laight wrote:
> 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@xxxxxxxxx>
> > > > ---
> > > >  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.

Oh yeah.  You're right.  But you won't get any variable uninitialized
warnings because int foo = foo; was the traditional way to silence GCC's
uninitialized variable warnings.

Smatch copied the GCC code.  There are some static checkers which might
complain.  Sparse used to have a warning about shadow variables but it
didn't trigger on this code.  Not sure why.

regards,
dan carpenter





[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux