Skip to contentSkip to conversation

Staging: rts5208: Fix Macro argument reuse

PATCH In review Bhanusree Pola 2 participants 3 messages Feb 20, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 Staging: rts5208: Fix Macro argument reuse

Fixes Macro argument reuse issue
typeof is used to avoid possible side effects
Issue found with checkpatch.pl

---
 drivers/staging/rts5208/xd.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/staging/rts5208/xd.h +5 -4
index 98c00f268e56..5e9b3805c33a 100644
@@ -99,11 +99,12 @@
 #define	XD_RW_ADDR			0x01
 #define	XD_ERASE_ADDR			0x02
 
-#define	XD_PAGE_512(xd_card)		\
+#define	XD_PAGE_512(_card)		\
+(typeof(_card) (card) = (_card);	\
 do {					\
-	(xd_card)->block_shift = 5;	\
-	(xd_card)->page_off = 0x1F;	\
-} while (0)
+	(card)->block_shift = 5;	\
+	(card)->page_off = 0x1F;	\
+} while (0))
 
 #define	XD_SET_BAD_NEWBLK(xd_card)	((xd_card)->multi_flag |= 0x01)
 #define	XD_CLR_BAD_NEWBLK(xd_card)	((xd_card)->multi_flag &= ~0x01)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 17 lines · Bhanusree Pola

Fixes Macro argument reuse issue
typeof is used to avoid possible side effects
Issue found with checkpatch.pl

---
 drivers/staging/rts5208/xd.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/staging/rts5208/xd.h +0 -0
index 98c00f268e56..5e9b3805c33a 100644
@@ -99,11 +99,12 @@
 #define	XD_RW_ADDR			0x01
 #define	XD_ERASE_ADDR			0x02
 

drivers/staging/rts5208/xd.h line 107

Quoted 10 lines
drivers/staging/rts5208/xd.h +5 -4
-#define	XD_PAGE_512(xd_card)		\
+#define	XD_PAGE_512(_card)		\
+(typeof(_card) (card) = (_card);	\
 do {					\
-	(xd_card)->block_shift = 5;	\
-	(xd_card)->page_off = 0x1F;	\
-} while (0)
+	(card)->block_shift = 5;	\
+	(card)->page_off = 0x1F;	\
+} while (0))

Is it useful to reuse this macro? Other types may not have the same fields, with the same semantics. On the other hand, I wonder why this is a macro at all, and not an inline function? Likewise for the next two macros. Then you would have proper typed parameters.

I haven't checked on the uses, though. Perhaps there are many closely related types with the same field names and so having a macro is useful.

julia

Quoted 13 lines
drivers/staging/rts5208/xd.h +0 -1
 #define	XD_SET_BAD_NEWBLK(xd_card)	((xd_card)->multi_flag |= 0x01)
 #define	XD_CLR_BAD_NEWBLK(xd_card)	((xd_card)->multi_flag &= ~0x01)
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190220050522.GA19976%40bhanusree-MacBookAir.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
Quoted 22 lines · Julia Lawall
Quoted 17 lines · Bhanusree Pola

Fixes Macro argument reuse issue
typeof is used to avoid possible side effects
Issue found with checkpatch.pl

---
 drivers/staging/rts5208/xd.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/staging/rts5208/xd.h +0 -0
index 98c00f268e56..5e9b3805c33a 100644
@@ -99,11 +99,12 @@
 #define      XD_RW_ADDR                      0x01
 #define      XD_ERASE_ADDR                   0x02
 
Quoted 16 lines

drivers/staging/rts5208/xd.h line 107

Quoted 10 lines
drivers/staging/rts5208/xd.h +5 -4
-#define      XD_PAGE_512(xd_card)            \
+#define      XD_PAGE_512(_card)              \
+(typeof(_card) (card) = (_card);     \
 do {                                 \
-     (xd_card)->block_shift = 5;     \
-     (xd_card)->page_off = 0x1F;     \
-} while (0)
+     (card)->block_shift = 5;        \
+     (card)->page_off = 0x1F;        \
+} while (0))

Is it useful to reuse this macro? Other types may not have the same fields, with the same semantics. On the other hand, I wonder why this is a macro at all, and not an inline function? Likewise for the next two macros. Then you would have proper typed parameters.

Should I change it to inline function or leave it as a macro? Should I also modify for the next two macros?

Quoted 25 lines

I haven't checked on the uses, though. Perhaps there are many closely related types with the same field names and so having a macro is useful.

julia

Quoted 6 lines
drivers/staging/rts5208/xd.h +0 -1
 #define      XD_SET_BAD_NEWBLK(xd_card)      ((xd_card)->multi_flag |= 0x01)
 #define      XD_CLR_BAD_NEWBLK(xd_card)      ((xd_card)->multi_flag &= ~0x01)
--

2.17.1

Quoted 7 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190220050522.GA19976%40bhanusree-MacBookAir.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1902200825590.14914%40hadrien.
For more options, visit https://groups.google.com/d/optout.