* [PATCH] Drivers: i2c: busses: Use max macro instead of ternary operator
@ 2016-09-10 18:56 Bhumika Goyal
0 siblings, 0 replies; 4+ messages in thread
From: Bhumika Goyal @ 2016-09-10 18:56 UTC (permalink / raw)
To: wsa, linux-i2c; +Cc: 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:
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)
Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
drivers/i2c/busses/i2c-jz4780.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index cd98725..b6c6f90 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -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
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] Drivers: i2c: busses: Use max macro instead of ternary operator
@ 2016-09-10 19:08 Bhumika Goyal
2016-09-10 19:21 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Bhumika Goyal @ 2016-09-10 19:08 UTC (permalink / raw)
To: wsa, linux-i2c, linux-kernel; +Cc: 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:
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)
Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
drivers/i2c/busses/i2c-jz4780.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index cd98725..b6c6f90 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -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
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Drivers: i2c: busses: Use max macro instead of ternary operator
2016-09-10 19:08 Bhumika Goyal
@ 2016-09-10 19:21 ` Joe Perches
2016-09-10 19:24 ` Bhumika Goyal
0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2016-09-10 19:21 UTC (permalink / raw)
To: Bhumika Goyal, wsa, linux-i2c, linux-kernel
On Sun, 2016-09-11 at 00:38 +0530, Bhumika Goyal wrote:
> 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)
> )
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.
> diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
[]
> @@ -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))
For instance: the parentheses are unnecessary and could be removed
like the BIT macro above.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Drivers: i2c: busses: Use max macro instead of ternary operator
2016-09-10 19:21 ` Joe Perches
@ 2016-09-10 19:24 ` Bhumika Goyal
0 siblings, 0 replies; 4+ messages in thread
From: Bhumika Goyal @ 2016-09-10 19:24 UTC (permalink / raw)
To: Joe Perches; +Cc: wsa, linux-i2c, linux-kernel
On Sun, Sep 11, 2016 at 12:51 AM, Joe Perches <joe@perches.com> wrote:
> On Sun, 2016-09-11 at 00:38 +0530, Bhumika Goyal wrote:
>> 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)
>> )
>
> 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.
>
>> diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
> []
>> @@ -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))
>
> 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
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-10 19:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-10 18:56 [PATCH] Drivers: i2c: busses: Use max macro instead of ternary operator Bhumika Goyal
-- strict thread matches above, loose matches on Subject: below --
2016-09-10 19:08 Bhumika Goyal
2016-09-10 19:21 ` Joe Perches
2016-09-10 19:24 ` Bhumika Goyal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).