Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3170652pxb; Mon, 9 Nov 2020 04:42:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4JZPDoKs0i9B1ECwKKCDL7kH0xvKBoWqy7BgkOcQANYmM8r316XqqRyLq88qhXPiiOUzF X-Received: by 2002:a17:906:d0cc:: with SMTP id bq12mr14467712ejb.127.1604925723025; Mon, 09 Nov 2020 04:42:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604925723; cv=none; d=google.com; s=arc-20160816; b=qic/bsCkbKcwXvbLS9ti3bDDl1+Smtci2vz2JhXRnwAnFseCUXIkJV9eK1t1l1fiVc JGZyQpNVuv3+3xzhGj6f4TnEuB7N5ocZ6cCZ3B1csmxRFaX0Ivqe6lWmJ9/JIDrZR+8J zG0xyS8XENk4R6amuElP25uk0GuwPprPzzKOZI8HwT155kXPG0N3c3JjFeuYce3bKBKj gE24MbkBraaBie+ZNxtaKiZbyP3htGsae32/yqDTe7ZA5EKckJyHEYa0zhPnSYGSwHoI HLMbwQqprVE04DmpV+aKedsg+OMcq6GHLDE7xsKmH8R9C2TIE0TcdJlaVat5CdXFi7iz TXyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=KkYfFKkbabaj9OE/GuiWOITD9OlNQWUeO1XPnzkoSi4=; b=VYeusEylvI16tgymQ62MpgCnmJG1VYTgNh5xn+iL0uq1tLyNDnnvGvTCXGAqwSNYQo RXfk3xyqYNJUDFfHVpjPIsbGoCmXLvBrZPWe/9jTeUcy1AYuR2AiL+DVPWB6ztgXj4Tk j8eM/7kt+vS4gMH+tCHv5JVkLEqsrEK9WBQmta0EKbREniw9YMCtZ37kqp7TiUSJkHuT UredbG9+szpIQeFfqg6N/g6vt1UWVYPI7QRVdM8eFGL/LPD9OeXa9DuwFRt4BeDi0aRt QQ2tT9N7Pg9pbbRwgCdcHfmMTM9tJF2EXbsego2r39TkF7le8aFnqU4Kg+Ie4D2sZ6HK X4Pg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s25si6688469ejv.48.2020.11.09.04.41.40; Mon, 09 Nov 2020 04:42:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729608AbgKIMkO (ORCPT + 99 others); Mon, 9 Nov 2020 07:40:14 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:51131 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726410AbgKIMkO (ORCPT ); Mon, 9 Nov 2020 07:40:14 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kc6Su-0004zh-OY; Mon, 09 Nov 2020 12:40:08 +0000 From: Colin King To: Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Jakub Kicinski , Kurt Kanzenbach , netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] net: dsa: fix unintended sign extension on a u16 left shift Date: Mon, 9 Nov 2020 12:40:08 +0000 Message-Id: <20201109124008.2079873-1-colin.king@canonical.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King The left shift of u16 variable high is promoted to the type int and then sign extended to a 64 bit u64 value. If the top bit of high is set then the upper 32 bits of the result end up being set by the sign extension. Fix this by explicitly casting the value in high to a u64 before left shifting by 16 places. Also, remove the initialisation of variable value to 0 at the start of each loop iteration as the value is never read and hence the assignment it is redundant. Addresses-Coverity: ("Unintended sign extension") Fixes: e4b27ebc780f ("net: dsa: Add DSA driver for Hirschmann Hellcreek switches") Signed-off-by: Colin Ian King --- drivers/net/dsa/hirschmann/hellcreek.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/hirschmann/hellcreek.c b/drivers/net/dsa/hirschmann/hellcreek.c index dfa66f7260d6..d42f40c76ba5 100644 --- a/drivers/net/dsa/hirschmann/hellcreek.c +++ b/drivers/net/dsa/hirschmann/hellcreek.c @@ -308,7 +308,7 @@ static void hellcreek_get_ethtool_stats(struct dsa_switch *ds, int port, const struct hellcreek_counter *counter = &hellcreek_counter[i]; u8 offset = counter->offset + port * 64; u16 high, low; - u64 value = 0; + u64 value; mutex_lock(&hellcreek->reg_lock); @@ -320,7 +320,7 @@ static void hellcreek_get_ethtool_stats(struct dsa_switch *ds, int port, */ high = hellcreek_read(hellcreek, HR_CRDH); low = hellcreek_read(hellcreek, HR_CRDL); - value = (high << 16) | low; + value = ((u64)high << 16) | low; hellcreek_port->counter_values[i] += value; data[i] = hellcreek_port->counter_values[i]; -- 2.28.0