linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: Ray Jui <ray.jui@broadcom.com>, Wolfram Sang <wsa@the-dreams.de>
Cc: "linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"bcm-kernel-feedback-list@broadcom.com"
	<bcm-kernel-feedback-list@broadcom.com>,
	Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
Subject: Re: [PATCH] i2c: iproc: Change driver to use 'BIT' macro
Date: Mon, 15 Apr 2019 06:56:13 +0000	[thread overview]
Message-ID: <c47c6ec2-6d6f-8885-932c-35390783f55b@axentia.se> (raw)
In-Reply-To: <f28f604a-55a4-7542-0e13-a92a83ab2144@axentia.se>

On 2019-04-13 00:59, Peter Rosin wrote:
> On 2019-04-03 23:05, Ray Jui wrote:
>> Change the iProc I2C driver to use the 'BIT' macro from all '1 << XXX'
>> bit operations to get rid of compiler warning and improve readability of
>> the code
> 
> All? I see lots more '1 << XXX_SHIFT' matches. I might be behind though?

I verified that, and yes indeed, I was behind. That said, see below...

> Anyway, if you are cleaning up, I'm just flagging that BIT(XXX_SHIFT) looks
> a bit clunky to me. You might consider renaming all those single-bit
> XXX_SHIFT macros to simple be
> 
> #define XXX BIT(<xxx>)
> 
> instead of
> 
> #define XXX_SHIFT <xxx>
> 
> but that triggers more churn, so is obviously more error prone. You might
> not dare it?
> 
> Cheers,
> Peter
> 
>> Signed-off-by: Ray Jui <ray.jui@broadcom.com>
>> ---
>>  drivers/i2c/busses/i2c-bcm-iproc.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c
>> index 562942d0c05c..a845b8decac8 100644
>> --- a/drivers/i2c/busses/i2c-bcm-iproc.c
>> +++ b/drivers/i2c/busses/i2c-bcm-iproc.c
>> @@ -717,7 +717,7 @@ static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c,
>>  
>>  			/* mark the last byte */
>>  			if (i == msg->len - 1)
>> -				val |= 1 << M_TX_WR_STATUS_SHIFT;
>> +				val |= BIT(M_TX_WR_STATUS_SHIFT);
>>  
>>  			iproc_i2c_wr_reg(iproc_i2c, M_TX_OFFSET, val);
>>  		}
>> @@ -844,7 +844,7 @@ static int bcm_iproc_i2c_cfg_speed(struct bcm_iproc_i2c_dev *iproc_i2c)
>>  
>>  	iproc_i2c->bus_speed = bus_speed;
>>  	val = iproc_i2c_rd_reg(iproc_i2c, TIM_CFG_OFFSET);
>> -	val &= ~(1 << TIM_CFG_MODE_400_SHIFT);
>> +	val &= ~BIT(TIM_CFG_MODE_400_SHIFT);
>>  	val |= (bus_speed == 400000) << TIM_CFG_MODE_400_SHIFT;

These two statements now no longer "match". One uses BIT and the other open
codes the shift. I think that's bad. Losing the _SHIFT suffix and including
BIT in the macro expansion, as suggested above, yields:

	val &= ~TIM_CFG_MODE_400;
	if (bus_speed == 400000)
		val |= TIM_CFG_MODE_400;

which is perhaps one more line, but also more readable IMO.

But all this is of course in deep nit-pick-territory...

Cheers,
Peter

>>  	iproc_i2c_wr_reg(iproc_i2c, TIM_CFG_OFFSET, val);
>>  
>> @@ -995,7 +995,7 @@ static int bcm_iproc_i2c_resume(struct device *dev)
>>  
>>  	/* configure to the desired bus speed */
>>  	val = iproc_i2c_rd_reg(iproc_i2c, TIM_CFG_OFFSET);
>> -	val &= ~(1 << TIM_CFG_MODE_400_SHIFT);
>> +	val &= ~BIT(TIM_CFG_MODE_400_SHIFT);
>>  	val |= (iproc_i2c->bus_speed == 400000) << TIM_CFG_MODE_400_SHIFT;
>>  	iproc_i2c_wr_reg(iproc_i2c, TIM_CFG_OFFSET, val);
>>  
>>
> 


  reply	other threads:[~2019-04-15  6:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-03 21:05 [PATCH] i2c: iproc: Change driver to use 'BIT' macro Ray Jui
2019-04-12 22:59 ` Peter Rosin
2019-04-15  6:56   ` Peter Rosin [this message]
2019-04-17 23:48     ` Ray Jui
2019-04-18  6:21       ` Peter Rosin
2019-04-18 17:25         ` Ray Jui
2019-04-18 21:27           ` Peter Rosin
2019-04-23 21:36 ` Wolfram Sang

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=c47c6ec2-6d6f-8885-932c-35390783f55b@axentia.se \
    --to=peda@axentia.se \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ray.jui@broadcom.com \
    --cc=rayagonda.kokatanur@broadcom.com \
    --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).