From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eugeniu Rosca Date: Mon, 27 Aug 2018 01:13:23 +0200 Subject: [U-Boot] [PATCH v2 05/13] net: phy: Fix signed shift overflow In-Reply-To: <20180826231332.2491-1-erosca@de.adit-jv.com> References: <20180826231332.2491-1-erosca@de.adit-jv.com> Message-ID: <20180826231332.2491-6-erosca@de.adit-jv.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Booting R-Car Gen3 arm64 U-Boot with CONFIG_UBSAN=y results 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 --- Changes in v2: - Shorten the summary line. Rephrase/rewrap the description. --- drivers/net/phy/phy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index e837eb7688cc..0a8df72a495f 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -719,13 +719,13 @@ static struct phy_device *search_for_existing_phy(struct mii_dev *bus, { /* If we have one, return the existing device, with new interface */ while (phy_mask) { - int addr = ffs(phy_mask) - 1; + unsigned int addr = ffs(phy_mask) - 1; if (bus->phymap[addr]) { bus->phymap[addr]->interface = interface; return bus->phymap[addr]; } - phy_mask &= ~(1 << addr); + phy_mask &= ~(1UL << addr); } return NULL; } -- 2.18.0