All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: gdm724x: Fix Duplication of Side Effects
@ 2022-03-31 10:18 Alaa Mohamed
  2022-03-31 10:27 ` Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alaa Mohamed @ 2022-03-31 10:18 UTC (permalink / raw)
  To: outreachy; +Cc: gregkh, linux-staging, linux-kernel, eng.alaamohamedsoliman.am

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); })
 
 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging: gdm724x: Fix Duplication of Side Effects
  2022-03-31 10:18 [PATCH] staging: gdm724x: Fix Duplication of Side Effects Alaa Mohamed
@ 2022-03-31 10:27 ` Dan Carpenter
  2022-03-31 10:29 ` David Laight
  2022-03-31 11:33 ` Greg KH
  2 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2022-03-31 10:27 UTC (permalink / raw)
  To: Alaa Mohamed; +Cc: outreachy, gregkh, linux-staging, linux-kernel

On Thu, Mar 31, 2022 at 12:18:49PM +0200, Alaa Mohamed wrote:
> 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); })

The new macro is uglier.  This is not a real bug and there is very
little chance it will become a bug in the future.  So it's fine to leave
it as is.

Or another option would be to make it an inline function.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH] staging: gdm724x: Fix Duplication of Side Effects
  2022-03-31 10:18 [PATCH] staging: gdm724x: Fix Duplication of Side Effects 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 11:33 ` Greg KH
  2 siblings, 1 reply; 7+ messages in thread
From: David Laight @ 2022-03-31 10:29 UTC (permalink / raw)
  To: 'Alaa Mohamed', outreachy; +Cc: gregkh, linux-staging, linux-kernel

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

	David

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging: gdm724x: Fix Duplication of Side Effects
  2022-03-31 10:29 ` David Laight
@ 2022-03-31 10:40   ` Dan Carpenter
  2022-03-31 10:49     ` David Laight
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2022-03-31 10:40 UTC (permalink / raw)
  To: David Laight
  Cc: 'Alaa Mohamed', outreachy, gregkh, linux-staging, linux-kernel

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.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH] staging: gdm724x: Fix Duplication of Side Effects
  2022-03-31 10:40   ` Dan Carpenter
@ 2022-03-31 10:49     ` David Laight
  2022-03-31 11:00       ` Dan Carpenter
  0 siblings, 1 reply; 7+ messages in thread
From: David Laight @ 2022-03-31 10:49 UTC (permalink / raw)
  To: 'Dan Carpenter'
  Cc: 'Alaa Mohamed', outreachy, gregkh, linux-staging, linux-kernel

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)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging: gdm724x: Fix Duplication of Side Effects
  2022-03-31 10:49     ` David Laight
@ 2022-03-31 11:00       ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2022-03-31 11:00 UTC (permalink / raw)
  To: David Laight
  Cc: 'Alaa Mohamed', outreachy, gregkh, linux-staging, linux-kernel

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@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.

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] staging: gdm724x: Fix Duplication of Side Effects
  2022-03-31 10:18 [PATCH] staging: gdm724x: Fix Duplication of Side Effects Alaa Mohamed
  2022-03-31 10:27 ` Dan Carpenter
  2022-03-31 10:29 ` David Laight
@ 2022-03-31 11:33 ` Greg KH
  2 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2022-03-31 11:33 UTC (permalink / raw)
  To: Alaa Mohamed; +Cc: outreachy, linux-staging, linux-kernel

On Thu, Mar 31, 2022 at 12:18:49PM +0200, Alaa Mohamed wrote:
> Fix Duplication of Side Effects for GDM_TTY_READY(gdm) macro
> reported by checkpatch
> "CHECK: Macro argument reuse 'gdm' - possible side-effects?"

There are no such side-effects here, sorry.  Please always evaluate the
code to see what it does, checkpatch sometimes gets it wrong.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-03-31 11:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-31 10:18 [PATCH] staging: gdm724x: Fix Duplication of Side Effects 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
2022-03-31 11:00       ` Dan Carpenter
2022-03-31 11:33 ` Greg KH

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.