2020-07-20 12:21:09

by Jing Xiangfeng

[permalink] [raw]
Subject: [PATCH] clk: ti: clkctrl: add the missed kfree() for _ti_omap4_clkctrl_setup()

_ti_omap4_clkctrl_setup() misses to call kfree() in an error path. Add
the missed function call to fix it.

Fixes: 6c3090520554 ("clk: ti: clkctrl: Fix hidden dependency to node name")
Signed-off-by: Jing Xiangfeng <[email protected]>
---
drivers/clk/ti/clkctrl.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/ti/clkctrl.c b/drivers/clk/ti/clkctrl.c
index 864c484bde1b..868e50132c21 100644
--- a/drivers/clk/ti/clkctrl.c
+++ b/drivers/clk/ti/clkctrl.c
@@ -655,8 +655,10 @@ static void __init _ti_omap4_clkctrl_setup(struct device_node *node)
}

hw = kzalloc(sizeof(*hw), GFP_KERNEL);
- if (!hw)
+ if (!hw) {
+ kfree(clkctrl_name);
return;
+ }

hw->enable_reg.ptr = provider->base + reg_data->offset;

--
2.17.1


2020-07-20 14:20:02

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH] clk: ti: clkctrl: add the missed kfree() for _ti_omap4_clkctrl_setup()


> +++ b/drivers/clk/ti/clkctrl.c
> @@ -655,8 +655,10 @@ static void __init _ti_omap4_clkctrl_setup(struct device_node *node)
> }
>
> hw = kzalloc(sizeof(*hw), GFP_KERNEL);
> - if (!hw)
> + if (!hw) {
> + kfree(clkctrl_name);
> return;
> + }


I suggest to use an additional label instead.

if (!hw)
- return;
+ goto free_control_name;


By the way:
How do you think about to replace the label “cleanup” by other jump targets
for better exception handling in this function implementation?

Regards,
Markus

2020-07-20 14:20:26

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH] clk: ti: clkctrl: add the missed kfree() for _ti_omap4_clkctrl_setup()


> +++ b/drivers/clk/ti/clkctrl.c
> @@ -655,8 +655,10 @@ static void __init _ti_omap4_clkctrl_setup(struct device_node *node)
> }
>
> hw = kzalloc(sizeof(*hw), GFP_KERNEL);
> - if (!hw)
> + if (!hw) {
> + kfree(clkctrl_name);
> return;
> + }


I suggest to use an additional label instead.

if (!hw)
- return;
+ goto free_control_name;


By the way:
How do you think about to replace the label “cleanup” by other jump targets
for better exception handling in this function implementation?

Regards,
Markus

2020-07-28 01:26:01

by Stephen Boyd

[permalink] [raw]
Subject: Re: [PATCH] clk: ti: clkctrl: add the missed kfree() for _ti_omap4_clkctrl_setup()

Quoting Jing Xiangfeng (2020-07-20 05:23:43)
> _ti_omap4_clkctrl_setup() misses to call kfree() in an error path. Add
> the missed function call to fix it.
>
> Fixes: 6c3090520554 ("clk: ti: clkctrl: Fix hidden dependency to node name")
> Signed-off-by: Jing Xiangfeng <[email protected]>
> ---
> drivers/clk/ti/clkctrl.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/ti/clkctrl.c b/drivers/clk/ti/clkctrl.c
> index 864c484bde1b..868e50132c21 100644
> --- a/drivers/clk/ti/clkctrl.c
> +++ b/drivers/clk/ti/clkctrl.c
> @@ -655,8 +655,10 @@ static void __init _ti_omap4_clkctrl_setup(struct device_node *node)
> }
>
> hw = kzalloc(sizeof(*hw), GFP_KERNEL);
> - if (!hw)
> + if (!hw) {
> + kfree(clkctrl_name);
> return;
> + }

Why not goto cleanup?

>
> hw->enable_reg.ptr = provider->base + reg_data->offset;
>
> --
> 2.17.1
>

2020-07-28 03:44:37

by Jing Xiangfeng

[permalink] [raw]
Subject: Re: [PATCH] clk: ti: clkctrl: add the missed kfree() for _ti_omap4_clkctrl_setup()



On 2020/7/28 9:24, Stephen Boyd wrote:
> Quoting Jing Xiangfeng (2020-07-20 05:23:43)
>> _ti_omap4_clkctrl_setup() misses to call kfree() in an error path. Add
>> the missed function call to fix it.
>>
>> Fixes: 6c3090520554 ("clk: ti: clkctrl: Fix hidden dependency to node name")
>> Signed-off-by: Jing Xiangfeng <[email protected]>
>> ---
>> drivers/clk/ti/clkctrl.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/clk/ti/clkctrl.c b/drivers/clk/ti/clkctrl.c
>> index 864c484bde1b..868e50132c21 100644
>> --- a/drivers/clk/ti/clkctrl.c
>> +++ b/drivers/clk/ti/clkctrl.c
>> @@ -655,8 +655,10 @@ static void __init _ti_omap4_clkctrl_setup(struct device_node *node)
>> }
>>
>> hw = kzalloc(sizeof(*hw), GFP_KERNEL);
>> - if (!hw)
>> + if (!hw) {
>> + kfree(clkctrl_name);
>> return;
>> + }
>
> Why not goto cleanup?

Thanks, I will change it as you suggested.

>
>>
>> hw->enable_reg.ptr = provider->base + reg_data->offset;
>>
>> --
>> 2.17.1
>>
> .
>