diff options
author | Tero Kristo <t-kristo@ti.com> | 2012-09-25 12:05:32 -0400 |
---|---|---|
committer | Tony Lindgren <tony@atomide.com> | 2012-10-17 12:00:31 -0400 |
commit | 64e29fd5ed42f5d0ff5b0ea9395b3abd5d43f89b (patch) | |
tree | 2d1a162662e2279f03d17de9b2e33c5d6cb8ca54 /arch/arm | |
parent | 49c58e82023649924b1b0f38d715d94093f4044b (diff) |
ARM: OMAP: clockdomain: Fix locking on _clkdm_clk_hwmod_enable / disable
Previously the code only acquired spinlock after increasing / decreasing
the usecount value, which is wrong. This leaves a small window where
a task switch may occur between the check of the usecount and the actual
wakeup / sleep of the domain. Fixed by moving the spinlock locking before
the usecount access. Left the usecount as atomic_t if someone wants an
easy access to the parameter through atomic_read.
Signed-off-by: Tero Kristo <t-kristo@ti.com>
Acked-by: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'arch/arm')
-rw-r--r-- | arch/arm/mach-omap2/clockdomain.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/arch/arm/mach-omap2/clockdomain.c b/arch/arm/mach-omap2/clockdomain.c index cbb879139c51..512e79a842cb 100644 --- a/arch/arm/mach-omap2/clockdomain.c +++ b/arch/arm/mach-omap2/clockdomain.c | |||
@@ -925,15 +925,18 @@ static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm) | |||
925 | if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable) | 925 | if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable) |
926 | return -EINVAL; | 926 | return -EINVAL; |
927 | 927 | ||
928 | spin_lock_irqsave(&clkdm->lock, flags); | ||
929 | |||
928 | /* | 930 | /* |
929 | * For arch's with no autodeps, clkcm_clk_enable | 931 | * For arch's with no autodeps, clkcm_clk_enable |
930 | * should be called for every clock instance or hwmod that is | 932 | * should be called for every clock instance or hwmod that is |
931 | * enabled, so the clkdm can be force woken up. | 933 | * enabled, so the clkdm can be force woken up. |
932 | */ | 934 | */ |
933 | if ((atomic_inc_return(&clkdm->usecount) > 1) && autodeps) | 935 | if ((atomic_inc_return(&clkdm->usecount) > 1) && autodeps) { |
936 | spin_unlock_irqrestore(&clkdm->lock, flags); | ||
934 | return 0; | 937 | return 0; |
938 | } | ||
935 | 939 | ||
936 | spin_lock_irqsave(&clkdm->lock, flags); | ||
937 | arch_clkdm->clkdm_clk_enable(clkdm); | 940 | arch_clkdm->clkdm_clk_enable(clkdm); |
938 | pwrdm_state_switch(clkdm->pwrdm.ptr); | 941 | pwrdm_state_switch(clkdm->pwrdm.ptr); |
939 | spin_unlock_irqrestore(&clkdm->lock, flags); | 942 | spin_unlock_irqrestore(&clkdm->lock, flags); |
@@ -950,15 +953,19 @@ static int _clkdm_clk_hwmod_disable(struct clockdomain *clkdm) | |||
950 | if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_disable) | 953 | if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_disable) |
951 | return -EINVAL; | 954 | return -EINVAL; |
952 | 955 | ||
956 | spin_lock_irqsave(&clkdm->lock, flags); | ||
957 | |||
953 | if (atomic_read(&clkdm->usecount) == 0) { | 958 | if (atomic_read(&clkdm->usecount) == 0) { |
959 | spin_unlock_irqrestore(&clkdm->lock, flags); | ||
954 | WARN_ON(1); /* underflow */ | 960 | WARN_ON(1); /* underflow */ |
955 | return -ERANGE; | 961 | return -ERANGE; |
956 | } | 962 | } |
957 | 963 | ||
958 | if (atomic_dec_return(&clkdm->usecount) > 0) | 964 | if (atomic_dec_return(&clkdm->usecount) > 0) { |
965 | spin_unlock_irqrestore(&clkdm->lock, flags); | ||
959 | return 0; | 966 | return 0; |
967 | } | ||
960 | 968 | ||
961 | spin_lock_irqsave(&clkdm->lock, flags); | ||
962 | arch_clkdm->clkdm_clk_disable(clkdm); | 969 | arch_clkdm->clkdm_clk_disable(clkdm); |
963 | pwrdm_state_switch(clkdm->pwrdm.ptr); | 970 | pwrdm_state_switch(clkdm->pwrdm.ptr); |
964 | spin_unlock_irqrestore(&clkdm->lock, flags); | 971 | spin_unlock_irqrestore(&clkdm->lock, flags); |