lkml.org 
[lkml]   [2015]   [Nov]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 1/2] comedi: dmm32at: Fix coding style - use BIT macro
From
Date
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/ )=-


\
 
 \ /
  Last update: 2015-11-18 18:21    [W:0.037 / U:60.644 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site