From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756189AbdLVMig (ORCPT ); Fri, 22 Dec 2017 07:38:36 -0500 Received: from mga05.intel.com ([192.55.52.43]:5711 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755816AbdLVMib (ORCPT ); Fri, 22 Dec 2017 07:38:31 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,441,1508828400"; d="scan'208";a="14828838" Date: Fri, 22 Dec 2017 18:12:26 +0530 From: Vinod Koul To: Colin King Cc: Sanyog Kale , alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] soundwire: fix sign extension when shifting buf[2] 24 places Message-ID: <20171222124226.GW18649@localhost> References: <20171221235113.9274-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171221235113.9274-1-colin.king@canonical.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 21, 2017 at 11:51:13PM +0000, Colin King wrote: > From: Colin Ian King > > The buf[2] left shift by 24 bits is promoted to int (32 bit signed) > and then signed-extended to unsigned long long. Hence if the upper > bit to buf[2] is set then all the upper bits of addr end up as 1. > Fix this by casting it to u64 before shifting it. Also replace the > unsigned long long casts to u64 casts to match the same type of > addr. Applied, thanks > > Detected by CoverityScan, CID#1463147 ("Unintended sign extension") > > Fixes: d52d7a1be02c ("soundwire: Add Slave status handling helpers") > Signed-off-by: Colin Ian King > --- > drivers/soundwire/bus.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c > index 4c345197eb55..7211ecc62015 100644 > --- a/drivers/soundwire/bus.c > +++ b/drivers/soundwire/bus.c > @@ -522,8 +522,8 @@ static int sdw_program_device_num(struct sdw_bus *bus) > * bits to avoid truncation due to size limit. > */ > addr = buf[5] | (buf[4] << 8) | (buf[3] << 16) | > - (buf[2] << 24) | ((unsigned long long)buf[1] << 32) | > - ((unsigned long long)buf[0] << 40); > + ((u64)buf[2] << 24) | ((u64)buf[1] << 32) | > + ((u64)buf[0] << 40); > > sdw_extract_slave_id(bus, addr, &id); > > -- > 2.14.1 > -- ~Vinod