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 <colin.king@canonical.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Andrzej Perczak <linux@andrzejperczak.com>
Change-Id: Ie50f3c49e2ad9b23b41ed4e904630f4e991e1694
Signed-off-by: azrim <mirzaspc@gmail.com>
This commit is contained in:
Colin Ian King 2021-11-16 11:09:38 +01:00 committed by azrim
parent 099c263bc3
commit 0051465172
No known key found for this signature in database
GPG Key ID: 497F8FB059B45D1C

View File

@ -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;