public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: Hartley Sweeten <HartleyS@visionengravers.com>,
	Ranjith Thangavel <ranjithece24@gmail.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] comedi: dmm32at: Fix coding style - use BIT macro
Date: Wed, 18 Nov 2015 17:02:50 +0000	[thread overview]
Message-ID: <564CAF3A.20507@mev.co.uk> (raw)
In-Reply-To: <BN3PR0101MB1057EE70E83A679918C4F8D6D01C0@BN3PR0101MB1057.prod.exchangelabs.com>

On 18/11/15 16:45, Hartley Sweeten wrote:
> On Wednesday, November 18, 2015 9:42 AM, Ian Abbott wrote:
>> On 16/11/15 17:18, Ranjith Thangavel wrote:
>   [snip]
>>> -#define DMM32AT_AI_CFG_SCINT_20US	(0 << 4)
>>> -#define DMM32AT_AI_CFG_SCINT_15US	(1 << 4)
>>> -#define DMM32AT_AI_CFG_SCINT_10US	(2 << 4)
>>> -#define DMM32AT_AI_CFG_SCINT_5US	(3 << 4)
>>> -#define DMM32AT_AI_CFG_RANGE		(1 << 3)  /* 0=5V  1=10V */
>>> -#define DMM32AT_AI_CFG_ADBU		(1 << 2)  /* 0=bipolar  1=unipolar */
>>> +#define DMM32AT_AI_CFG_SCINT_20US	0
>>> +#define DMM32AT_AI_CFG_SCINT_15US	BIT(4)
>>> +#define DMM32AT_AI_CFG_SCINT_10US	(BIT(5) & ~BIT(4))
>>
>> The `(BIT(5) & ~BIT(4))` is a bit ugly.  You can just use `BIT(5)` to
>> fit in with the style of your other changes.
>>
>>   (Personally though, I don't think BIT() is appropriate for shifted,
>> multi-bit values.)
>
> It would be more appropriate as a macro:
>
> #define DMM32AT_AI_CFG_SCINT(x)		(((x) & 0x3) << 4)
> #define DMM32AT_AI_CFG_SCINT_20US	DMM32AT_AI_CFG_SCINT (0)
> #define DMM32AT_AI_CFG_SCINT_15US	DMM32AT_AI_CFG_SCINT (1)
> #define DMM32AT_AI_CFG_SCINT_10US	DMM32AT_AI_CFG_SCINT (2)
> #define DMM32AT_AI_CFG_SCINT_5US	DMM32AT_AI_CFG_SCINT (3)

Yes, but without the spaces in the macro calls!

It's slightly surprising no one has pushed a generic macro for this sort 
of thing, maybe something like:

#define MBIT(v, s)	((v) * BIT(s))

although the name sucks - maybe the problem is thinking up a decent name!

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-

      reply	other threads:[~2015-11-18 17:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 17:18 [PATCH 1/2] comedi: dmm32at: Fix coding style - use BIT macro Ranjith Thangavel
2015-11-16 17:18 ` [PATCH 2/2] " Ranjith Thangavel
2015-11-17 16:26   ` Sudip Mukherjee
2015-11-17 16:24 ` [PATCH 1/2] " Sudip Mukherjee
2015-11-18 16:41 ` Ian Abbott
2015-11-18 16:45   ` Hartley Sweeten
2015-11-18 17:02     ` Ian Abbott [this message]

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=564CAF3A.20507@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=HartleyS@visionengravers.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ranjithece24@gmail.com \
    /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