lkml.org 
[lkml]   [2014]   [Mar]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] thermal: Fix KELVIN_TO_CELSIUS macro
On 03/23/2014 09:25 PM, Joe Perches wrote:
> On Sun, 2014-03-23 at 21:14 -0700, Guenter Roeck wrote:
>> It is always a good idea to use paranthesis around macro parameters
>> to avoid undesired side effects.
>>
>> In this specific case, KELVIN_TO_CELSIUS() is used in
>> drivers/platform/x86/asus-wmi.c with parameter "value & 0xFFFF",
>> which due to operator evaluation order causes more or less random
>> results.
>
> Maybe it's better to use a statement expression to avoid
> multiple calculations of t
>
> Maybe;
>
> #define KELVIN_TO_CELSIUS(t) \
> ({ \
> long _t = (long)(t) - 2732; \
> _t >= 0 ? (_t + 5) / 10 : (_t - 5) / 10; \
> })
>
>

Possibly, but I only want to have a bug fixed which should possibly be applied
to -stable at some point. As such, I prefer the minimalistic approach.
Anything more fancy on top of that can be submitted as separate patch.

Guenter



\
 
 \ /
  Last update: 2014-03-24 07:21    [W:0.063 / U:1.488 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site