All of lore.kernel.org
 help / color / mirror / Atom feed
* question about clk_hw_register_fixed_factor
@ 2016-09-20  6:15 Julia Lawall
  2016-09-20 17:31 ` Stephen Boyd
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2016-09-20  6:15 UTC (permalink / raw)
  To: mturquette, sboyd; +Cc: linux-clk, linux-kernel

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

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

* Re: question about clk_hw_register_fixed_factor
  2016-09-20  6:15 question about clk_hw_register_fixed_factor Julia Lawall
@ 2016-09-20 17:31 ` Stephen Boyd
  2016-09-20 17:32   ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Boyd @ 2016-09-20 17:31 UTC (permalink / raw)
  To: Julia Lawall; +Cc: mturquette, linux-clk, linux-kernel

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

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

* Re: question about clk_hw_register_fixed_factor
  2016-09-20 17:31 ` Stephen Boyd
@ 2016-09-20 17:32   ` Julia Lawall
  0 siblings, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2016-09-20 17:32 UTC (permalink / raw)
  To: Stephen Boyd; +Cc: mturquette, linux-clk, linux-kernel



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

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

end of thread, other threads:[~2016-09-20 17:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-20  6:15 question about clk_hw_register_fixed_factor Julia Lawall
2016-09-20 17:31 ` Stephen Boyd
2016-09-20 17:32   ` Julia Lawall

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.