[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <4743eb0a-6ba3-4daf-a448-829931dc297f@gmail.com>
Date: Thu, 14 Nov 2024 14:24:01 +0530
From: Suraj Sonawane <surajsonawane0215@...il.com>
To: Mark Brown <broonie@...nel.org>
Cc: Liam Girdwood <lgirdwood@...il.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] regulator: aat2870-regulator: replace division condition
with direct comparison
On 13/11/24 19:09, Mark Brown wrote:
> On Wed, Nov 13, 2024 at 01:50:41AM +0530, Suraj Sonawane wrote:
>> Fix an issue detected by the Smatch tool:
>>
>> drivers/regulator/aat2870-regulator.c:142 aat2870_get_regulator() warn:
>> replace divide condition '(id - 1) / 2' with '(id - 1) >= 2'
>>
>> The division '(id - 1) / 2' was used to check if the regulator ID
>> is greater than or equal to 2, which can be confusing and less
>> readable. Replacing it with '(id - 1) >= 2' makes the code clearer
>
> This is absolute nonsense, the tool should be fixed instead. Writing a
> division as a shift when the intent is a division is a microoptimisation
> which modern compilers really should figure out where it's relevant.
>
>> - ri->voltage_addr = (id - AAT2870_ID_LDOA) / 2 ?
>> + ri->voltage_addr = (id - AAT2870_ID_LDOA) >= 2 ?
>> AAT2870_LDO_CD : AAT2870_LDO_AB;
>
> Neither version of this is particularly readable, but the new form here
> seems fairly clearly worse rather than better.
Hi Mark,
Thank you for your feedback. I see your point about the original code
being clear enough and changing it as suggested making it worse.
Best,
Suraj
Powered by blists - more mailing lists