Commit 0214f33c authored by Stephen Boyd's avatar Stephen Boyd

clk: Overwrite clk_hw::init with NULL during clk_register()

We don't want clk provider drivers to use the init structure after clk
registration time, but we leave a dangling reference to it by means of
clk_hw::init. Let's overwrite the member with NULL during clk_register()
so that this can't be used anymore after registration time.

Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Doug Anderson <dianders@chromium.org>
Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
Link: https://lkml.kernel.org/r/20190731193517.237136-10-sboyd@kernel.orgReviewed-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
parent a7b85ad2
...@@ -3484,9 +3484,9 @@ static int clk_cpy_name(const char **dst_p, const char *src, bool must_exist) ...@@ -3484,9 +3484,9 @@ static int clk_cpy_name(const char **dst_p, const char *src, bool must_exist)
return 0; return 0;
} }
static int clk_core_populate_parent_map(struct clk_core *core) static int clk_core_populate_parent_map(struct clk_core *core,
const struct clk_init_data *init)
{ {
const struct clk_init_data *init = core->hw->init;
u8 num_parents = init->num_parents; u8 num_parents = init->num_parents;
const char * const *parent_names = init->parent_names; const char * const *parent_names = init->parent_names;
const struct clk_hw **parent_hws = init->parent_hws; const struct clk_hw **parent_hws = init->parent_hws;
...@@ -3566,6 +3566,14 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) ...@@ -3566,6 +3566,14 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw)
{ {
int ret; int ret;
struct clk_core *core; struct clk_core *core;
const struct clk_init_data *init = hw->init;
/*
* The init data is not supposed to be used outside of registration path.
* Set it to NULL so that provider drivers can't use it either and so that
* we catch use of hw->init early on in the core.
*/
hw->init = NULL;
core = kzalloc(sizeof(*core), GFP_KERNEL); core = kzalloc(sizeof(*core), GFP_KERNEL);
if (!core) { if (!core) {
...@@ -3573,17 +3581,17 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) ...@@ -3573,17 +3581,17 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw)
goto fail_out; goto fail_out;
} }
core->name = kstrdup_const(hw->init->name, GFP_KERNEL); core->name = kstrdup_const(init->name, GFP_KERNEL);
if (!core->name) { if (!core->name) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail_name; goto fail_name;
} }
if (WARN_ON(!hw->init->ops)) { if (WARN_ON(!init->ops)) {
ret = -EINVAL; ret = -EINVAL;
goto fail_ops; goto fail_ops;
} }
core->ops = hw->init->ops; core->ops = init->ops;
if (dev && pm_runtime_enabled(dev)) if (dev && pm_runtime_enabled(dev))
core->rpm_enabled = true; core->rpm_enabled = true;
...@@ -3592,13 +3600,13 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) ...@@ -3592,13 +3600,13 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw)
if (dev && dev->driver) if (dev && dev->driver)
core->owner = dev->driver->owner; core->owner = dev->driver->owner;
core->hw = hw; core->hw = hw;
core->flags = hw->init->flags; core->flags = init->flags;
core->num_parents = hw->init->num_parents; core->num_parents = init->num_parents;
core->min_rate = 0; core->min_rate = 0;
core->max_rate = ULONG_MAX; core->max_rate = ULONG_MAX;
hw->core = core; hw->core = core;
ret = clk_core_populate_parent_map(core); ret = clk_core_populate_parent_map(core, init);
if (ret) if (ret)
goto fail_parents; goto fail_parents;
......
...@@ -299,7 +299,8 @@ struct clk_init_data { ...@@ -299,7 +299,8 @@ struct clk_init_data {
* into the clk API * into the clk API
* *
* @init: pointer to struct clk_init_data that contains the init data shared * @init: pointer to struct clk_init_data that contains the init data shared
* with the common clock framework. * with the common clock framework. This pointer will be set to NULL once
* a clk_register() variant is called on this clk_hw pointer.
*/ */
struct clk_hw { struct clk_hw {
struct clk_core *core; struct clk_core *core;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment