mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-11-28 20:44:00 +08:00
rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
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: be7d9c9161
("rtc: Add support for the MSTAR MSC313 RTC")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Romain Perier <romain.perier@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210928134654.991923-1-colin.king@canonical.com
This commit is contained in:
parent
3109151c47
commit
f3606687b4
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user