Skip to contentSkip to conversation

clk: mux: Return a sane value on error

PATCH In review Russ Dill 2 participants 2 messages Oct 21, 2013 – Oct 30, 2013 Common clk

lore
Share & tools
lore

Russ Dill

author
#0 lore raw

PATCH 1/1 clk: mux: Return a sane value on error

The get_parent op is defined as returning u8, but clk-mux is returning negative values on error. Code within drivers/clk/clk.c uses this return value as an index into an array which could cause an oops.

---
 drivers/clk/clk-mux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-mux.c +2 -2
index 4f96ff3..cc06015 100644
@@ -51,7 +51,7 @@ static u8 clk_mux_get_parent(struct clk_hw *hw)
 		for (i = 0; i < num_parents; i++)
 			if (mux->table[i] == val)
 				return i;
-		return -EINVAL;
+		return 0;
 	}
 
 	if (val && (mux->flags & CLK_MUX_INDEX_BIT))
@@ -61,7 +61,7 @@ static u8 clk_mux_get_parent(struct clk_hw *hw)
 		val--;
 
 	if (val >= num_parents)
-		return -EINVAL;
+		return 0;
 
 	return val;
 }
Signature · 1 line
1.8.3.2
#1 lore raw

Quoting Russ Dill (2013-10-21 01:59:50)

Quoted 6 lines

The get_parent op is defined as returning u8, but clk-mux is returning negative values on error. Code within drivers/clk/clk.c uses this return value as an index into an array which could cause an oops.

Hi Russ,

Thanks for the fix. Haojian Zhuang sent an identical fix the day before you so I took his in ;-)

Regards,
Mike

Quoted 28 lines
---
 drivers/clk/clk-mux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-mux.c +2 -2
index 4f96ff3..cc06015 100644
@@ -51,7 +51,7 @@ static u8 clk_mux_get_parent(struct clk_hw *hw)
                for (i = 0; i < num_parents; i++)
                        if (mux->table[i] == val)
                                return i;
-               return -EINVAL;
+               return 0;
        }
 
        if (val && (mux->flags & CLK_MUX_INDEX_BIT))
@@ -61,7 +61,7 @@ static u8 clk_mux_get_parent(struct clk_hw *hw)
                val--;
 
        if (val >= num_parents)
-               return -EINVAL;
+               return 0;
 
        return val;
 }
Signature · 1 line
1.8.3.2