From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AD26C33CB3 for ; Thu, 16 Jan 2020 19:09:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D95A206E6 for ; Thu, 16 Jan 2020 19:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579201787; bh=4KwJYEY4NLAQPKKbonyJb+ZFRqThbJv4RYUN1FP+KZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Qrnq8cxGxEz1GMwABaQEVj0+0Xje6ALomEBZVLmVOxeDuwAOouRQeUkHDnLmncerO 4QzfzucG5D53AQxwm7hUjz/Jj2/KP6A2xtlt4kedqqguct81Kq4bC/0bD0UslZwnZD OkqBIFdbxPaDpdMsl5pcqXuFnPg+5ySSLCOv2+l8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387860AbgAPRAk (ORCPT ); Thu, 16 Jan 2020 12:00:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:50534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387857AbgAPRAj (ORCPT ); Thu, 16 Jan 2020 12:00:39 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3816020730; Thu, 16 Jan 2020 17:00:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579194039; bh=4KwJYEY4NLAQPKKbonyJb+ZFRqThbJv4RYUN1FP+KZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NLq8vCNXU3Gya7ugD7dgcICrG2T/NGdNHP+m0SxlO0UUtH+Y+dfHqve+2GAqVw49a X+5qmaE5+jC9tT6L1Ljna5ZXd92E0RT0s6roL+oNtqAXtLxZ79RwpCSbjLTBNasFvl kuhteyGH4wBm1oUzbEB8qUfS6L16ktCsTVihY1Nw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Colin Ian King , Alexandre Belloni , Sasha Levin , linux-rtc@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 156/671] rtc: ds1672: fix unintended sign extension Date: Thu, 16 Jan 2020 11:51:05 -0500 Message-Id: <20200116165940.10720-39-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116165940.10720-1-sashal@kernel.org> References: <20200116165940.10720-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org From: Colin Ian King [ Upstream commit f0c04c276739ed8acbb41b4868e942a55b128dca ] Shifting a u8 by 24 will cause the value to be promoted to an integer. If the top bit of the u8 is set then the following conversion to an unsigned long will sign extend the value causing the upper 32 bits to be set in the result. Fix this by casting the u8 value to an unsigned long before the shift. Detected by CoverityScan, CID#138801 ("Unintended sign extension") Fixes: edf1aaa31fc5 ("[PATCH] RTC subsystem: DS1672 driver") Signed-off-by: Colin Ian King Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-ds1672.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c index 9caaccccaa57..b1ebca099b0d 100644 --- a/drivers/rtc/rtc-ds1672.c +++ b/drivers/rtc/rtc-ds1672.c @@ -58,7 +58,8 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm) "%s: raw read data - counters=%02x,%02x,%02x,%02x\n", __func__, buf[0], buf[1], buf[2], buf[3]); - time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + time = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | + (buf[1] << 8) | buf[0]; rtc_time_to_tm(time, tm); -- 2.20.1