Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Biju Das and committed by
Mark Brown
e21ac64e 9e6b3986

+8 -8
+8 -8
drivers/regulator/raa215300.c
··· 38 38 #define RAA215300_REG_BLOCK_EN_RTC_EN BIT(6) 39 39 #define RAA215300_RTC_DEFAULT_ADDR 0x6f 40 40 41 - static struct clk *clk; 42 - 43 41 static const struct regmap_config raa215300_regmap_config = { 44 42 .reg_bits = 8, 45 43 .val_bits = 8, ··· 47 49 static void raa215300_rtc_unregister_device(void *data) 48 50 { 49 51 i2c_unregister_device(data); 50 - if (!clk) { 51 - clk_unregister_fixed_rate(clk); 52 - clk = NULL; 53 - } 54 52 } 55 53 56 54 static int raa215300_clk_present(struct i2c_client *client, const char *name) ··· 124 130 u32 addr = RAA215300_RTC_DEFAULT_ADDR; 125 131 struct i2c_board_info info = {}; 126 132 struct i2c_client *rtc_client; 133 + struct clk_hw *hw; 127 134 ssize_t size; 128 135 129 - clk = clk_register_fixed_rate(NULL, clk_name, NULL, 0, 32000); 130 - clk_register_clkdev(clk, clk_name, NULL); 136 + hw = devm_clk_hw_register_fixed_rate(dev, clk_name, NULL, 0, 32000); 137 + if (IS_ERR(hw)) 138 + return PTR_ERR(hw); 139 + 140 + ret = devm_clk_hw_register_clkdev(dev, hw, clk_name, NULL); 141 + if (ret) 142 + return dev_err_probe(dev, ret, "Failed to initialize clkdev\n"); 131 143 132 144 if (np) { 133 145 int i;