From patchwork Mon Aug 20 00:00:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 959473 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jAYZ/+Qk"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41tvQ45N9Nz9s4v for ; Mon, 20 Aug 2018 10:12:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 69E7DC21DB5; Mon, 20 Aug 2018 00:09:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, KHOP_BIG_TO_CC, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EADC6C21E02; Mon, 20 Aug 2018 00:07:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BF284C21C93; Mon, 20 Aug 2018 00:04:51 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by lists.denx.de (Postfix) with ESMTPS id 5C63DC21C2C for ; Mon, 20 Aug 2018 00:04:51 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id s12-v6so12487437wmc.0 for ; Sun, 19 Aug 2018 17:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+csizhtJ4rnXm7RM/d5+39S6hTFtX76pg68PIqKIMg4=; b=jAYZ/+QkYfBLnm02v1GJUy2lO986CBtG6pZuGpVSQ1EhQCx5YO7bf1aHZWDf5kfuY2 dJKZfBSNh38Xs5nUlohdyRfmo90NLacVZHlWDBSspwmNbdnZjIeiT5YTExgKnWpfmkEk v/caQAkxcjBxEkmu+a+3sRhRym2XTfN4RmtXvfvGj563UO4q3cUptxHf4NVZnQ3a8Iva lXfDf3HTDP7oQUxXDNVRQZoZ5YelFUmWdF2Tuo+mC7DAOMy+G8dP1FZfC+6dJ2nvKprb Vt7uWV/wQFSpdbE+fBdwTLwavU4m4c40TMepwvjVsIDh4OEdYaVHeCFkgoTUv/f3om5W aWbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+csizhtJ4rnXm7RM/d5+39S6hTFtX76pg68PIqKIMg4=; b=FNhzQHdiiPw+ewPto2b9j5zHfT6WdTXhi2CCPwLNj+690SKSjrBteHWgTUkopv9vVV oYrBtdcXZvUBamiFz+Ixzy6DV2FxI+1Q8eSzMrNqXj7VNg21I8tq7vgX57nMhHvuXHQT jAuhVi7TLFcEFDjLDafIYCVMFf/qUFzjiqOMCakbPsi0xy9grUm5KulNuJvSmemXbMiw 5cnzsSNqtfNCTWTtrdD26WOmp0sBx3MvqKrmSyRFVq+GiSBWEDYV/V5bhukEEvQRzAYz NOkQSX54yV4DiRtfB/nem5Oi4UWe2SbKzTFcz+sM83HEK+9lNV6JceIUKCayisl5tFLU VIkQ== X-Gm-Message-State: AOUpUlEFXkdkg1GXg7pQhv34zxJOWnWzbFadN4gvY3GPfniiwDWTJ8iV WNvluxtojNvs8u13+fU4kKc= X-Google-Smtp-Source: AA+uWPyQ+aYqQDlgm/aGlEGaYjbgWsCmLDhFmmvZlDUJoIsV88VVUHrwIeKPzgdy9e4TeWEsgv5rnQ== X-Received: by 2002:a1c:4b0c:: with SMTP id y12-v6mr22346287wma.22.1534723491090; Sun, 19 Aug 2018 17:04:51 -0700 (PDT) Received: from localhost.localdomain (ipb218f552.dynamic.kabel-deutschland.de. [178.24.245.82]) by smtp.gmail.com with ESMTPSA id w4-v6sm7648194wro.24.2018.08.19.17.04.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 19 Aug 2018 17:04:50 -0700 (PDT) From: Eugeniu Rosca X-Google-Original-From: Eugeniu Rosca To: Tom Rini , Simon Glass , Masahiro Yamada , Andrey Ryabinin , Andre Przywara , Igor Opaniuk , Rasmus Villemoes , Bryan O'Donoghue , Andy Shevchenko , Chris Packham , Alex Kiernan , Alexey Brodkin , Michal Simek , York Sun , "Derald D . Woods" , Miquel Raynal , Baruch Siach , Albert Aribaud , Stephen Warren , Alexander Graf , Rick Chen , Adam Ford , Simon Goldschmidt , Pantelis Antoniou , Marek Vasut , Takeshi Kihara , Bin Meng , Heinrich Schuchardt , Anatolij Gustschin , Jean-Jacques Hiblot , Jaehoon Chung , Peng Fan , Andy Yan , Philipp Tomsich , Nobuhiro Iwamatsu , Mario Six , Grygorii Strashko , Neil Armstrong , Joe Hershberger , Florian Fainelli , Stefan Roese , Zubair Lutfullah Kakakhel , Quentin Schulz Date: Mon, 20 Aug 2018 02:00:29 +0200 Message-Id: <20180820000033.25519-6-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180820000033.25519-1-erosca@de.adit-jv.com> References: <20180820000033.25519-1-erosca@de.adit-jv.com> X-Mailman-Approved-At: Mon, 20 Aug 2018 00:07:41 +0000 Cc: u-boot@lists.denx.de, Eugeniu Rosca Subject: [U-Boot] [PATCH 5/8] net: phy: Fix "left shift in type int" undefined behavior X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 int, to protect against shifting the numeric literal by a negative value (which would translate into a different type of undefined behavior). Fixes: 1adb406b0141 ("phy: add phy_find_by_mask/phy_connect_dev") Signed-off-by: Eugeniu Rosca --- 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; }