On Wed, Nov 13, 2024 at 01:50:41AM +0530, Suraj Sonawane wrote:Hi Mark,
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.