From 00514651723f28a0a5a7e1ddf54bc177d7ba5709 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 16 Nov 2021 11:09:38 +0100 Subject: [PATCH] BACKPORT: rtc: qpnp: fix unintended sign extension [ 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") Signed-off-by: Colin Ian King Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin Signed-off-by: Andrzej Perczak Change-Id: Ie50f3c49e2ad9b23b41ed4e904630f4e991e1694 Signed-off-by: azrim --- drivers/rtc/qpnp-rtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rtc/qpnp-rtc.c b/drivers/rtc/qpnp-rtc.c index e3e88976915f..c470d220197d 100644 --- a/drivers/rtc/qpnp-rtc.c +++ b/drivers/rtc/qpnp-rtc.c @@ -46,7 +46,7 @@ #define NUM_8_BIT_RTC_REGS 0x4 #define TO_SECS(arr) (arr[0] | (arr[1] << 8) | (arr[2] << 16) | \ - (arr[3] << 24)) + ((unsigned long)arr[3] << 24)) /* Module parameter to control power-on-alarm */ bool poweron_alarm;