Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4905009pxb; Tue, 28 Sep 2021 06:40:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQuCrqzlzNnOgoNInMW0fO+qQoedZFP0Za1DRG6X1O9gEQC9ZWNfbQKW+FHz/XFqcK/rDS X-Received: by 2002:aa7:c905:: with SMTP id b5mr7790217edt.380.1632836413829; Tue, 28 Sep 2021 06:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632836413; cv=none; d=google.com; s=arc-20160816; b=bGiVV60Xw8Wmbj/6/uCF4T6notpTmatKUxVsl1ZSWsFP3Tdxp6P0cysJBYYIjOKlSN DTnkFCvTrmS21db8xq4EV0vvBbS44nlKl3L/NVVbJeRk7LZjYOKy4FjclHW297pSPji7 BdEaKNgYECyxPkoAX2IQyeaw9eefZdkrh5q2of+TE1nNQ6LoFVF43FILkJWTvKq3pOMG gfHP6G4eu/bJJmwg5Kws2qSS5K7ShjduwiGYWFwBPIxlLNIot9yn0nb8KVRjH2DTM4jB 9eFaYdzjEqe/ln58frbMhyl4MHRgXIWnEDp4cWTNmBiC+gnRdBF4xXMTq6G7inS8PW7+ 5Uyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=LthWjnlRqwPVsS/SaAlB15xuPGLGuLfciTawY1djQSY=; b=ZV/6IPUDSd0bGJ29UR2aDcEvKmwRqlU8YYHRNA7vyeYe1emLCactGhwL77sIsUzm2L rhGf2C9eQF6vkevK9JxWSfr9vFoB+Zr/7+E6674FYZ3Ir18QMzpj+NTK24AKAWrgr/SE UgmCLarEtGhM5wr108PhQP8NP9OHYZ4SlOJ69Bf3jDIHCSQMfC5+PXOAeJm1VgXCQnGR G5w3cJm7TdcZasuSVnXBIPtv2zFLGtXu0OX8WS8Z1a5lsQ9EXF7QRJ/bI7nbVUD0XqoP hRBlMzMetMDx7JlcYTl2RvsUMrbF2AYQQWXbMd0meU2rxzPPt8IWuMymudL3Ca0WAg59 2NYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=rjtC0iVx; 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=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 u1si973315edi.511.2021.09.28.06.39.43; Tue, 28 Sep 2021 06:40:13 -0700 (PDT) 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=@canonical.com header.s=20210705 header.b=rjtC0iVx; 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=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241463AbhI1Ngu (ORCPT + 99 others); Tue, 28 Sep 2021 09:36:50 -0400 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]:44766 "EHLO smtp-relay-canonical-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241533AbhI1Ngd (ORCPT ); Tue, 28 Sep 2021 09:36:33 -0400 Received: from [10.172.193.212] (1.general.cking.uk.vpn [10.172.193.212]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 16CDC40CEE; Tue, 28 Sep 2021 13:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632836090; bh=LthWjnlRqwPVsS/SaAlB15xuPGLGuLfciTawY1djQSY=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=rjtC0iVxro3HDDb+ajvexNya1mRfJj0n7ePicasiTxDHVlsEnB+eJxugdJFHJDdN+ wnayh9SkmpmSOHAHlK9tGX3iuAXOuVW+gQBIstMINUfwtPDbUyit+fwaWW9pB9SWXS LZDOhyQLvKd2ktLsY2b6AzyhOQeBNzr5/BL+UFulSWWoDiZM8ANJRuhNEyKkbKs39G my6YrA3JXSXCCdIlOqs9OwlN+NplKaKBYKDuhgTbhSW3QXeIJ0J8NMfqqCGlGasvB8 5LYmkXNN5uhiaD0brBhx28+jbhc/mQM7yUuQay+6Q0H0A0TIEiiFWewPmAkqTotz/X aJisN56dq9mWw== Subject: Re: [PATCH][next] rtc: msc313: Fix unintentional sign extension issue on left shift of a u16 To: Daniel Palmer Cc: Daniel Palmer , Romain Perier , Alessandro Zummo , Alexandre Belloni , Nobuhiro Iwamatsu , linux-arm-kernel , linux-rtc@vger.kernel.org, kernel-janitors@vger.kernel.org, Linux Kernel Mailing List References: <20210928123906.988813-1-colin.king@canonical.com> From: Colin Ian King Message-ID: <8f21ec82-201d-efee-d1db-382a7885d38f@canonical.com> Date: Tue, 28 Sep 2021 14:34:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/09/2021 14:31, Daniel Palmer wrote: > Hi Colin, > > On Tue, 28 Sept 2021 at 21:39, Colin King wrote: >> Shifting the u16 value returned by readw by 16 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 the readw is set then >> the shifted value will be sign extended and the top 32 bits of >> the result will be set. > > Ah,.. C is fun in all the wrong places. :) > These chips are full of 32bit registers that are split into two 16 > registers 4 bytes apart when seen from the ARM CPU so we probably have > this same mistake in a few other places. > > A similar pattern is used a bit later on in the same file to read the counter: > > seconds = readw(priv->rtc_base + REG_RTC_CNT_VAL_L) > | (readw(priv->rtc_base + REG_RTC_CNT_VAL_H) << 16); Ah, I missed that one! I'll send a V2. > > I guess it works at the moment because the top bit won't be set until 2038. I hope to be retired by then, but I guess fixing it up before 2038 is a good idea ;-) > > Thanks, > > Daniel >