diff options
author | David Lechner <david@lechnology.com> | 2018-01-04 20:46:08 -0500 |
---|---|---|
committer | Stephen Boyd <sboyd@codeaurora.org> | 2018-01-10 16:39:31 -0500 |
commit | a12aa8a68dfef5de181f2e555aa950a0ab05411f (patch) | |
tree | f2faf66b671c503e15028be86a07e70f63767f96 | |
parent | 4fbd8d194f06c8a3fd2af1ce560ddb31f7ec8323 (diff) |
clk: fix reentrancy of clk_enable() on UP systems
Reentrant calls to clk_enable() are not working on UP systems. This is
caused by the fact spin_trylock_irqsave() always returns true when
CONFIG_SMP=n (and CONFIG_DEBUG_SPINLOCK=n) which causes the reference
counting to not work correctly when clk_enable_lock() is called twice
before clk_enable_unlock() is called (this happens when clk_enable()
is called from within another clk_enable()).
This fixes the problem by skipping the call to spin_trylock_irqsave() on UP
systems and relying solely on reference counting. We also make sure to set
flags in this case so that we are not returning an uninitialized value.
Suggested-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: David Lechner <david@lechnology.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
-rw-r--r-- | drivers/clk/clk.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 647d056df88c..b221d80cc7ba 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c | |||
@@ -141,10 +141,18 @@ static unsigned long clk_enable_lock(void) | |||
141 | { | 141 | { |
142 | unsigned long flags; | 142 | unsigned long flags; |
143 | 143 | ||
144 | if (!spin_trylock_irqsave(&enable_lock, flags)) { | 144 | /* |
145 | * On UP systems, spin_trylock_irqsave() always returns true, even if | ||
146 | * we already hold the lock. So, in that case, we rely only on | ||
147 | * reference counting. | ||
148 | */ | ||
149 | if (!IS_ENABLED(CONFIG_SMP) || | ||
150 | !spin_trylock_irqsave(&enable_lock, flags)) { | ||
145 | if (enable_owner == current) { | 151 | if (enable_owner == current) { |
146 | enable_refcnt++; | 152 | enable_refcnt++; |
147 | __acquire(enable_lock); | 153 | __acquire(enable_lock); |
154 | if (!IS_ENABLED(CONFIG_SMP)) | ||
155 | local_save_flags(flags); | ||
148 | return flags; | 156 | return flags; |
149 | } | 157 | } |
150 | spin_lock_irqsave(&enable_lock, flags); | 158 | spin_lock_irqsave(&enable_lock, flags); |