diff options
author | Biju Das <biju.das.jz@bp.renesas.com> | 2023-08-16 14:55:49 +0100 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2023-08-16 15:02:41 +0100 |
commit | e21ac64e669e960688e79bf5babeed63132dac8a (patch) | |
tree | bc87e6370785dc47ab939ad63c5b59d51f1f13c7 /drivers/regulator/raa215300.c | |
parent | 9e6b3986759b5e6d625d6e9e33bdae59f5ed48c1 (diff) | |
download | linux-stable-e21ac64e669e960688e79bf5babeed63132dac8a.tar.gz linux-stable-e21ac64e669e960688e79bf5babeed63132dac8a.tar.bz2 linux-stable-e21ac64e669e960688e79bf5babeed63132dac8a.zip |
regulator: raa215300: Fix resource leak in case of error
The clk_register_clkdev() allocates memory by calling vclkdev_alloc() and
this memory is not freed in the error path. Similarly, resources allocated
by clk_register_fixed_rate() are not freed in the error path.
Fix these issues by using devm_clk_hw_register_fixed_rate() and
devm_clk_hw_register_clkdev().
After this, the static variable clk is not needed. Replace it withÂ
local variable hw in probe() and drop calling clk_unregister_fixed_rate()
from raa215300_rtc_unregister_device().
Fixes: 7bce16630837 ("regulator: Add Renesas PMIC RAA215300 driver")
Cc: stable@kernel.org
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230816135550.146657-2-biju.das.jz@bp.renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator/raa215300.c')
-rw-r--r-- | drivers/regulator/raa215300.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/regulator/raa215300.c b/drivers/regulator/raa215300.c index 848a03a2fbd4..898f53cac02c 100644 --- a/drivers/regulator/raa215300.c +++ b/drivers/regulator/raa215300.c @@ -38,8 +38,6 @@ #define RAA215300_REG_BLOCK_EN_RTC_EN BIT(6) #define RAA215300_RTC_DEFAULT_ADDR 0x6f -static struct clk *clk; - static const struct regmap_config raa215300_regmap_config = { .reg_bits = 8, .val_bits = 8, @@ -49,10 +47,6 @@ static const struct regmap_config raa215300_regmap_config = { static void raa215300_rtc_unregister_device(void *data) { i2c_unregister_device(data); - if (!clk) { - clk_unregister_fixed_rate(clk); - clk = NULL; - } } static int raa215300_clk_present(struct i2c_client *client, const char *name) @@ -130,10 +124,16 @@ static int raa215300_i2c_probe(struct i2c_client *client) u32 addr = RAA215300_RTC_DEFAULT_ADDR; struct i2c_board_info info = {}; struct i2c_client *rtc_client; + struct clk_hw *hw; ssize_t size; - clk = clk_register_fixed_rate(NULL, clk_name, NULL, 0, 32000); - clk_register_clkdev(clk, clk_name, NULL); + hw = devm_clk_hw_register_fixed_rate(dev, clk_name, NULL, 0, 32000); + if (IS_ERR(hw)) + return PTR_ERR(hw); + + ret = devm_clk_hw_register_clkdev(dev, hw, clk_name, NULL); + if (ret) + return dev_err_probe(dev, ret, "Failed to initialize clkdev\n"); if (np) { int i; |