Skip to contentSkip to conversation

question about clk_hw_register_fixed_factor

DISCUSSION Julia Lawall 2 participants 3 messages Sep 20, 2016 Common clk

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 13 lines · Julia Lawall

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;

Quoted 4 lines

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.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw
Quoted 19 lines · Stephen Boyd
Quoted 13 lines · Julia Lawall

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;

Quoted 4 lines

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?

Quoted 9 lines

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