Skip to contentSkip to conversation

drivers: staging: comedi: Fixed side effects from macro definition.

PATCH In review chakravarthikulkarni 3 participants 3 messages Feb 17, 2021 – Feb 24, 2021 1 message not in the archive Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: staging: comedi: Fixed side effects from macro definition.

Warning found by checkpatch.pl script.

---
 drivers/staging/comedi/comedi.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/staging/comedi/comedi.h +6 -3
index b5d00a006dbb..b2af6a88d389 100644
@@ -1103,9 +1103,12 @@ enum ni_common_signal_names {
 
 /* *** END GLOBALLY-NAMED NI TERMINALS/SIGNALS *** */
 
-#define NI_USUAL_PFI_SELECT(x)	(((x) < 10) ? (0x1 + (x)) : (0xb + (x)))
-#define NI_USUAL_RTSI_SELECT(x)	(((x) < 7) ? (0xb + (x)) : 0x1b)
-
+#define NI_USUAL_PFI_SELECT(x) \
+	({ typeof(x) _x = x; \
+	 (((_x) < 10) ? (0x1 + (_x)) : (0xb + (_x))); })
+#define NI_USUAL_RTSI_SELECT(x)	\
+	({ typeof(x) _x = x; \
+	 (((_x) < 7) ? (0xb + (_x)) : 0x1b); })
 /*
  * mode bits for NI general-purpose counters, set with
  * INSN_CONFIG_SET_COUNTER_MODE
Signature · 1 line
2.17.1
#1 lore raw
Quoted 18 lines · chakravarthikulkarni

Warning found by checkpatch.pl script.

---
  drivers/staging/comedi/comedi.h | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
drivers/staging/comedi/comedi.h +0 -2
index b5d00a006dbb..b2af6a88d389 100644
@@ -1103,9 +1103,12 @@ enum ni_common_signal_names {
 
  /* *** END GLOBALLY-NAMED NI TERMINALS/SIGNALS *** */
 
-#define NI_USUAL_PFI_SELECT(x)	(((x) < 10) ? (0x1 + (x)) : (0xb + (x)))
-#define NI_USUAL_RTSI_SELECT(x)	(((x) < 7) ? (0xb + (x)) : 0x1b)

drivers/staging/comedi/comedi.h enum ni_common_signal_names { · line 1114

Quoted 10 lines
drivers/staging/comedi/comedi.h +6 -1
-
+#define NI_USUAL_PFI_SELECT(x) \
+	({ typeof(x) _x = x; \
+	 (((_x) < 10) ? (0x1 + (_x)) : (0xb + (_x))); })
+#define NI_USUAL_RTSI_SELECT(x)	\
+	({ typeof(x) _x = x; \
+	 (((_x) < 7) ? (0xb + (_x)) : 0x1b); })
  /*
   * mode bits for NI general-purpose counters, set with
   * INSN_CONFIG_SET_COUNTER_MODE

I'd rather not do that because this is intended to be a userspace header. This change adds GCC extensions and prohibits the use of the macros in constant expressions.

Signature · 4 lines
-=( Ian Abbott <[email protected]> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

A message that is not in the archive (sent off-list or not yet received): CAEwrQWZEXYJDsTDiOAZLOr5jLXXyuZamwqRMquCyBdYPa8anow@mail.gmail.com

#3 lore raw

A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

Quoted 8 lines · chakravarthi Kulkarni

Hi,

I tested it will unit test cases it looks fine.
int x = 10;
NI_USUAL_PFI_SELECT(x++)

will not have side effects as it is taken care using local variable in macro.

You ignored what Ian said about why this change was not ok :(

It's long deleted from my review queue, sorry.

greg k-h