lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZzSsCoYy-Cs7d_Q7@finisterre.sirena.org.uk>
Date: Wed, 13 Nov 2024 13:39:22 +0000
From: Mark Brown <broonie@...nel.org>
To: Suraj Sonawane <surajsonawane0215@...il.com>
Cc: Liam Girdwood <lgirdwood@...il.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] regulator: aat2870-regulator: replace division condition
 with direct comparison

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.

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