Skip to contentSkip to conversation

clk: tegra: Implement locking for super clock

PATCH In review Peter De Schrijver 4 participants 5 messages Feb 7, 2013 – Feb 8, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: tegra: Implement locking for super clock

Although tegra_clk_register_super_mux() has a lock parameter, the lock is not actually used by the code. Fixed with this patch.

---
 drivers/clk/tegra/clk-super.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
drivers/clk/tegra/clk-super.c +15 -3
index 7ad48a8..2fd924d 100644
@@ -73,7 +73,12 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
 {
 	struct tegra_clk_super_mux *mux = to_clk_super_mux(hw);
 	u32 val, state;
+	int err = 0;
 	u8 parent_index, shift;
+	unsigned long flags = 0;
+
+	if (mux->lock)
+		spin_lock_irqsave(mux->lock, flags);
 
 	val = readl_relaxed(mux->reg);
 	state = val & SUPER_STATE_MASK;
@@ -92,8 +97,10 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
 					       (index == mux->pllx_index))) {
 		parent_index = clk_super_get_parent(hw);
 		if ((parent_index == mux->div2_index) ||
-		    (parent_index == mux->pllx_index))
-			return -EINVAL;
+		    (parent_index == mux->pllx_index)) {
+			err = -EINVAL;
+			goto out;
+		}
 
 		val ^= SUPER_LP_DIV2_BYPASS;
 		writel_relaxed(val, mux->reg);
@@ -107,7 +114,12 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
 
 	writel_relaxed(val, mux->reg);
 	udelay(2);
-	return 0;
+
+out:
+	if (mux->lock)
+		spin_unlock_irqrestore(mux->lock, flags);
+
+	return err;
 }
 
 const struct clk_ops tegra_clk_super_ops = {
Signature · 1 line
1.7.7.rc0.72.g4b5ea.dirty
Acked-by on v1 1/1
#1 lore raw

Quoting Peter De Schrijver (2013-02-07 08:24:14)

Quoted 13 lines

Although tegra_clk_register_super_mux() has a lock parameter, the lock is not actually used by the code. Fixed with this patch.

---
 drivers/clk/tegra/clk-super.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
drivers/clk/tegra/clk-super.c +0 -0
index 7ad48a8..2fd924d 100644

drivers/clk/tegra/clk-super.c static int clk_super_set_parent(struct clk_hw *hw, u8 index) · line 78

Quoted 6 lines
drivers/clk/tegra/clk-super.c +2 -0
@@ -73,7 +73,12 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
 {
        struct tegra_clk_super_mux *mux = to_clk_super_mux(hw);
        u32 val, state;
+       int err = 0;
        u8 parent_index, shift;
+       unsigned long flags = 0;

I don't think initializing flags to zero is necessary but it is not a big deal. Is gcc throwing a warning? Otherwise:

Regards,
Mike

#2 lore raw
Quoted 24 lines · Mike Turquette

Quoting Peter De Schrijver (2013-02-07 08:24:14)

Quoted 13 lines

Although tegra_clk_register_super_mux() has a lock parameter, the lock is not actually used by the code. Fixed with this patch.

---
 drivers/clk/tegra/clk-super.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
drivers/clk/tegra/clk-super.c +0 -0
index 7ad48a8..2fd924d 100644

drivers/clk/tegra/clk-super.c static int clk_super_set_parent(struct clk_hw *hw, u8 index) · line 78

Quoted 6 lines
drivers/clk/tegra/clk-super.c +2 -0
@@ -73,7 +73,12 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
 {
        struct tegra_clk_super_mux *mux = to_clk_super_mux(hw);
        u32 val, state;
+       int err = 0;
        u8 parent_index, shift;
+       unsigned long flags = 0;

I don't think initializing flags to zero is necessary but it is not a big deal. Is gcc throwing a warning? Otherwise:

Quoted 1 line

I've applied this to Tegra's for-3.9/soc-ccf-fixes branch. If you want to repost given Mike's comments, I can take an updated version.

#3 lore raw
In reply to Mike Turquette
Quoted 9 lines · Mike Turquette

Quoting Peter De Schrijver (2013-02-07 08:24:14)

Quoted 8 lines

Although tegra_clk_register_super_mux() has a lock parameter, the lock is not actually used by the code. Fixed with this patch.

---
 drivers/clk/tegra/clk-super.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
Quoted 15 lines

drivers/clk/tegra/clk-super.c static int clk_super_set_parent(struct clk_hw *hw, u8 index) · line 78

Quoted 11 lines
drivers/clk/tegra/clk-super.c +2 -0
index 7ad48a8..2fd924d 100644
@@ -73,7 +73,12 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
 {
        struct tegra_clk_super_mux *mux = to_clk_super_mux(hw);
        u32 val, state;
+       int err = 0;
        u8 parent_index, shift;
+       unsigned long flags = 0;

I don't think initializing flags to zero is necessary but it is not a big deal. Is gcc throwing a warning? Otherwise:

Yes. gcc throws a warning if it's not initialized.

Cheers,

Peter.

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Peter De Schrijver
Quoted 4 lines · Peter De Schrijver

Although tegra_clk_register_super_mux() has a lock parameter, the lock is not actually used by the code. Fixed with this patch.

Quoted 48 lines
---
  drivers/clk/tegra/clk-super.c |   18 +++++++++++++++---
  1 files changed, 15 insertions(+), 3 deletions(-)
drivers/clk/tegra/clk-super.c +15 -3
index 7ad48a8..2fd924d 100644
@@ -73,7 +73,12 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
  {
  	struct tegra_clk_super_mux *mux = to_clk_super_mux(hw);
  	u32 val, state;
+	int err = 0;
  	u8 parent_index, shift;
+	unsigned long flags = 0;
+
+	if (mux->lock)
+		spin_lock_irqsave(mux->lock, flags);
 
  	val = readl_relaxed(mux->reg);
  	state = val & SUPER_STATE_MASK;
@@ -92,8 +97,10 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
  					       (index == mux->pllx_index))) {
  		parent_index = clk_super_get_parent(hw);
  		if ((parent_index == mux->div2_index) ||
-		    (parent_index == mux->pllx_index))
-			return -EINVAL;
+		    (parent_index == mux->pllx_index)) {
+			err = -EINVAL;
+			goto out;
+		}
 
  		val ^= SUPER_LP_DIV2_BYPASS;
  		writel_relaxed(val, mux->reg);
@@ -107,7 +114,12 @@ static int clk_super_set_parent(struct clk_hw *hw, u8 index)
 
  	writel_relaxed(val, mux->reg);
  	udelay(2);
-	return 0;
+
+out:
+	if (mux->lock)
+		spin_unlock_irqrestore(mux->lock, flags);
+
+	return err;
  }
 
  const struct clk_ops tegra_clk_super_ops = {