Received: by 10.223.185.116 with SMTP id b49csp1037598wrg; Fri, 16 Feb 2018 11:15:02 -0800 (PST) X-Google-Smtp-Source: AH8x224HdSLvaCTp/xB8mseSKNXiHFoVxwQ5mnVK8d8bYsw/vu0pfFGNFpumoiOZL6InJcs/4MNy X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr6455272plb.81.1518808502171; Fri, 16 Feb 2018 11:15:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518808502; cv=none; d=google.com; s=arc-20160816; b=NgIHpU3mYXKOn2xw5VLj1INi6lDBDBdYLtKcoNrZ+4hz6y8yx/dliGGFDlMKSVUOsU 8AsTCIfz6kuVrfqh1gXzoLZF+/zKtlMsz1Yodbk/CDrPCeJlZnQ6WNd2KS8qpdfqrYNt m32O6mDyMMfDQ+AbgD3FlpqKlB6aEK7mUccZvuKebIU704IeYWCfBb4gCBd5SWStkUN8 pQW8fsoT6Ker4E2huOsmNDy5qDOOEVrkBzlenjj8rPuPOAjw+lVbhCqNatxRJm3qHc1E mRUZG8hhEKO+GOlMAk/PGJ9Dyt/Eptd6S8dCtgEOluOHQ18DquXzRS0G0J8GZSkzHB7N Dmvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=ROiuK2yyU1f7bJ5VcJFqzmtd58A1+/yEmFkntYii2GU=; b=05AQSVA9doDbLlr+c8/BbHdqrOW/HUL7gyBAH7dyycoRWKcSSaaalOt4Z+mmKy4wXR j6c058ITIcL6fmwJ8wddxQMFV/jc6HbGQ3i2amsYOkWyIdQ0aNLb6g30ICiN7mSEG3Z2 N6TiMr1gJCUGn9M+zSpy6NKX2hYGEcYSzim+Q5XLl4e6/z0LgbP1TeW2c1ZZHDuAYKi5 rdCb6O8P1r+fNemBJBp3lwmbO5pd7eGwMYaKMQYoufCyWqE4cfwAIN0NN5Vnpv6iqQyO j6UgicE6m6j4wlq0A8P35aVde3ZWnyhghXR7xOEAZpd5lcKT+4gdbyTJ5wUhSfTF42Dv ZuZA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si488301pgs.345.2018.02.16.11.14.47; Fri, 16 Feb 2018 11:15:02 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754868AbeBPPYo (ORCPT + 99 others); Fri, 16 Feb 2018 10:24:44 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:53941 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752408AbeBPPYm (ORCPT ); Fri, 16 Feb 2018 10:24:42 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id 387D720725; Fri, 16 Feb 2018 16:24:40 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (242.171.71.37.rev.sfr.net [37.71.171.242]) by mail.free-electrons.com (Postfix) with ESMTPSA id EEF772036B; Fri, 16 Feb 2018 16:24:39 +0100 (CET) Date: Fri, 16 Feb 2018 16:24:40 +0100 From: Alexandre Belloni To: Colin King Cc: Alessandro Zummo , linux-rtc@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][V2] rtc: tx4939: avoid unintended sign extension on a 24 bit shift Message-ID: <20180216152440.GH14177@piout.net> References: <20180215193614.28684-1-colin.king@canonical.com> <20180215204453.GE14177@piout.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180215204453.GE14177@piout.net> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com