All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Staging: gdm724x: tty: Fix macro argument reuse that could cause side-effects.
@ 2018-02-16 22:26 Quytelda Kahja
  2018-02-17 12:17 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Quytelda Kahja @ 2018-02-16 22:26 UTC (permalink / raw)
  To: gregkh, gs051095; +Cc: devel, Quytelda Kahja, linux-kernel

Fix a coding style warning from checkpatch.pl.  Use GNU extensions to create
references to the results of problem macro arguments when they are evaluated so
that they can be used safely multiple times.

Signed-off-by: Quytelda Kahja <quytelda@tamalin.org>
---
 drivers/staging/gdm724x/gdm_tty.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
index fc7682c18f20..73d39fa86d10 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -37,14 +37,22 @@
 
 #define MUX_TX_MAX_SIZE 2048
 
-#define gdm_tty_send(n, d, l, i, c, b) (\
-	n->tty_dev->send_func(n->tty_dev->priv_dev, d, l, i, c, b))
-#define gdm_tty_recv(n, c) (\
-	n->tty_dev->recv_func(n->tty_dev->priv_dev, c))
-#define gdm_tty_send_control(n, r, v, d, l) (\
-	n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
-
-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
+#define gdm_tty_send(n, d, l, i, c, b)					\
+	({ typeof(n) n_ = (n);						\
+		void *priv_dev = n_->tty_dev->priv_dev;			\
+		n_->tty_dev->send_func(priv_dev, d, l, i, c, b); })
+#define gdm_tty_recv(n, c)					\
+	({ typeof(n) n_ = (n);					\
+		void *priv_dev = n_->tty_dev->priv_dev;		\
+		n_->tty_dev->recv_func(priv_dev, c); })
+#define gdm_tty_send_control(n, r, v, d, l)				\
+	({ typeof(n) n_ = (n);						\
+		void *priv_dev = n_->tty_dev->priv_dev;			\
+		n_->tty_dev->send_control(priv_dev, r, v, d, l); })
+
+#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.16.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH] Staging: gdm724x: tty: Fix macro argument reuse that could cause side-effects.
  2018-02-16 22:26 [PATCH] Staging: gdm724x: tty: Fix macro argument reuse that could cause side-effects Quytelda Kahja
@ 2018-02-17 12:17 ` Greg KH
  2018-02-17 21:02   ` Quytelda Kahja
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2018-02-17 12:17 UTC (permalink / raw)
  To: Quytelda Kahja; +Cc: gs051095, devel, linux-kernel

On Fri, Feb 16, 2018 at 02:26:55PM -0800, Quytelda Kahja wrote:
> Fix a coding style warning from checkpatch.pl.  Use GNU extensions to create
> references to the results of problem macro arguments when they are evaluated so
> that they can be used safely multiple times.
> 
> Signed-off-by: Quytelda Kahja <quytelda@tamalin.org>
> ---
>  drivers/staging/gdm724x/gdm_tty.c | 24 ++++++++++++++++--------
>  1 file changed, 16 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
> index fc7682c18f20..73d39fa86d10 100644
> --- a/drivers/staging/gdm724x/gdm_tty.c
> +++ b/drivers/staging/gdm724x/gdm_tty.c
> @@ -37,14 +37,22 @@
>  
>  #define MUX_TX_MAX_SIZE 2048
>  
> -#define gdm_tty_send(n, d, l, i, c, b) (\
> -	n->tty_dev->send_func(n->tty_dev->priv_dev, d, l, i, c, b))
> -#define gdm_tty_recv(n, c) (\
> -	n->tty_dev->recv_func(n->tty_dev->priv_dev, c))
> -#define gdm_tty_send_control(n, r, v, d, l) (\
> -	n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
> -
> -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
> +#define gdm_tty_send(n, d, l, i, c, b)					\
> +	({ typeof(n) n_ = (n);						\
> +		void *priv_dev = n_->tty_dev->priv_dev;			\
> +		n_->tty_dev->send_func(priv_dev, d, l, i, c, b); })
> +#define gdm_tty_recv(n, c)					\
> +	({ typeof(n) n_ = (n);					\
> +		void *priv_dev = n_->tty_dev->priv_dev;		\
> +		n_->tty_dev->recv_func(priv_dev, c); })
> +#define gdm_tty_send_control(n, r, v, d, l)				\
> +	({ typeof(n) n_ = (n);						\
> +		void *priv_dev = n_->tty_dev->priv_dev;			\
> +		n_->tty_dev->send_control(priv_dev, r, v, d, l); })
> +
> +#define GDM_TTY_READY(gdm)						\
> +	({ typeof(gdm) gdm_ = gdm;					\
> +		gdm_ && gdm_->tty_dev && gdm_->port.count; })

