Thread (3 messages) 3 messages, 3 authors, 2021-10-01

Re: [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16

From: Romain Perier <romain.perier@gmail.com>
Date: 2021-09-28 17:36:14
Also in: kernel-janitors, linux-arm-kernel, lkml

Hi,


Re-tested with rtctest and rtc-range, everything passed.



Le mar. 28 sept. 2021 à 15:46, Colin King [off-list ref] a écrit :
From: Colin Ian King <redacted>

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 <redacted>
Reviewed-by: Romain Perier <romain.perier@gmail.com>

Thanks,
Romain
quoted hunk ↗ jump to hunk
---
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);

--
2.32.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help