From: Suraj Sonawane <surajsonawane0215@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] regulator: aat2870-regulator: replace division condition with direct comparison
Date: Thu, 14 Nov 2024 14:24:01 +0530 [thread overview]
Message-ID: <4743eb0a-6ba3-4daf-a448-829931dc297f@gmail.com> (raw)
In-Reply-To: <ZzSsCoYy-Cs7d_Q7@finisterre.sirena.org.uk>
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
prev parent reply other threads:[~2024-11-14 8:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 20:20 Suraj Sonawane
2024-11-13 13:39 ` Mark Brown
2024-11-14 8:54 ` Suraj Sonawane [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=4743eb0a-6ba3-4daf-a448-829931dc297f@gmail.com \
--to=surajsonawane0215@gmail.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®