All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: mux: fix the return value of get_parent
@ 2013-10-20  7:48 Haojian Zhuang
  2013-10-30 19:46 ` Mike Turquette
  0 siblings, 1 reply; 2+ messages in thread
From: Haojian Zhuang @ 2013-10-20  7:48 UTC (permalink / raw)
  To: linux-kernel, mturquette; +Cc: patches, Haojian Zhuang

If there're no parents on the clock mux node, it should return 0, not an
errnor code.

The orphan clock node is using get_parent() to get the index of its
parents in__clk_init(). If the return value is negative, it'll be
transformed to a u8 value (clk_mux_get_parent()). Then the orphan clock
node tries to get its parent with the invalid index. It will only cause
accessing memory beyond border.

Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
---
 drivers/clk/clk-mux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index 4f96ff3..cc06015 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -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;
 }
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] clk: mux: fix the return value of get_parent
  2013-10-20  7:48 [PATCH] clk: mux: fix the return value of get_parent Haojian Zhuang
@ 2013-10-30 19:46 ` Mike Turquette
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Turquette @ 2013-10-30 19:46 UTC (permalink / raw)
  To: Haojian Zhuang, linux-kernel; +Cc: patches, Haojian Zhuang

Quoting Haojian Zhuang (2013-10-20 00:48:55)
> If there're no parents on the clock mux node, it should return 0, not an
> errnor code.
> 
> The orphan clock node is using get_parent() to get the index of its
> parents in__clk_init(). If the return value is negative, it'll be
> transformed to a u8 value (clk_mux_get_parent()). Then the orphan clock
> node tries to get its parent with the invalid index. It will only cause
> accessing memory beyond border.
> 
> Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>

Taken into clk-next.

Thanks!
Mike

> ---
>  drivers/clk/clk-mux.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
> index 4f96ff3..cc06015 100644
> --- a/drivers/clk/clk-mux.c
> +++ b/drivers/clk/clk-mux.c
> @@ -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;
>  }
> -- 
> 1.8.1.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-30 19:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-20  7:48 [PATCH] clk: mux: fix the return value of get_parent Haojian Zhuang
2013-10-30 19:46 ` Mike Turquette

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.