Received: by 10.223.185.116 with SMTP id b49csp1038673wrg; Fri, 16 Feb 2018 11:16:05 -0800 (PST) X-Google-Smtp-Source: AH8x227KwwSjM3xnM027OKXX4Hy1DelHVlWS5uvUQ9Aa/ocTzn5OcKYlC5LVbzfYbNAF+WecTDUt X-Received: by 10.167.129.195 with SMTP id c3mr7014914pfn.14.1518808564895; Fri, 16 Feb 2018 11:16:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518808564; cv=none; d=google.com; s=arc-20160816; b=Ss2PQOE0ZxOqKNc8HNnCL2ucoYBaY0XC/NGNa4rOncwVbQ+yRxcne9CuB/oBdfAJjI JCxlnAN/9cdGub1eMWINedvpds880A5JIy3a+RBasay4JgjCeOThd5fHGJ4fsgr3dOQ0 IlE3ijy4lDHXRf0qP46i5U/JVgjMoo7PF33IcLP5rA+/9WSaXsem694C+cMWGXaNpXg6 +VUo9Kxdcs1T6/ztFxMWqKyUD4Yjx/5pJ9n1lbcK4Z9KYO7WDe8tjeGFoVCEHoic3c6y Qy0cWiCO2f4Kdw0kYdQ+W7J9b3dxIPftSes+yoFxY8SsMwh5V8nuePYIT7IB4cojYf0A Ev2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=UXIF8BabAnGUKnADY1nxSSdCwhTWW4vV196t1NScKTQ=; b=Cwfmroi/Z0ojM+YnmyBvMR7E6INwUXCAEdu5uc8VbP/TeMgugAhrxO3yRagRRfrZlA xwAfO745y2sm1LcoWH1AeuCARBvBQ/Fhr95WSsaFFD1xG1e/7qAbpGzkQle9X/x+PWRV Q6IQ/AfEDf9BdW3a1yll8lmBoNakr7xTn76oDwXQ6Hp5nQ31iz0pmMDiOXoxCzxzh1QL CUdb7ky9BDNeMi+uIt6u0aF68FENTtliJNSDP9yK+wa7FbC3BSiw0WX7gdAvdOnt2eIi pRmTVFFaw8Xqdp37BydkKU2PZuKy+GY1G0eBhhchErecTgBbI1I6adlCBV3PeiyCOKqU dP/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id k66si3110430pfa.369.2018.02.16.11.15.50; Fri, 16 Feb 2018 11:16:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1758194AbeBPPa7 (ORCPT + 99 others); Fri, 16 Feb 2018 10:30:59 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:54667 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755453AbeBPP0W (ORCPT ); Fri, 16 Feb 2018 10:26:22 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1emhu1-0001Co-6z; Fri, 16 Feb 2018 15:26:21 +0000 Subject: Re: [PATCH][V2] rtc: tx4939: avoid unintended sign extension on a 24 bit shift To: Alexandre Belloni Cc: Alessandro Zummo , linux-rtc@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180215193614.28684-1-colin.king@canonical.com> <20180215204453.GE14177@piout.net> <20180216152440.GH14177@piout.net> From: Colin Ian King Message-ID: <7ec6aba6-fb27-0982-8874-891528c9535c@canonical.com> Date: Fri, 16 Feb 2018 15:26:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180216152440.GH14177@piout.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/02/18 15:24, Alexandre Belloni wrote: > On 15/02/2018 at 21:44:53 +0100, Alexandre Belloni wrote: >> On 15/02/2018 at 19:36:14 +0000, Colin King wrote: >>> From: Colin Ian King >>> >>> The shifting of buf[5] by 24 bits to the left will be promoted to >>> a 32 bit signed int and then sign-extended to an unsigned long. If >>> the top bit of buf[5] is set then all then all the upper bits sec >>> end up as also being set because of the sign-extension. Fix this by >>> casting buf[5] to an unsigned long before the shift. >>> >> >> The timing of the discovery of this issue is suspicious. I believe it is >> because I just enabled COMPILE_TEST on that driver and now this gets >> compiled on a 64bit architecture. >> >> Can I ask on which architecture this is an issue? I don't think (and a >> small test program confirms) x86 does the sign extension because both >> sec and buf are unsigned. >> > > Actually, my test program was wrong and you are right. > Kudos to CoverityScan static analysis for finding it. It's not obvious for sure Colin