[PATCH 3/4] Staging: ks7010: hostif: Fix multiple use of arguments in rate and event masking macros.

From: Quytelda Kahja
Date: Fri Feb 16 2018 - 21:25:50 EST


Use GCC extensions to prevent macro arguments from accidentally being evaluated
multiple times when the macro is called.

Signed-off-by: Quytelda Kahja <quytelda@xxxxxxxxxxx>
---
drivers/staging/ks7010/ks_hostif.h | 74 +++++++++++++++++++++++++-------------
1 file changed, 50 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.h b/drivers/staging/ks7010/ks_hostif.h
index 5bae8d468e23..750ac86cee77 100644
--- a/drivers/staging/ks7010/ks_hostif.h
+++ b/drivers/staging/ks7010/ks_hostif.h
@@ -599,19 +599,39 @@ struct hostif_mic_failure_confirm_t {
#define TX_RATE_48M (uint8_t)(480 / 5)
#define TX_RATE_54M (uint8_t)(540 / 5)

-#define IS_11B_RATE(A) (((A & RATE_MASK) == TX_RATE_1M) || ((A & RATE_MASK) == TX_RATE_2M) || \
- ((A & RATE_MASK) == TX_RATE_5M) || ((A & RATE_MASK) == TX_RATE_11M))
-
-#define IS_OFDM_RATE(A) (((A & RATE_MASK) == TX_RATE_6M) || ((A & RATE_MASK) == TX_RATE_12M) || \
- ((A & RATE_MASK) == TX_RATE_24M) || ((A & RATE_MASK) == TX_RATE_9M) || \
- ((A & RATE_MASK) == TX_RATE_18M) || ((A & RATE_MASK) == TX_RATE_36M) || \
- ((A & RATE_MASK) == TX_RATE_48M) || ((A & RATE_MASK) == TX_RATE_54M))
-
-#define IS_11BG_RATE(A) (IS_11B_RATE(A) || IS_OFDM_RATE(A))
-
-#define IS_OFDM_EXT_RATE(A) (((A & RATE_MASK) == TX_RATE_9M) || ((A & RATE_MASK) == TX_RATE_18M) || \
- ((A & RATE_MASK) == TX_RATE_36M) || ((A & RATE_MASK) == TX_RATE_48M) || \
- ((A & RATE_MASK) == TX_RATE_54M))
+#define IS_11B_RATE(A) \
+ ({ \
+ typeof(A) A_ = (A); \
+ ((A_ & RATE_MASK) == TX_RATE_1M) || \
+ ((A_ & RATE_MASK) == TX_RATE_2M) || \
+ ((A_ & RATE_MASK) == TX_RATE_5M) || \
+ ((A_ & RATE_MASK) == TX_RATE_11M); })
+
+#define IS_OFDM_RATE(A) \
+ ({ \
+ typeof(A) A_ = (A); \
+ ((A_ & RATE_MASK) == TX_RATE_6M) || \
+ ((A_ & RATE_MASK) == TX_RATE_12M) || \
+ ((A_ & RATE_MASK) == TX_RATE_24M) || \
+ ((A_ & RATE_MASK) == TX_RATE_9M) || \
+ ((A_ & RATE_MASK) == TX_RATE_18M) || \
+ ((A_ & RATE_MASK) == TX_RATE_36M) || \
+ ((A_ & RATE_MASK) == TX_RATE_48M) || \
+ ((A_ & RATE_MASK) == TX_RATE_54M); })
+
+#define IS_11BG_RATE(A) \
+ ({ \
+ typeof(A) A_ = (A); \
+ IS_11B_RATE(A_) || IS_OFDM_RATE(A_); })
+
+#define IS_OFDM_EXT_RATE(A) \
+ ({ \
+ typeof(A) A_ = (A); \
+ ((A_ & RATE_MASK) == TX_RATE_9M) || \
+ ((A_ & RATE_MASK) == TX_RATE_18M) || \
+ ((A_ & RATE_MASK) == TX_RATE_36M) || \
+ ((A_ & RATE_MASK) == TX_RATE_48M) || \
+ ((A_ & RATE_MASK) == TX_RATE_54M); })

enum connect_status_type {
CONNECT_STATUS,
@@ -633,17 +653,23 @@ enum multicast_filter_type {

/* macro function */
#define HIF_EVENT_MASK 0xE800
-#define IS_HIF_IND(_EVENT) ((_EVENT & HIF_EVENT_MASK) == 0xE800 && \
- ((_EVENT & ~HIF_EVENT_MASK) == 0x0001 || \
- (_EVENT & ~HIF_EVENT_MASK) == 0x0006 || \
- (_EVENT & ~HIF_EVENT_MASK) == 0x000C || \
- (_EVENT & ~HIF_EVENT_MASK) == 0x0011 || \
- (_EVENT & ~HIF_EVENT_MASK) == 0x0012))
-
-#define IS_HIF_CONF(_EVENT) ((_EVENT & HIF_EVENT_MASK) == 0xE800 && \
- (_EVENT & ~HIF_EVENT_MASK) > 0x0000 && \
- (_EVENT & ~HIF_EVENT_MASK) < 0x0012 && \
- !IS_HIF_IND(_EVENT))
+#define IS_HIF_IND(_EVENT) \
+ ({ \
+ typeof(_EVENT) EVENT_ = (_EVENT); \
+ (EVENT_ & HIF_EVENT_MASK) == 0xE800 && \
+ ((EVENT_ & ~HIF_EVENT_MASK) == 0x0001 || \
+ (EVENT_ & ~HIF_EVENT_MASK) == 0x0006 || \
+ (EVENT_ & ~HIF_EVENT_MASK) == 0x000C || \
+ (EVENT_ & ~HIF_EVENT_MASK) == 0x0011 || \
+ (EVENT_ & ~HIF_EVENT_MASK) == 0x0012); })
+
+#define IS_HIF_CONF(_EVENT) \
+ ({ \
+ typeof(_EVENT) EVENT_ = (_EVENT); \
+ (EVENT_ & HIF_EVENT_MASK) == 0xE800 && \
+ (EVENT_ & ~HIF_EVENT_MASK) > 0x0000 && \
+ (EVENT_ & ~HIF_EVENT_MASK) < 0x0012 && \
+ !IS_HIF_IND(EVENT_); })

#ifdef __KERNEL__

--
2.16.1