From e087a19247d7dec35eae92a3d2f3d42bf25b427d Mon Sep 17 00:00:00 2001 From: David Collins Date: Wed, 27 Mar 2019 15:38:10 -0700 Subject: [PATCH] clk: avoid returning local variable pointers during clock registration Several clock drivers initialize the clk_hw init element to a local variable before calling [devm_]clk_hw_register() on it. This style is fine. However, the init pointer value becomes invalid as soon as the registration function returns. Clear the init pointer to avoid the possibility of accessing an invalid memory address after registration completes. Change-Id: I3ae72c2c7ebc30e443c7034d072591827f4342aa Signed-off-by: David Collins --- drivers/clk/clk-divider.c | 1 + drivers/clk/clk-fixed-factor.c | 1 + drivers/clk/clk-fixed-rate.c | 1 + drivers/clk/clk-fractional-divider.c | 1 + drivers/clk/clk-gate.c | 1 + drivers/clk/clk-gpio.c | 2 +- drivers/clk/clk-mux.c | 1 + 7 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 1521b7906a6e..d7780262ebdc 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -510,6 +510,7 @@ static struct clk_hw *_register_divider(struct device *dev, const char *name, /* register the clock */ hw = &div->hw; ret = clk_hw_register(dev, hw); + hw->init = NULL; if (ret) { kfree(div); hw = ERR_PTR(ret); diff --git a/drivers/clk/clk-fixed-factor.c b/drivers/clk/clk-fixed-factor.c index 8b343e59dc61..623522cbc187 100644 --- a/drivers/clk/clk-fixed-factor.c +++ b/drivers/clk/clk-fixed-factor.c @@ -98,6 +98,7 @@ __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np, ret = clk_hw_register(dev, hw); else ret = of_clk_hw_register(np, hw); + hw->init = NULL; if (ret) { kfree(fix); hw = ERR_PTR(ret); diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c index a7e4aef7a376..6844e177acb8 100644 --- a/drivers/clk/clk-fixed-rate.c +++ b/drivers/clk/clk-fixed-rate.c @@ -80,6 +80,7 @@ struct clk_hw *clk_hw_register_fixed_rate_with_accuracy(struct device *dev, /* register the clock */ hw = &fixed->hw; ret = clk_hw_register(dev, hw); + hw->init = NULL; if (ret) { kfree(fixed); hw = ERR_PTR(ret); diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index b1e556f20911..d071fc63ba8f 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -185,6 +185,7 @@ struct clk_hw *clk_hw_register_fractional_divider(struct device *dev, hw = &fd->hw; ret = clk_hw_register(dev, hw); + hw->init = NULL; if (ret) { kfree(fd); hw = ERR_PTR(ret); diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c index 1b99fc962745..40ce3fa093d7 100644 --- a/drivers/clk/clk-gate.c +++ b/drivers/clk/clk-gate.c @@ -171,6 +171,7 @@ struct clk_hw *clk_hw_register_gate(struct device *dev, const char *name, hw = &gate->hw; ret = clk_hw_register(dev, hw); + hw->init = NULL; if (ret) { kfree(gate); hw = ERR_PTR(ret); diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c index 9d930edd6516..8147c66ad9ad 100644 --- a/drivers/clk/clk-gpio.c +++ b/drivers/clk/clk-gpio.c @@ -149,7 +149,7 @@ static struct clk_hw *clk_register_gpio(struct device *dev, const char *name, err = devm_clk_hw_register(dev, hw); else err = clk_hw_register(NULL, hw); - + hw->init = NULL; if (!err) return hw; diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c index 66e91f740508..23d41798883c 100644 --- a/drivers/clk/clk-mux.c +++ b/drivers/clk/clk-mux.c @@ -190,6 +190,7 @@ struct clk_hw *clk_hw_register_mux_table(struct device *dev, const char *name, hw = &mux->hw; ret = clk_hw_register(dev, hw); + hw->init = NULL; if (ret) { kfree(mux); hw = ERR_PTR(ret);