Skip to contentSkip to conversation

avr32: fix deadlock when reading clock list in debugfs

PATCH In review Ole Henrik Jahren 2 participants 2 messages Mar 6, 2011 – Apr 13, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 avr32: fix deadlock when reading clock list in debugfs

When writing out /sys/kernel/debug/at32ap_clk, clock list lock is being held while clk_get() is called. clk_get() attempts to take the same lock, which results in deadlock. Introduce and call lock free version, __clk_get(), instead.

Cc Hans-Christian Egtvedt <[email protected]>
---
 arch/avr32/mach-at32ap/clock.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
arch/avr32/mach-at32ap/clock.c +16 -8
index 442f08c..86925fd 100644
@@ -35,22 +35,30 @@ void at32_clk_register(struct clk *clk)
 	spin_unlock(&clk_list_lock);
 }
 
-struct clk *clk_get(struct device *dev, const char *id)
+static struct clk *__clk_get(struct device *dev, const char *id)
 {
 	struct clk *clk;
 
-	spin_lock(&clk_list_lock);
-
 	list_for_each_entry(clk, &at32_clock_list, list) {
 		if (clk->dev == dev && strcmp(id, clk->name) == 0) {
-			spin_unlock(&clk_list_lock);
 			return clk;
 		}
 	}
 
-	spin_unlock(&clk_list_lock);
 	return ERR_PTR(-ENOENT);
 }
+
+struct clk *clk_get(struct device *dev, const char *id)
+{
+	struct clk *clk;
+
+	spin_lock(&clk_list_lock);
+	clk = __clk_get(dev, id);
+	spin_unlock(&clk_list_lock);
+
+	return clk;
+}
+
 EXPORT_SYMBOL(clk_get);
 
 void clk_put(struct clk *clk)
@@ -257,15 +265,15 @@ static int clk_show(struct seq_file *s, void *unused)
 	spin_lock(&clk_list_lock);
 
 	/* show clock tree as derived from the three oscillators */
-	clk = clk_get(NULL, "osc32k");
+	clk = __clk_get(NULL, "osc32k");
 	dump_clock(clk, &r);
 	clk_put(clk);
 
-	clk = clk_get(NULL, "osc0");
+	clk = __clk_get(NULL, "osc0");
 	dump_clock(clk, &r);
 	clk_put(clk);
 
-	clk = clk_get(NULL, "osc1");
+	clk = __clk_get(NULL, "osc1");
 	dump_clock(clk, &r);
 	clk_put(clk);
 
Signature · 1 line
1.7.4
#1 lore raw
Quoted 7 lines · Ole Henrik Jahren

When writing out /sys/kernel/debug/at32ap_clk, clock list lock is being held while clk_get() is called. clk_get() attempts to take the same lock, which results in deadlock. Introduce and call lock free version, __clk_get(), instead.

Cc Hans-Christian Egtvedt <[email protected]>

Thanks for this fix, added to the AVR32 tree.

<snipp patch>

Signature · 1 line
Hans-Christian Egtvedt