[RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq()

Alim Akhtar
2016-07-04T11:03:56Z

As per code flow it is possible that s3c_rtc_setfreq() might get called
with rtc clock disabled and in set_freq we perform h/w registers read/write,
which might results in a kernel crash while probing rtc driver.
Below is one such case:
s3c_rtc_probe()
clk_prepare_enable(info->rtc_clk) // rtc clock enabled
s3c_rtc_gettime() // will enable clk if not done, and disable it upon exit
s3c_rtc_setfreq() //then this will be called with clk disabled

This patch take cares of such issue by adding s3c_rtc_{enable/disable}_clk in
s3c_rtc_setfreq().

Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
---
drivers/rtc/rtc-s3c.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index b083840..1168814 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -149,12 +149,14 @@ static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq)
if (!is_power_of_2(freq))
return -EINVAL;

+ s3c_rtc_enable_clk(info);
spin_lock_irq(&info->pie_lock);

if (info->data->set_freq)
info->data->set_freq(info, freq);

spin_unlock_irq(&info->pie_lock);
+ s3c_rtc_disable_clk(info);

return 0;
}
--
1.7.10.4