[PATCH 1/1] net: phy: Fix signed shift overflow

Tom Rini trini at konsulko.com
Thu Mar 28 16:09:09 CET 2024


On Thu, Jan 04, 2024 at 05:26:23AM +0100, Heinrich Schuchardt wrote:

> From: Eugeniu Rosca <erosca at de.adit-jv.com>
> 
> Booting R-Car Gen3 arm64 U-Boot with CONFIG_UBSAN=y resulted in:
> 
>  =====================================================================
>  UBSAN: Undefined behaviour in drivers/net/phy/phy.c:728:19
>  left shift of 1 by 31 places cannot be represented in type 'int'
>  =====================================================================
> 
> Fix it by appending the UL suffix to the numeric literal. While at it,
> convert the type of "addr" variable from signed to unsigned, to protect
> against shifting the numeric literal by a negative value (which would
> lead to yet another undefined behavior).
> 
> Fixes: 1adb406b0141 ("phy: add phy_find_by_mask/phy_connect_dev")
> Signed-off-by: Eugeniu Rosca <erosca at de.adit-jv.com>
> 
> * Using U-suffix for integer is sufficient.
> * ffs() of non-zero value cannot be 0. But addr being unsigned is
> * preferable.
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>

Applied to u-boot/next, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20240328/7e749446/attachment.sig>


More information about the U-Boot mailing list