From patchwork Tue Sep 28 13:46:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12522831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C4B1C433EF for ; Tue, 28 Sep 2021 13:49:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 31129611CA for ; Tue, 28 Sep 2021 13:49:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 31129611CA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=rNfO6wKRLgkW8lAjIpy1/H+lKT27sbXphiTyX7xK6W8=; b=AhO730g3lnJgVB XvHD64gru+Nx8ONrrC3RvK5F5gawOkk/N67F3XcqmaiY39hExb/IgNpp5WSn6hXTgO+skD4P8Y3dA lflsOR66+ZDL632LBmgGlmyGcEXEJ7+WCtuy6BPe3Bpi5fPItY93dogtc1TL+YOM4wNb7xFlVwuR7 CJbGNn4TdUUqrTxM4i/C6lNZyrk74myYfM6mH54k7dFS+wIlU1Hv8SrBXDTqEc36tXw7Hjduiab2x KftnGKvUUiQ/2K6vC+gv/lk3wfnb5Ku93iZ/FWkTGvjR2VFe5mbWQo4UxA4fq3WCNzcyn05ELKSHm CMBI19B2g7JHMhg/8AsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVDRl-007N7c-9B; Tue, 28 Sep 2021 13:47:01 +0000 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVDRh-007N76-Ae for linux-arm-kernel@lists.infradead.org; Tue, 28 Sep 2021 13:46:58 +0000 Received: from localhost (1.general.cking.uk.vpn [10.172.193.212]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 19D29405E4; Tue, 28 Sep 2021 13:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632836815; bh=CVPzKw2Lf6fMiEtRUXtIUtsODqt2nAe+y+A62+2Z9IY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=DSXRZ0wptf2RiwWyAD0QPn2zdUgT89tEBpTwHBqCgEPUx48yTDEulxBLFXUCgpICR tyZJKsR+RUsxjSTytHcs6u/Vg7q9b75ycMuuVTICwi9Attq658OoC8bak2feTQFX9c h7GVZiR8+MJuFNvP9m/PJ6j91YF+/3jMw208n/QuA2IGg1BGwN/36KitkUzRiR3Vqm 8SCigiokb9y+ZWIigeBfQg9BVCLRH2ye4cQ0TyowvL1rmppSPFZakhmcDDpKg5tXz9 pJCKf1pDSRGOu38clY9lxfOjMHNOtxBMRWBXHzG33GvCBkw2B5VO7l1xvsIGMR4xGz TbazDNZNjvcaA== From: Colin King To: Daniel Palmer , Romain Perier , Alexandre Belloni , Nobuhiro Iwamatsu , linux-arm-kernel@lists.infradead.org, linux-rtc@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16 Date: Tue, 28 Sep 2021 14:46:54 +0100 Message-Id: <20210928134654.991923-1-colin.king@canonical.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210928_064657_600297_2836FA75 X-CRM114-Status: GOOD ( 13.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Colin Ian King 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. Fixes: be7d9c9161b9 ("rtc: Add support for the MSTAR MSC313 RTC") Signed-off-by: Colin Ian King Reviewed-by: Romain Perier --- V2: Fix identical issue in msc313_rtc_read_time too. Thanks to Daniel Palmer for noticing this ommission. --- drivers/rtc/rtc-msc313.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-msc313.c b/drivers/rtc/rtc-msc313.c index 5f178d29cfd8..f3fde013c4b8 100644 --- a/drivers/rtc/rtc-msc313.c +++ b/drivers/rtc/rtc-msc313.c @@ -53,7 +53,7 @@ static int msc313_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) unsigned long seconds; seconds = readw(priv->rtc_base + REG_RTC_MATCH_VAL_L) - | (readw(priv->rtc_base + REG_RTC_MATCH_VAL_H) << 16); + | ((unsigned long)readw(priv->rtc_base + REG_RTC_MATCH_VAL_H) << 16); rtc_time64_to_tm(seconds, &alarm->time); @@ -122,7 +122,7 @@ static int msc313_rtc_read_time(struct device *dev, struct rtc_time *tm) udelay(1); seconds = readw(priv->rtc_base + REG_RTC_CNT_VAL_L) - | (readw(priv->rtc_base + REG_RTC_CNT_VAL_H) << 16); + | ((unsigned long)readw(priv->rtc_base + REG_RTC_CNT_VAL_H) << 16); rtc_time64_to_tm(seconds, tm);