Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3177069pxb; Mon, 9 Nov 2020 04:54:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTU+t6TSpZlsWD1l8LNlIegOPbmfRUzT6oLpJaZTiz4nlmYpqb1VQnh4okv+Ztr2zO6mpj X-Received: by 2002:a05:6402:1765:: with SMTP id da5mr14763178edb.155.1604926446868; Mon, 09 Nov 2020 04:54:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604926446; cv=none; d=google.com; s=arc-20160816; b=XJ6mV7QUQ7Na1AacPNZPUPlzUL14scWF6tjq6vd0wpFGdMwI7TpECHRqqnf6x40iRv ADAuJNhsvNCEsm9kTDpDS6P0WvxmAf9Nc5SYlI5PTkJWNx7qsngxye8E9CdvlpUCBh+A cH2GHg6/bvUfbeSTa4SnmWmX7JnGNW0KPtOZ6KgRMl1R2oYi2tm9Wdb8arUAUN03ebDt VQJy3Th+zIRNLyYGLr1iulyDzquFsw0pJOUP6+nF4iagfcRSzKo36exT8mu1fDEj7BMr 1LZiUX9lfv6HvCOmDt9IVg2TIB8ljUk92YymGjddnI6fPkpgN5NlV59vQIv5lb9BRyf6 gFNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=zwES86N0yJ0dgEGX9ZXoJmJfCl+XMGLkOyAmFYlVn78=; b=tXv1g+y5h7I8J4QFWOIGeW/r8LGolkZM2TfiXxODAhF7VGtylo3HrbFB58CDfJI7Y/ bIrJizPiRqe03xyhCgVhVb/J1GtCFbaVCIaOdMUo3lwisbdPZ/FlmpnfsopTr76AP6mH gU/Qv8Ctahi8WjxjlQSP1V8wJYrkFPWQRECBq6oThlFvG6HgVALsmiKVrOS8gPEg7Ry4 aGDLZzyK5AEYHZXcEcEVqu6mHLMMBm52gsPyWf0QbUsp143lfOp7RfjsqMYXpUqslbbP yTrzDTXR7Y5qXkOdA0rLFOKmGB1fdoXStRoNj7bcJYKDeFKVQUVLVFK9Q1NdeJlVbUyw GmLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SJSUAYLn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si6441021edj.601.2020.11.09.04.53.44; Mon, 09 Nov 2020 04:54:06 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SJSUAYLn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728462AbgKIMwT (ORCPT + 99 others); Mon, 9 Nov 2020 07:52:19 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:51078 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729366AbgKIMv7 (ORCPT ); Mon, 9 Nov 2020 07:51:59 -0500 From: Kurt Kanzenbach DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1604926306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zwES86N0yJ0dgEGX9ZXoJmJfCl+XMGLkOyAmFYlVn78=; b=SJSUAYLne91ofdxwYKpDP/cXIlGLsDnBBfB+R/eBAJLeOtbBne78hIbZbNWueiMJes2OM6 wuB1J9pVZ5QdjSIpZOks+7xTCCcVSIxSLTWYWVu7sEpaSO45/RK/+J7AUqTWAt8Pr2Ekry dQofOxY392Tc96ASX3EUpu+ydoaqqGidcWjHk6SrLQKUK72syPdDTy+9P434k8o4AWRPDT WI/iyXgFsCy+AFKeW/W2tL22iFRaN26DJuWCZJ6EX8jTFigVYeanxXO4Xkpmx3zLthF+T+ W8paKGedu274pQrGpwpS6xG2pAhE3QNVGOD/GhDcCl5nS70dm540usAMddXjsQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1604926306; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zwES86N0yJ0dgEGX9ZXoJmJfCl+XMGLkOyAmFYlVn78=; b=nLbbdC5jNq5ayIWQQ4PdZgzOVEv5Movf8A9/IZhH113Xdnz79wP1JciDk8Q6dmQbZqsx+E O1QWzdv07Y3YNwBg== To: Colin King , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Jakub Kicinski , netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] net: dsa: fix unintended sign extension on a u16 left shift In-Reply-To: <20201109124008.2079873-1-colin.king@canonical.com> References: <20201109124008.2079873-1-colin.king@canonical.com> Date: Mon, 09 Nov 2020 13:51:45 +0100 Message-ID: <877dqusnfi.fsf@kurt> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Mon Nov 09 2020, Colin King wrote: > 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 s= witches") > 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/hir= schmann/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_sw= itch *ds, int port, > const struct hellcreek_counter *counter =3D &hellcreek_counter[i]; > u8 offset =3D counter->offset + port * 64; > u16 high, low; > - u64 value =3D 0; > + u64 value; >=20=20 > mutex_lock(&hellcreek->reg_lock); >=20=20 > @@ -320,7 +320,7 @@ static void hellcreek_get_ethtool_stats(struct dsa_sw= itch *ds, int port, > */ > high =3D hellcreek_read(hellcreek, HR_CRDH); > low =3D hellcreek_read(hellcreek, HR_CRDL); > - value =3D (high << 16) | low; > + value =3D ((u64)high << 16) | low; Looks good to me. Thank you. Thanks, Kurt --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEooWgvezyxHPhdEojeSpbgcuY8KYFAl+pO2EACgkQeSpbgcuY 8KauRhAAkLQ+DCT570ooD5dZAQdphqu8IuvFMDQbsPy92qO9FNA07A5n0P2hbZdq JE2jjD0VUcP+FjhbZ7nz7vPl9vohLZ4P5ZQBX+J25YF+lh0JqJFcH8kSdhobOSdb Cz68+RnbmEA63M82oYGZUwk7ZZ48Ao4oa6v+9snaUZ4onq2iy1ZBcvqpjbTtMCKn CQxH8fGe8D6l0vXUF6Ma/M/RTuOFA7IK7rVVBJ2OyAxzrSj/Q6sJ0RrUsgHztBms iWRWu2Vdq434aR73SxKj8O8pWRusagd0xdNcMu8Le1Zd9dw6CE+MGBGWZiqCyzeY mZF2A6GW4OMKFz6GLhIlSU/MclXMLmYNRKh0AiaccG9A2M8C6R+5sL62BeJU6WPm jEv0DM5fV3dPEA2w7U2bS2CTJVtpwgFutE2q8CsIKpZ1gyRDkSvoGBH5Mjy+l2qA NIi0c9gBCgz6Mx2uyXme6hmciTFd6cCohmjFm7gtX8ZbumqIFhaWNNwFrgFZ/FsB LoxBRM7hZPkGmnnMFrxKpTym+9JcAg5+gvFsa2G6gfAv22fxdi/qKg34npksnWY+ GvOFLwHBJJrenP96uDCNOlogRkOesgdeO9K6R3JqpgEFV0l0kV2q5mZ3bPxT/cIw jw4M68MPiFOfiUudIARjVofFONh/Dn0bpekmSA8HWLTu5Dvj8zY= =DIYK -----END PGP SIGNATURE----- --=-=-=--