[v5,2/8] clk: Warn if clk_init_data is not zero initialized
diff mbox series

Message ID 20190916161447.32715-3-manivannan.sadhasivam@linaro.org
State New
Headers show
Series
  • Add Bitmain BM1880 clock driver
Related show

Commit Message

Manivannan Sadhasivam Sept. 16, 2019, 4:14 p.m. UTC
The new implementation for determining parent map uses multiple ways
to pass parent info. The order in which it gets processed depends on
the first available member. Hence, it is necessary to zero init the
clk_init_data struct so that the expected member gets processed correctly.
So, add a warning if multiple clk_init_data members are available during
clk registration.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/clk/clk.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Stephen Boyd Sept. 17, 2019, 8:38 p.m. UTC | #1
Quoting Manivannan Sadhasivam (2019-09-16 09:14:41)
> The new implementation for determining parent map uses multiple ways
> to pass parent info. The order in which it gets processed depends on
> the first available member. Hence, it is necessary to zero init the
> clk_init_data struct so that the expected member gets processed correctly.
> So, add a warning if multiple clk_init_data members are available during
> clk registration.
> 
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  drivers/clk/clk.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index c0990703ce54..7d6d6984c979 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -3497,6 +3497,14 @@ static int clk_core_populate_parent_map(struct clk_core *core)
>         if (!num_parents)
>                 return 0;
>  
> +       /*
> +        * Check for non-zero initialized clk_init_data struct. This is
> +        * required because, we only require one of the (parent_names/
> +        * parent_data/parent_hws) to be set at a time. Otherwise, the
> +        * current code would use first available member.
> +        */
> +       WARN_ON((parent_names && parent_data) || (parent_names && parent_hws));
> +

This will warn for many drivers because they set clk_init_data on the
stack and assign parent_names but let junk from the stack be assigned to
parent_data. The code uses parent_names first and then looks for
parent_data or parent_hws because of this fact of life that we've never
required clk_init_data to be initialized to all zero.

>         /*
>          * Avoid unnecessary string look-ups of clk_core's possible parents by
>          * having a cache of names/clk_hw pointers to clk_core pointers.
Manivannan Sadhasivam Oct. 20, 2019, 3:25 p.m. UTC | #2
Hi Stephen,

On Tue, Sep 17, 2019 at 01:38:53PM -0700, Stephen Boyd wrote:
> Quoting Manivannan Sadhasivam (2019-09-16 09:14:41)
> > The new implementation for determining parent map uses multiple ways
> > to pass parent info. The order in which it gets processed depends on
> > the first available member. Hence, it is necessary to zero init the
> > clk_init_data struct so that the expected member gets processed correctly.
> > So, add a warning if multiple clk_init_data members are available during
> > clk registration.
> > 
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> >  drivers/clk/clk.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index c0990703ce54..7d6d6984c979 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -3497,6 +3497,14 @@ static int clk_core_populate_parent_map(struct clk_core *core)
> >         if (!num_parents)
> >                 return 0;
> >  
> > +       /*
> > +        * Check for non-zero initialized clk_init_data struct. This is
> > +        * required because, we only require one of the (parent_names/
> > +        * parent_data/parent_hws) to be set at a time. Otherwise, the
> > +        * current code would use first available member.
> > +        */
> > +       WARN_ON((parent_names && parent_data) || (parent_names && parent_hws));
> > +
> 
> This will warn for many drivers because they set clk_init_data on the
> stack and assign parent_names but let junk from the stack be assigned to
> parent_data.

Yes, I agree.

> The code uses parent_names first and then looks for
> parent_data or parent_hws because of this fact of life that we've never
> required clk_init_data to be initialized to all zero.
> 

Do you want me to just drop this patch or have any idea to make it better?

Thanks,
Mani

> >         /*
> >          * Avoid unnecessary string look-ups of clk_core's possible parents by
> >          * having a cache of names/clk_hw pointers to clk_core pointers.

Patch
diff mbox series

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index c0990703ce54..7d6d6984c979 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3497,6 +3497,14 @@  static int clk_core_populate_parent_map(struct clk_core *core)
 	if (!num_parents)
 		return 0;
 
+	/*
+	 * Check for non-zero initialized clk_init_data struct. This is
+	 * required because, we only require one of the (parent_names/
+	 * parent_data/parent_hws) to be set at a time. Otherwise, the
+	 * current code would use first available member.
+	 */
+	WARN_ON((parent_names && parent_data) || (parent_names && parent_hws));
+
 	/*
 	 * Avoid unnecessary string look-ups of clk_core's possible parents by
 	 * having a cache of names/clk_hw pointers to clk_core pointers.