Skip to content

Commit e21ac64

Browse files
bijudasbroonie
authored andcommitted
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: 7bce166 ("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>
1 parent 9e6b398 commit e21ac64

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/regulator/raa215300.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
#define RAA215300_REG_BLOCK_EN_RTC_EN BIT(6)
3939
#define RAA215300_RTC_DEFAULT_ADDR 0x6f
4040

41-
static struct clk *clk;
42-
4341
static const struct regmap_config raa215300_regmap_config = {
4442
.reg_bits = 8,
4543
.val_bits = 8,
@@ -49,10 +47,6 @@ static const struct regmap_config raa215300_regmap_config = {
4947
static void raa215300_rtc_unregister_device(void *data)
5048
{
5149
i2c_unregister_device(data);
52-
if (!clk) {
53-
clk_unregister_fixed_rate(clk);
54-
clk = NULL;
55-
}
5650
}
5751

5852
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)
130124
u32 addr = RAA215300_RTC_DEFAULT_ADDR;
131125
struct i2c_board_info info = {};
132126
struct i2c_client *rtc_client;
127+
struct clk_hw *hw;
133128
ssize_t size;
134129

135-
clk = clk_register_fixed_rate(NULL, clk_name, NULL, 0, 32000);
136-
clk_register_clkdev(clk, clk_name, NULL);
130+
hw = devm_clk_hw_register_fixed_rate(dev, clk_name, NULL, 0, 32000);
131+
if (IS_ERR(hw))
132+
return PTR_ERR(hw);
133+
134+
ret = devm_clk_hw_register_clkdev(dev, hw, clk_name, NULL);
135+
if (ret)
136+
return dev_err_probe(dev, ret, "Failed to initialize clkdev\n");
137137

138138
if (np) {
139139
int i;

0 commit comments

Comments
 (0)