Skip to contentSkip to conversation

Drivers: i2c: busses: Use max macro instead of ternary operator

PATCH In review Bhumika Goyal 2 participants 3 messages Sep 10, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Drivers: i2c: busses: Use max macro instead of ternary operator

Replace ternary operators with macro 'max' as it is shorter and thus increases code readability. Macro max returns the maximum of the two compared values.
Done using coccinelle:

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)

---
 drivers/i2c/busses/i2c-jz4780.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-jz4780.c +4 -4
index cd98725..b6c6f90 100644
@@ -133,10 +133,10 @@ static const char * const jz4780_i2c_abrt_src[] = {
 
 #define JZ4780_I2C_ENB_I2C		BIT(0)
 
-#define JZ4780_I2CSHCNT_ADJUST(n)	(((n) - 8) < 6 ? 6 : ((n) - 8))
-#define JZ4780_I2CSLCNT_ADJUST(n)	(((n) - 1) < 8 ? 8 : ((n) - 1))
-#define JZ4780_I2CFHCNT_ADJUST(n)	(((n) - 8) < 6 ? 6 : ((n) - 8))
-#define JZ4780_I2CFLCNT_ADJUST(n)	(((n) - 1) < 8 ? 8 : ((n) - 1))
+#define JZ4780_I2CSHCNT_ADJUST(n)	(max(6, (n) - 8))
+#define JZ4780_I2CSLCNT_ADJUST(n)	(max(8, (n) - 1))
+#define JZ4780_I2CFHCNT_ADJUST(n)	(max(6, (n) - 8))
+#define JZ4780_I2CFLCNT_ADJUST(n)	(max(8, (n) - 1))
 
 #define JZ4780_I2C_FIFO_LEN	16
 #define TX_LEVEL		3
Signature · 1 line
1.9.1
#1 lore raw
Quoted 5 lines · Bhumika Goyal

Replace ternary operators with macro 'max' as it is shorter and thus increases code readability. Macro max returns the maximum of the two compared values.
Done using coccinelle:

Quoted 11 lines

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
- x > y ? x : y
+ max(x,y)
)

Hello.

Please make sure to inspect and if appropriate modify the coccinelle output for the 'best' coding style, for whatever definition of 'best' you might use, before submitting automatically produced patches.

drivers/i2c/busses/i2c-jz4780.c

Quoted 1 line
drivers/i2c/busses/i2c-jz4780.c +0 -0

[]

drivers/i2c/busses/i2c-jz4780.c static const char * const jz4780_i2c_abrt_src[] = { · line 139

Quoted 12 lines
drivers/i2c/busses/i2c-jz4780.c +0 -0
@@ -133,10 +133,10 @@ static const char * const jz4780_i2c_abrt_src[] = {


 #define JZ4780_I2C_ENB_I2C BIT(0)

drivers/i2c/busses/i2c-jz4780.c +4 -4
-#define JZ4780_I2CSHCNT_ADJUST(n)	(((n) - 8) < 6 ? 6 : ((n) - 8))
-#define JZ4780_I2CSLCNT_ADJUST(n)	(((n) - 1) < 8 ? 8 : ((n) - 1))
-#define JZ4780_I2CFHCNT_ADJUST(n)	(((n) - 8) < 6 ? 6 : ((n) - 8))
-#define JZ4780_I2CFLCNT_ADJUST(n)	(((n) - 1) < 8 ? 8 : ((n) - 1))
+#define JZ4780_I2CSHCNT_ADJUST(n)	(max(6, (n) - 8))
+#define JZ4780_I2CSLCNT_ADJUST(n)	(max(8, (n) - 1))
+#define JZ4780_I2CFHCNT_ADJUST(n)	(max(6, (n) - 8))
+#define JZ4780_I2CFLCNT_ADJUST(n)	(max(8, (n) - 1))

For instance: the parentheses are unnecessary and could be removed like the BIT macro above.

Quoted 1 line
#2 lore raw
Quoted 30 lines · Joe Perches
Quoted 5 lines · Bhumika Goyal

Replace ternary operators with macro 'max' as it is shorter and thus increases code readability. Macro max returns the maximum of the two compared values.
Done using coccinelle:

Quoted 11 lines

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
- x > y ? x : y
+ max(x,y)
)

Hello.

Please make sure to inspect and if appropriate modify the coccinelle output for the 'best' coding style, for whatever definition of 'best' you might use, before submitting automatically produced patches.

drivers/i2c/busses/i2c-jz4780.c

Quoted 1 line
drivers/i2c/busses/i2c-jz4780.c +0 -0

[]

Quoted 4 lines
drivers/i2c/busses/i2c-jz4780.c +0 -0
@@ -133,10 +133,10 @@ static const char * const jz4780_i2c_abrt_src[] = {
 
 #define JZ4780_I2C_ENB_I2C            BIT(0)
 
Quoted 11 lines

drivers/i2c/busses/i2c-jz4780.c static const char * const jz4780_i2c_abrt_src[] = { · line 139

Quoted 8 lines
drivers/i2c/busses/i2c-jz4780.c +4 -4
-#define JZ4780_I2CSHCNT_ADJUST(n)    (((n) - 8) < 6 ? 6 : ((n) - 8))
-#define JZ4780_I2CSLCNT_ADJUST(n)    (((n) - 1) < 8 ? 8 : ((n) - 1))
-#define JZ4780_I2CFHCNT_ADJUST(n)    (((n) - 8) < 6 ? 6 : ((n) - 8))
-#define JZ4780_I2CFLCNT_ADJUST(n)    (((n) - 1) < 8 ? 8 : ((n) - 1))
+#define JZ4780_I2CSHCNT_ADJUST(n)    (max(6, (n) - 8))
+#define JZ4780_I2CSLCNT_ADJUST(n)    (max(8, (n) - 1))
+#define JZ4780_I2CFHCNT_ADJUST(n)    (max(6, (n) - 8))
+#define JZ4780_I2CFLCNT_ADJUST(n)    (max(8, (n) - 1))

For instance: the parentheses are unnecessary and could be removed like the BIT macro above.

Thanks for pointing it out. I will resend the patch.

Thanks,
Bhumika

Quoted 1 line
Quoted 1 line