Staging: gdm724x: tty: Fix macro argument reuse that could cause side-effects.
PATCH 1/1 Staging: gdm724x: tty: Fix macro argument reuse that could cause side-effects.
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.
--- drivers/staging/gdm724x/gdm_tty.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
drivers/staging/gdm724x/gdm_tty.c +16 -8
@@ -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 ];
Signature · 6 lines
2.16.1 _______________________________________________ devel mailing list [email protected] http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Greg KH
maintainerQuoted 31 lines · Quytelda Kahja
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 <[email protected]>--- drivers/staging/gdm724x/gdm_tty.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)drivers/staging/gdm724x/gdm_tty.c +6
-8@@ -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); \
drivers/staging/gdm724x/gdm_tty.c line 55
Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.c +10
-0+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
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
Quoted 56 lines · Greg KH
Quoted 1 line · Quytelda Kahja
Fix a coding style warning from checkpatch.pl. Use GNU extensions to
create
Quoted 1 line
references to the results of problem macro arguments when they are
evaluated so
Review
Quoted 8 lines
that they can be used safely multiple times.
Signed-off-by Quytelda Kahja <[email protected]>--- drivers/staging/gdm724x/gdm_tty.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)(quoted diff) +0
-0
b/drivers/staging/gdm724x/gdm_tty.cQuoted 6 lines
index
fc7682c18f20..73d39fa86d10100644drivers/staging/gdm724x/gdm_tty.c +0
-0@@ -37,14 +37,22 @@#define MUX_TX_MAX_SIZE 2048drivers/staging/gdm724x/gdm_tty.c line 40
Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.c +1
-8-#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)\Quoted 5 lines
drivers/staging/gdm724x/gdm_tty.c +5
-0+ ({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); \drivers/staging/gdm724x/gdm_tty.c line 55
Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.c +10
-0+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_devcall directly is really strange and should be made a lot more obvious, as that probably needs to be fixed up.thanks,
greg k-h