Skip to contentSkip to conversation

Staging: iio: adc: ad7280a.c: Fixed Macro argument reuse

PATCH Superseded Jaya Durga 2 participants 2 messages Jul 18, 2017

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jaya Durga

author
#0 lore raw

PATCH 3/3 Staging: iio: adc: ad7280a.c: Fixed Macro argument reuse

CHECK: Macro argument reuse 'addr' - possible side-effects?

convert AD7280A_DEVADDR to inline function to fix checkpath check

---
 drivers/staging/iio/adc/ad7280a.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/staging/iio/adc/ad7280a.c +6 -3
index d5ab83f..cb94b7f 100644
@@ -99,9 +99,12 @@
 #define AD7280A_DEVADDR_MASTER		0
 #define AD7280A_DEVADDR_ALL		0x1F
 /* 5-bit device address is sent LSB first */
-#define AD7280A_DEVADDR(addr)	(((addr & 0x1) << 4) | ((addr & 0x2) << 3) | \
-				(addr & 0x4) | ((addr & 0x8) >> 3) | \
-				((addr & 0x10) >> 4))
+static inline unsigned int AD7280A_DEVADDR(unsigned int addr)
+{
+	return ((((addr & 0x1) << 4) | ((addr & 0x2) << 3) |
+		  (addr & 0x4) | ((addr & 0x8) >> 3) |
+		  ((addr & 0x10) >> 4)));
+}
 
 /* During a read a valid write is mandatory.
  * So writing to the highest available address (Address 0x1F)
Signature · 1 line
1.9.1
#1 lore raw

drivers/staging/iio/adc/ad7280a.c line 102

Quoted 12 lines · Jaya Durga
drivers/staging/iio/adc/ad7280a.c +1 -3
index d5ab83f..cb94b7f 100644
@@ -99,9 +99,12 @@
 #define AD7280A_DEVADDR_MASTER		0
 #define AD7280A_DEVADDR_ALL		0x1F
 /* 5-bit device address is sent LSB first */
-#define AD7280A_DEVADDR(addr)	(((addr & 0x1) << 4) | ((addr & 0x2) << 3) | \
-				(addr & 0x4) | ((addr & 0x8) >> 3) | \
-				((addr & 0x10) >> 4))
+static inline unsigned int AD7280A_DEVADDR(unsigned int addr)

Don't make this inline. GCC is going to ignore the inline anyway, and make up its own mind about what to do. Change the name to not be all caps. Generally, all caps means it's a macro.

drivers/staging/iio/adc/ad7280a.c line 106

Quoted 4 lines
drivers/staging/iio/adc/ad7280a.c +4 -0
+{
+	return ((((addr & 0x1) << 4) | ((addr & 0x2) << 3) |
+		  (addr & 0x4) | ((addr & 0x8) >> 3) |
+		  ((addr & 0x10) >> 4)));

We don't need all the parens.

	return ((addr & 0x1) << 4) |
	       ((addr & 0x2) << 3) |
		(addr & 0x4)       |
	       ((addr & 0x8) >> 3) |
	       ((addr & 0x10) >> 4);

regards,
dan carpenter