Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1487082 > unrolled thread

question about clk_hw_register_fixed_factor

Started byJulia Lawall <julia.lawall@lip6.fr>
First post2016-09-20 08:20 +0200
Last post2016-09-20 19:40 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  question about clk_hw_register_fixed_factor Julia Lawall <julia.lawall@lip6.fr> - 2016-09-20 08:20 +0200
    Re: question about clk_hw_register_fixed_factor Stephen Boyd <sboyd@codeaurora.org> - 2016-09-20 19:40 +0200
      Re: question about clk_hw_register_fixed_factor Julia Lawall <julia.lawall@lip6.fr> - 2016-09-20 19:40 +0200

#1487082 — question about clk_hw_register_fixed_factor

FromJulia Lawall <julia.lawall@lip6.fr>
Date2016-09-20 08:20 +0200
Subjectquestion about clk_hw_register_fixed_factor
Message-ID<sjmzn-7Jp-7@gated-at.bofh.it>
Hello,

The function clk_hw_register_fixed_factor from
drivers/clk/clk-fixed-factor.c contains:

struct clk_init_data init;
...
fix->hw.init = &init;
...
hw = &fix->hw;
...
return hw;

It looks like hw would then contain a dangling pointer, to init.  Should
this be nulled out, or does it not matter because it is certain that no
one will look at it anyway?  Or did I miss a null assignment elsewhere?

thanks,
julia

[toc] | [next] | [standalone]


#1487538

FromStephen Boyd <sboyd@codeaurora.org>
Date2016-09-20 19:40 +0200
Message-ID<sjxbr-61r-1@gated-at.bofh.it>
In reply to#1487082
On 09/20, Julia Lawall wrote:
> Hello,
> 
> The function clk_hw_register_fixed_factor from
> drivers/clk/clk-fixed-factor.c contains:
> 
> struct clk_init_data init;
> ...
> fix->hw.init = &init;
> ...
> hw = &fix->hw;
> ...
> return hw;
> 
> It looks like hw would then contain a dangling pointer, to init.  Should
> this be nulled out, or does it not matter because it is certain that no
> one will look at it anyway?  Or did I miss a null assignment elsewhere?
> 

Yes this is a common pattern in clk drivers. The init structure
is not used after clk_register() (or its variants) is called, so
there will typically be a dangling pointer in clk_hw to the
clk_init_data structure. Sometimes that structure is allocated on
the stack, which leads to other problems like people forgetting
to initialize all the members. Usually they forgot to set flags
to something and then clk framework does very odd things. We
could null out the init pointer if we really cared, but so far
this hasn't been a problem.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

[toc] | [prev] | [next] | [standalone]


#1487542

FromJulia Lawall <julia.lawall@lip6.fr>
Date2016-09-20 19:40 +0200
Message-ID<sjxbr-61r-17@gated-at.bofh.it>
In reply to#1487538

On Tue, 20 Sep 2016, Stephen Boyd wrote:

> On 09/20, Julia Lawall wrote:
> > Hello,
> >
> > The function clk_hw_register_fixed_factor from
> > drivers/clk/clk-fixed-factor.c contains:
> >
> > struct clk_init_data init;
> > ...
> > fix->hw.init = &init;
> > ...
> > hw = &fix->hw;
> > ...
> > return hw;
> >
> > It looks like hw would then contain a dangling pointer, to init.  Should
> > this be nulled out, or does it not matter because it is certain that no
> > one will look at it anyway?  Or did I miss a null assignment elsewhere?
> >
>
> Yes this is a common pattern in clk drivers. The init structure
> is not used after clk_register() (or its variants) is called, so
> there will typically be a dangling pointer in clk_hw to the
> clk_init_data structure. Sometimes that structure is allocated on
> the stack, which leads to other problems like people forgetting
> to initialize all the members. Usually they forgot to set flags
> to something and then clk framework does very odd things. We
> could null out the init pointer if we really cared, but so far
> this hasn't been a problem.

OK, thanks for the clarification.

julia

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web