Ugh, that's a mess.  How about just replacing the use of these odd
macros with the "real" call instead?  The fact that they are messing
around with the tty_dev call directly is really strange and should be
made a lot more obvious, as that probably needs to be fixed up.

thanks,

greg k-h

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

* Re: [PATCH] Staging: gdm724x: tty: Fix macro argument reuse that could cause side-effects.
  2018-02-17 12:17 ` Greg KH
@ 2018-02-17 21:02   ` Quytelda Kahja
  0 siblings, 0 replies; 3+ messages in thread
From: Quytelda Kahja @ 2018-02-17 21:02 UTC (permalink / raw)
  To: Greg KH; +Cc: gs051095, devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2805 bytes --]

Greg,

Do you mean that the code should make the tty_dev calls explicitly where
these macros are currently used, or maybe replacing them with "real"
functions?

Thanks,
Quytelda Kahja

On Sat, Feb 17, 2018 at 4:17 AM, Greg KH <gregkh@linuxfoundation.org> wrote:

> On Fri, Feb 16, 2018 at 02:26:55PM -0800, Quytelda Kahja wrote:
> > Fix a coding style warning from checkpatch.pl.  Use GNU extensions to
> create
> > references to the results of problem macro arguments when they are
> evaluated so
> > that they can be used safely multiple times.
> >
> > Signed-off-by: Quytelda Kahja <quytelda@tamalin.org>
> > ---
> >  drivers/staging/gdm724x/gdm_tty.c | 24 ++++++++++++++++--------
> >  1 file changed, 16 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/staging/gdm724x/gdm_tty.c
> b/drivers/staging/gdm724x/gdm_tty.c
> > index fc7682c18f20..73d39fa86d10 100644
> > --- a/drivers/staging/gdm724x/gdm_tty.c
> > +++ b/drivers/staging/gdm724x/gdm_tty.c
> > @@ -37,14 +37,22 @@
> >
> >  #define MUX_TX_MAX_SIZE 2048
> >
> > -#define gdm_tty_send(n, d, l, i, c, b) (\
> > -     n->tty_dev->send_func(n->tty_dev->priv_dev, d, l, i, c, b))
> > -#define gdm_tty_recv(n, c) (\
> > -     n->tty_dev->recv_func(n->tty_dev->priv_dev, c))
> > -#define gdm_tty_send_control(n, r, v, d, l) (\
> > -     n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
> > -
> > -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
> > +#define gdm_tty_send(n, d, l, i, c, b)
>      \
> > +     ({ typeof(n) n_ = (n);                                          \
> > +             void *priv_dev = n_->tty_dev->priv_dev;                 \
> > +             n_->tty_dev->send_func(priv_dev, d, l, i, c, b); })
> > +#define gdm_tty_recv(n, c)                                   \
> > +     ({ typeof(n) n_ = (n);                                  \
> > +             void *priv_dev = n_->tty_dev->priv_dev;         \
> > +             n_->tty_dev->recv_func(priv_dev, c); })
> > +#define gdm_tty_send_control(n, r, v, d, l)                          \
> > +     ({ typeof(n) n_ = (n);                                          \
> > +             void *priv_dev = n_->tty_dev->priv_dev;                 \
> > +             n_->tty_dev->send_control(priv_dev, r, v, d, l); })
> > +
> > +#define GDM_TTY_READY(gdm)                                           \
> > +     ({ typeof(gdm) gdm_ = gdm;                                      \
> > +             gdm_ && gdm_->tty_dev && gdm_->port.count; })
>
> Ugh, that's a mess.  How about just replacing the use of these odd
> macros with the "real" call instead?  The fact that they are messing
> around with the tty_dev call directly is really strange and should be
> made a lot more obvious, as that probably needs to be fixed up.
>
> thanks,
>
> greg k-h
>

[-- Attachment #2: Type: text/html, Size: 4075 bytes --]

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

end of thread, other threads:[~2018-02-17 21:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-16 22:26 [PATCH] Staging: gdm724x: tty: Fix macro argument reuse that could cause side-effects Quytelda Kahja
2018-02-17 12:17 ` Greg KH
2018-02-17 21:02   ` Quytelda Kahja

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.