linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Bhumika Goyal <bhumirks@gmail.com>,
	wsa@the-dreams.de, linux-i2c@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Drivers: i2c: busses: Use max macro instead of ternary operator
Date: Sat, 10 Sep 2016 12:21:49 -0700	[thread overview]
Message-ID: <1473535309.19464.5.camel@perches.com> (raw)
In-Reply-To: <1473534490-16592-1-git-send-email-bhumirks@gmail.com>

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.
> 

  reply	other threads:[~2016-09-10 19:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-10 19:08 [PATCH] Drivers: i2c: busses: Use max macro instead of ternary operator Bhumika Goyal
2016-09-10 19:21 ` Joe Perches [this message]
2016-09-10 19:24   ` Bhumika Goyal
  -- strict thread matches above, loose matches on Subject: below --
2016-09-10 18:56 Bhumika Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473535309.19464.5.camel@perches.com \
    --to=joe@perches.com \
    --cc=bhumirks@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).