From patchwork Fri Jan 24 09:25:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233033 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 B1061C2D0DB for ; Fri, 24 Jan 2020 11:09:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 87A302071A for ; Fri, 24 Jan 2020 11:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864185; bh=oQ11vGuMdMc8OwfxVPTsx1gMmZkeMJU6SkGKsRAoo5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=BF4AC+52npnppP0Um94a8dV/0BqWBnhSK83SPdc5tn/ZaFsnRl/mov2XG5KWie3Cv ZcLEES8DOrUIHRZX+jLRDoRlp2LrqFvTo3CeVCsWLID6Z+ydQd2cM9q+AxzTlHoePy BlJII0A0ZaK2qb33u0LvUKHXg6LEhFycj4EpsTBc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731815AbgAXLJn (ORCPT ); Fri, 24 Jan 2020 06:09:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:45318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733099AbgAXLJl (ORCPT ); Fri, 24 Jan 2020 06:09:41 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 41C3D20663; Fri, 24 Jan 2020 11:09:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864180; bh=oQ11vGuMdMc8OwfxVPTsx1gMmZkeMJU6SkGKsRAoo5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qNctvjM787RIiTuOxomLX3Tt+lyefF4j9gqOdyCMcHTaaul6sBf49xmVdZhknCgtk 6JTczZfQbx1mP8mDRLwQmknCLT+ENM6PTs+UPawIQhzaZmws5p0uFDrJpaDYhowzdM gn/IZMsUhCzsjfD2IJEgbRkEz+OJwpQv8iAVnd1U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Alexandre Belloni , Sasha Levin Subject: [PATCH 4.19 181/639] rtc: pm8xxx: fix unintended sign extension Date: Fri, 24 Jan 2020 10:25:51 +0100 Message-Id: <20200124093109.829440154@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Colin Ian King [ Upstream commit e42280886018c6f77f0a90190f7cba344b0df3e0 ] 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#1309693 ("Unintended sign extension") Fixes: 9a9a54ad7aa2 ("drivers/rtc: add support for Qualcomm PMIC8xxx RTC") Signed-off-by: Colin Ian King Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-pm8xxx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c index 29358a0459258..e03104b734fc9 100644 --- a/drivers/rtc/rtc-pm8xxx.c +++ b/drivers/rtc/rtc-pm8xxx.c @@ -213,7 +213,8 @@ static int pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) } } - secs = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); + secs = value[0] | (value[1] << 8) | (value[2] << 16) | + ((unsigned long)value[3] << 24); rtc_time_to_tm(secs, tm); @@ -288,7 +289,8 @@ static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) return rc; } - secs = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); + secs = value[0] | (value[1] << 8) | (value[2] << 16) | + ((unsigned long)value[3] << 24); rtc_time_to_tm(secs, &alarm->time);