All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
@ 2021-09-28 13:46 ` Colin King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin King @ 2021-09-28 13:46 UTC (permalink / raw)
  To: Daniel Palmer, Romain Perier, Alexandre Belloni,
	Nobuhiro Iwamatsu, linux-arm-kernel, linux-rtc
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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 <colin.king@canonical.com>
---
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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
@ 2021-09-28 13:46 ` Colin King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin King @ 2021-09-28 13:46 UTC (permalink / raw)
  To: Daniel Palmer, Romain Perier, Alexandre Belloni,
	Nobuhiro Iwamatsu, linux-arm-kernel, linux-rtc
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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 <colin.king@canonical.com>
---
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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
  2021-09-28 13:46 ` Colin King
@ 2021-09-28 17:35   ` Romain Perier
  -1 siblings, 0 replies; 6+ messages in thread
From: Romain Perier @ 2021-09-28 17:35 UTC (permalink / raw)
  To: Colin King
  Cc: Daniel Palmer, Alexandre Belloni, Nobuhiro Iwamatsu,
	linux-arm-kernel, linux-rtc, kernel-janitors,
	Linux Kernel Mailing List

Hi,


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



Le mar. 28 sept. 2021 à 15:46, Colin King <colin.king@canonical.com> a écrit :
>
> From: Colin Ian King <colin.king@canonical.com>
>
> 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 <colin.king@canonical.com>

Reviewed-by: Romain Perier <romain.perier@gmail.com>

Thanks,
Romain

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
@ 2021-09-28 17:35   ` Romain Perier
  0 siblings, 0 replies; 6+ messages in thread
From: Romain Perier @ 2021-09-28 17:35 UTC (permalink / raw)
  To: Colin King
  Cc: Daniel Palmer, Alexandre Belloni, Nobuhiro Iwamatsu,
	linux-arm-kernel, linux-rtc, kernel-janitors,
	Linux Kernel Mailing List

Hi,


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



Le mar. 28 sept. 2021 à 15:46, Colin King <colin.king@canonical.com> a écrit :
>
> From: Colin Ian King <colin.king@canonical.com>
>
> 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 <colin.king@canonical.com>

Reviewed-by: Romain Perier <romain.perier@gmail.com>

Thanks,
Romain

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
  2021-09-28 13:46 ` Colin King
@ 2021-10-01 21:29   ` Alexandre Belloni
  -1 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2021-10-01 21:29 UTC (permalink / raw)
  To: linux-rtc, Colin King, Romain Perier, Nobuhiro Iwamatsu,
	linux-arm-kernel, Daniel Palmer
  Cc: Alexandre Belloni, linux-kernel, kernel-janitors

On Tue, 28 Sep 2021 14:46:54 +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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.
> 
> [...]

Applied, thanks!

[1/1] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
      commit: f3606687b447c41d28a011c98373b62b1cd52345

Best regards,
-- 
Alexandre Belloni <alexandre.belloni@bootlin.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
@ 2021-10-01 21:29   ` Alexandre Belloni
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2021-10-01 21:29 UTC (permalink / raw)
  To: linux-rtc, Colin King, Romain Perier, Nobuhiro Iwamatsu,
	linux-arm-kernel, Daniel Palmer
  Cc: Alexandre Belloni, linux-kernel, kernel-janitors

On Tue, 28 Sep 2021 14:46:54 +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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.
> 
> [...]

Applied, thanks!

[1/1] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16
      commit: f3606687b447c41d28a011c98373b62b1cd52345

Best regards,
-- 
Alexandre Belloni <alexandre.belloni@bootlin.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-01 21:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 13:46 [PATCH][next][V2] rtc: msc313: Fix unintentional sign extension issues with left shift of a u16 Colin King
2021-09-28 13:46 ` Colin King
2021-09-28 17:35 ` Romain Perier
2021-09-28 17:35   ` Romain Perier
2021-10-01 21:29 ` Alexandre Belloni
2021-10-01 21:29   ` Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.