* [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock
@ 2016-07-04 11:03 Alim Akhtar
2016-07-04 11:03 ` [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq() Alim Akhtar
2016-07-05 7:18 ` [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock Krzysztof Kozlowski
0 siblings, 2 replies; 10+ messages in thread
From: Alim Akhtar @ 2016-07-04 11:03 UTC (permalink / raw)
To: rtc-linux, linux-kernel
Cc: alexandre.belloni, k.kozlowski, javier, pankaj.dubey, alim.akhtar
At the end of s3c_rtc_probe(), s3c_rtc_disable_clk() being called with rtc
clock already disabled, which looks extra and unnecessary call.
Lets clean it up.
Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
---
drivers/rtc/rtc-s3c.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index d01ad7e..b083840 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -577,8 +577,6 @@ static int s3c_rtc_probe(struct platform_device *pdev)
s3c_rtc_setfreq(info, 1);
- s3c_rtc_disable_clk(info);
-
return 0;
err_nortc:
--
1.7.10.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq()
2016-07-04 11:03 [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock Alim Akhtar
@ 2016-07-04 11:03 ` Alim Akhtar
2016-07-05 8:16 ` Krzysztof Kozlowski
2016-07-05 7:18 ` [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock Krzysztof Kozlowski
1 sibling, 1 reply; 10+ messages in thread
From: Alim Akhtar @ 2016-07-04 11:03 UTC (permalink / raw)
To: rtc-linux, linux-kernel
Cc: alexandre.belloni, k.kozlowski, javier, pankaj.dubey, alim.akhtar
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock
2016-07-04 11:03 [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock Alim Akhtar
2016-07-04 11:03 ` [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq() Alim Akhtar
@ 2016-07-05 7:18 ` Krzysztof Kozlowski
2016-07-05 8:46 ` Alim Akhtar
1 sibling, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2016-07-05 7:18 UTC (permalink / raw)
To: Alim Akhtar, rtc-linux, linux-kernel
Cc: alexandre.belloni, javier, pankaj.dubey
On 07/04/2016 01:03 PM, Alim Akhtar wrote:
> At the end of s3c_rtc_probe(), s3c_rtc_disable_clk() being called with rtc
> clock already disabled, which looks extra and unnecessary call.
> Lets clean it up.
Does not look right. Till that place, the clocks are enabled. Then
s3c_rtc_setaie() is called which expects that clocks are disabled...
otherwise counters get mixed.
So overall this looks like wrong approach unless I am missing something?
Best regards,
Krzysztof
>
> Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
> ---
> drivers/rtc/rtc-s3c.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
> index d01ad7e..b083840 100644
> --- a/drivers/rtc/rtc-s3c.c
> +++ b/drivers/rtc/rtc-s3c.c
> @@ -577,8 +577,6 @@ static int s3c_rtc_probe(struct platform_device *pdev)
>
> s3c_rtc_setfreq(info, 1);
>
> - s3c_rtc_disable_clk(info);
> -
> return 0;
>
> err_nortc:
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq()
2016-07-04 11:03 ` [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq() Alim Akhtar
@ 2016-07-05 8:16 ` Krzysztof Kozlowski
2016-07-05 8:52 ` Alim Akhtar
0 siblings, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2016-07-05 8:16 UTC (permalink / raw)
To: Alim Akhtar, rtc-linux, linux-kernel
Cc: alexandre.belloni, javier, pankaj.dubey
On 07/04/2016 01:03 PM, Alim Akhtar wrote:
> 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
The indentation suggests levels of calls (chain) not sequence. This
should be:
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().
What I don't get is that you wrote "it is *possible* that
s3c_rtc_setfreq() *might* get called". From my understanding this will
happen always because src_rtc_gettime() always disables the clocks.
Why it does not happen always?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock
2016-07-05 7:18 ` [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock Krzysztof Kozlowski
@ 2016-07-05 8:46 ` Alim Akhtar
2016-07-05 8:50 ` Krzysztof Kozlowski
0 siblings, 1 reply; 10+ messages in thread
From: Alim Akhtar @ 2016-07-05 8:46 UTC (permalink / raw)
To: Krzysztof Kozlowski, rtc-linux, linux-kernel
Cc: alexandre.belloni, javier, pankaj.dubey
Hi Krzsztof,
On 07/05/2016 12:48 PM, Krzysztof Kozlowski wrote:
> On 07/04/2016 01:03 PM, Alim Akhtar wrote:
>> At the end of s3c_rtc_probe(), s3c_rtc_disable_clk() being called with rtc
>> clock already disabled, which looks extra and unnecessary call.
>> Lets clean it up.
>
> Does not look right. Till that place, the clocks are enabled. Then
> s3c_rtc_setaie() is called which expects that clocks are disabled...
> otherwise counters get mixed.
>
The clock is always disabled when it reach s3c_rtc_setfreq() in probe(),
because s3c_rtc_gettime() will always disable the clock.
As far as s3c_rtc_setaie() is concern, it enables clock while entering
and disables it while leaving the function. And in
s3c_rtc_{enable,disable}_clk() there is check info->clk_disabled flag
which will make sure clock balancing.
> So overall this looks like wrong approach unless I am missing something?
>
> Best regards,
> Krzysztof
>
>>
>> Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
>> ---
>> drivers/rtc/rtc-s3c.c | 2 --
>> 1 file changed, 2 deletions(-)
>>
>> diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
>> index d01ad7e..b083840 100644
>> --- a/drivers/rtc/rtc-s3c.c
>> +++ b/drivers/rtc/rtc-s3c.c
>> @@ -577,8 +577,6 @@ static int s3c_rtc_probe(struct platform_device *pdev)
>>
>> s3c_rtc_setfreq(info, 1);
>>
>> - s3c_rtc_disable_clk(info);
>> -
>> return 0;
>>
>> err_nortc:
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock
2016-07-05 8:46 ` Alim Akhtar
@ 2016-07-05 8:50 ` Krzysztof Kozlowski
0 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2016-07-05 8:50 UTC (permalink / raw)
To: Alim Akhtar, rtc-linux, linux-kernel
Cc: alexandre.belloni, javier, pankaj.dubey
On 07/05/2016 10:46 AM, Alim Akhtar wrote:
> Hi Krzsztof,
>
> On 07/05/2016 12:48 PM, Krzysztof Kozlowski wrote:
>> On 07/04/2016 01:03 PM, Alim Akhtar wrote:
>>> At the end of s3c_rtc_probe(), s3c_rtc_disable_clk() being called
>>> with rtc
>>> clock already disabled, which looks extra and unnecessary call.
>>> Lets clean it up.
>>
>> Does not look right. Till that place, the clocks are enabled. Then
>> s3c_rtc_setaie() is called which expects that clocks are disabled...
>> otherwise counters get mixed.
>>
>
> The clock is always disabled when it reach s3c_rtc_setfreq() in probe(),
> because s3c_rtc_gettime() will always disable the clock.
>
> As far as s3c_rtc_setaie() is concern, it enables clock while entering
> and disables it while leaving the function. And in
> s3c_rtc_{enable,disable}_clk() there is check info->clk_disabled flag
> which will make sure clock balancing.
Ah, you're right. Looks correct although the information that clock is
disabled because of s3c_rtc_gettime() would be useful in the commit message.
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq()
2016-07-05 8:16 ` Krzysztof Kozlowski
@ 2016-07-05 8:52 ` Alim Akhtar
2016-07-05 8:56 ` Krzysztof Kozlowski
2016-07-05 9:44 ` pankaj.dubey
0 siblings, 2 replies; 10+ messages in thread
From: Alim Akhtar @ 2016-07-05 8:52 UTC (permalink / raw)
To: Krzysztof Kozlowski, rtc-linux, linux-kernel
Cc: alexandre.belloni, javier, pankaj.dubey
On 07/05/2016 01:46 PM, Krzysztof Kozlowski wrote:
> On 07/04/2016 01:03 PM, Alim Akhtar wrote:
>> 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
>
> The indentation suggests levels of calls (chain) not sequence. This
> should be:
> 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().
>
> What I don't get is that you wrote "it is *possible* that
> s3c_rtc_setfreq() *might* get called". From my understanding this will
> happen always because src_rtc_gettime() always disables the clocks.
>
> Why it does not happen always?
>
Yes, you are right, it is always disabled when reaches s3c_rtc_setfreq().
And I observed a kernel crash while testing on exynos7 platform in
s3c_rtc_setfreq() because clock was always disabled at this point. And
this patches fixes this issue.
> Best regards,
> Krzysztof
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq()
2016-07-05 8:52 ` Alim Akhtar
@ 2016-07-05 8:56 ` Krzysztof Kozlowski
2016-07-05 9:43 ` pankaj.dubey
2016-07-05 9:44 ` pankaj.dubey
1 sibling, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2016-07-05 8:56 UTC (permalink / raw)
To: Alim Akhtar, rtc-linux, linux-kernel
Cc: alexandre.belloni, javier, pankaj.dubey
On 07/05/2016 10:52 AM, Alim Akhtar wrote:
>
>
> On 07/05/2016 01:46 PM, Krzysztof Kozlowski wrote:
>> On 07/04/2016 01:03 PM, Alim Akhtar wrote:
>>> 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
>>
>> The indentation suggests levels of calls (chain) not sequence. This
>> should be:
>> 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().
>>
>> What I don't get is that you wrote "it is *possible* that
>> s3c_rtc_setfreq() *might* get called". From my understanding this will
>> happen always because src_rtc_gettime() always disables the clocks.
>>
>> Why it does not happen always?
>>
>
> Yes, you are right, it is always disabled when reaches s3c_rtc_setfreq().
> And I observed a kernel crash while testing on exynos7 platform in
> s3c_rtc_setfreq() because clock was always disabled at this point. And
> this patches fixes this issue.
Ok, thanks! Could you adjust the commit message mentioning that it
always causes crash on Exynos 7 platform and adding:
Fixes: 24e1455493da ("drivers/rtc/rtc-s3c.c: delete duplicate clock
control")
Cc: <stable@vger.kernel.org>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq()
2016-07-05 8:56 ` Krzysztof Kozlowski
@ 2016-07-05 9:43 ` pankaj.dubey
0 siblings, 0 replies; 10+ messages in thread
From: pankaj.dubey @ 2016-07-05 9:43 UTC (permalink / raw)
To: Krzysztof Kozlowski, Alim Akhtar, rtc-linux, linux-kernel
Cc: alexandre.belloni, javier
Hi Alim,
On Tuesday 05 July 2016 02:26 PM, Krzysztof Kozlowski wrote:
> On 07/05/2016 10:52 AM, Alim Akhtar wrote:
>>
>>
>> On 07/05/2016 01:46 PM, Krzysztof Kozlowski wrote:
>>> On 07/04/2016 01:03 PM, Alim Akhtar wrote:
>>>> 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
>>>
>>> The indentation suggests levels of calls (chain) not sequence. This
>>> should be:
>>> 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().
>>>
>>> What I don't get is that you wrote "it is *possible* that
>>> s3c_rtc_setfreq() *might* get called". From my understanding this will
>>> happen always because src_rtc_gettime() always disables the clocks.
>>>
>>> Why it does not happen always?
>>>
>>
>> Yes, you are right, it is always disabled when reaches s3c_rtc_setfreq().
>> And I observed a kernel crash while testing on exynos7 platform in
>> s3c_rtc_setfreq() because clock was always disabled at this point. And
>> this patches fixes this issue.
>
> Ok, thanks! Could you adjust the commit message mentioning that it
> always causes crash on Exynos 7 platform and adding:
>
> Fixes: 24e1455493da ("drivers/rtc/rtc-s3c.c: delete duplicate clock
> control")
> Cc: <stable@vger.kernel.org>
>
> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
>
After addressing Krzysztof's review comments, Please feel free to add
Reviewed-by: Pankaj Dubey <pankaj.dubey@samsung.com>
For testing on Exynos7420
Tested-by: Pankaj Dubey <pankaj.dubey@samsung.com>
Thanks,
Pankaj Dubey
> Best regards,
> Krzysztof
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq()
2016-07-05 8:52 ` Alim Akhtar
2016-07-05 8:56 ` Krzysztof Kozlowski
@ 2016-07-05 9:44 ` pankaj.dubey
1 sibling, 0 replies; 10+ messages in thread
From: pankaj.dubey @ 2016-07-05 9:44 UTC (permalink / raw)
To: Alim Akhtar, Krzysztof Kozlowski, rtc-linux, linux-kernel
Cc: alexandre.belloni, javier
Hi Alim,
On Tuesday 05 July 2016 02:22 PM, Alim Akhtar wrote:
>
>
> On 07/05/2016 01:46 PM, Krzysztof Kozlowski wrote:
>> On 07/04/2016 01:03 PM, Alim Akhtar wrote:
>>> 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
>>
>> The indentation suggests levels of calls (chain) not sequence. This
>> should be:
>> 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().
>>
>> What I don't get is that you wrote "it is *possible* that
>> s3c_rtc_setfreq() *might* get called". From my understanding this will
>> happen always because src_rtc_gettime() always disables the clocks.
>>
>> Why it does not happen always?
>>
>
> Yes, you are right, it is always disabled when reaches s3c_rtc_setfreq().
> And I observed a kernel crash while testing on exynos7 platform in
> s3c_rtc_setfreq() because clock was always disabled at this point. And
> this patches fixes this issue.
>
After addressing Krzysztof's review comments, Please feel free to add
Reviewed-by: Pankaj Dubey <pankaj.dubey@samsung.com>
For testing on Exynos7420
Tested-by: Pankaj Dubey <pankaj.dubey@samsung.com>
Thanks,
Pankaj Dubey
>
>> Best regards,
>> Krzysztof
>>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-07-05 9:41 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-04 11:03 [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock Alim Akhtar
2016-07-04 11:03 ` [RFC PATCH 2/2] rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq() Alim Akhtar
2016-07-05 8:16 ` Krzysztof Kozlowski
2016-07-05 8:52 ` Alim Akhtar
2016-07-05 8:56 ` Krzysztof Kozlowski
2016-07-05 9:43 ` pankaj.dubey
2016-07-05 9:44 ` pankaj.dubey
2016-07-05 7:18 ` [RFC PATCH 1/2] rtc: s3c: Remove unnecessary call to disable already disabled clock Krzysztof Kozlowski
2016-07-05 8:46 ` Alim Akhtar
2016-07-05 8:50 ` Krzysztof Kozlowski
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).