* [PATCH] rtc: ds1685: Fix bank switching to avoid endless loop
@ 2020-09-10 8:41 Thomas Bogendoerfer
2020-09-11 1:16 ` Joshua Kinard
2020-09-15 9:25 ` Alexandre Belloni
0 siblings, 2 replies; 3+ messages in thread
From: Thomas Bogendoerfer @ 2020-09-10 8:41 UTC (permalink / raw)
To: Joshua Kinard, Alessandro Zummo, Alexandre Belloni, linux-rtc,
linux-kernel
ds1685_rtc_begin_data_access() tried to access an extended register before
enabling access to it by switching to bank 1. Depending on content in NVRAM
this could lead to an endless loop. While at it fix also switch back to
bank 0 in ds1685_rtc_end_data_access().
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
drivers/rtc/rtc-ds1685.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index 56c670af2e50..dfbd7b88b2b9 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -193,12 +193,12 @@ ds1685_rtc_begin_data_access(struct ds1685_priv *rtc)
rtc->write(rtc, RTC_CTRL_B,
(rtc->read(rtc, RTC_CTRL_B) | RTC_CTRL_B_SET));
+ /* Switch to Bank 1 */
+ ds1685_rtc_switch_to_bank1(rtc);
+
/* Read Ext Ctrl 4A and check the INCR bit to avoid a lockout. */
while (rtc->read(rtc, RTC_EXT_CTRL_4A) & RTC_CTRL_4A_INCR)
cpu_relax();
-
- /* Switch to Bank 1 */
- ds1685_rtc_switch_to_bank1(rtc);
}
/**
@@ -213,7 +213,7 @@ static inline void
ds1685_rtc_end_data_access(struct ds1685_priv *rtc)
{
/* Switch back to Bank 0 */
- ds1685_rtc_switch_to_bank1(rtc);
+ ds1685_rtc_switch_to_bank0(rtc);
/* Clear the SET bit in Ctrl B */
rtc->write(rtc, RTC_CTRL_B,
--
2.16.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] rtc: ds1685: Fix bank switching to avoid endless loop
2020-09-10 8:41 [PATCH] rtc: ds1685: Fix bank switching to avoid endless loop Thomas Bogendoerfer
@ 2020-09-11 1:16 ` Joshua Kinard
2020-09-15 9:25 ` Alexandre Belloni
1 sibling, 0 replies; 3+ messages in thread
From: Joshua Kinard @ 2020-09-11 1:16 UTC (permalink / raw)
To: Thomas Bogendoerfer, Alessandro Zummo, Alexandre Belloni,
linux-rtc, linux-kernel
On 9/10/2020 04:41, Thomas Bogendoerfer wrote:
> ds1685_rtc_begin_data_access() tried to access an extended register before
> enabling access to it by switching to bank 1. Depending on content in NVRAM
> this could lead to an endless loop. While at it fix also switch back to
> bank 0 in ds1685_rtc_end_data_access().
>
> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> ---
> drivers/rtc/rtc-ds1685.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
> index 56c670af2e50..dfbd7b88b2b9 100644
> --- a/drivers/rtc/rtc-ds1685.c
> +++ b/drivers/rtc/rtc-ds1685.c
> @@ -193,12 +193,12 @@ ds1685_rtc_begin_data_access(struct ds1685_priv *rtc)
> rtc->write(rtc, RTC_CTRL_B,
> (rtc->read(rtc, RTC_CTRL_B) | RTC_CTRL_B_SET));
>
> + /* Switch to Bank 1 */
> + ds1685_rtc_switch_to_bank1(rtc);
> +
> /* Read Ext Ctrl 4A and check the INCR bit to avoid a lockout. */
> while (rtc->read(rtc, RTC_EXT_CTRL_4A) & RTC_CTRL_4A_INCR)
> cpu_relax();
> -
> - /* Switch to Bank 1 */
> - ds1685_rtc_switch_to_bank1(rtc);
> }
>
> /**
> @@ -213,7 +213,7 @@ static inline void
> ds1685_rtc_end_data_access(struct ds1685_priv *rtc)
> {
> /* Switch back to Bank 0 */
> - ds1685_rtc_switch_to_bank1(rtc);
> + ds1685_rtc_switch_to_bank0(rtc);
>
> /* Clear the SET bit in Ctrl B */
> rtc->write(rtc, RTC_CTRL_B,
>
This probably needs to be sent to stable as well.
Acked-by: Joshua Kinard <kumba@gentoo.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rtc: ds1685: Fix bank switching to avoid endless loop
2020-09-10 8:41 [PATCH] rtc: ds1685: Fix bank switching to avoid endless loop Thomas Bogendoerfer
2020-09-11 1:16 ` Joshua Kinard
@ 2020-09-15 9:25 ` Alexandre Belloni
1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2020-09-15 9:25 UTC (permalink / raw)
To: linux-kernel, linux-rtc, Joshua Kinard, Alessandro Zummo,
Thomas Bogendoerfer
Cc: Alexandre Belloni
On Thu, 10 Sep 2020 10:41:24 +0200, Thomas Bogendoerfer wrote:
> ds1685_rtc_begin_data_access() tried to access an extended register before
> enabling access to it by switching to bank 1. Depending on content in NVRAM
> this could lead to an endless loop. While at it fix also switch back to
> bank 0 in ds1685_rtc_end_data_access().
Applied, thanks!
[1/1] rtc: ds1685: Fix bank switching to avoid endless loop
commit: 9f8010e71f091b0609452742cfed4650ee633c44
Best regards,
--
Alexandre Belloni <alexandre.belloni@bootlin.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-15 9:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-10 8:41 [PATCH] rtc: ds1685: Fix bank switching to avoid endless loop Thomas Bogendoerfer
2020-09-11 1:16 ` Joshua Kinard
2020-09-15 9:25 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).