diff mbox series

[RESEND,2/2] thermal: sprd: add missing of_node_put for loop iteration

Message ID 20210528115036.18222-2-krzysztof.kozlowski@canonical.com (mailing list archive)
State New, archived
Headers show
Series [RESEND,1/2] thermal: imx_sc: add missing of_node_put for loop iteration | expand

Commit Message

Krzysztof Kozlowski May 28, 2021, 11:50 a.m. UTC
Early exits from for_each_available_child_of_node() should decrement the
node reference counter.  Reported by Coccinelle:

  drivers/thermal/sprd_thermal.c:387:1-23: WARNING:
    Function "for_each_child_of_node" should have of_node_put() before goto around lines 391.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Acked-by: Chunyan Zhang <zhang.lyra@gmail.com>
---
 drivers/thermal/sprd_thermal.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Daniel Lezcano June 14, 2021, 5:28 p.m. UTC | #1
On 28/05/2021 13:50, Krzysztof Kozlowski wrote:
> Early exits from for_each_available_child_of_node() should decrement the
> node reference counter.  Reported by Coccinelle:
> 
>   drivers/thermal/sprd_thermal.c:387:1-23: WARNING:
>     Function "for_each_child_of_node" should have of_node_put() before goto around lines 391.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
> Acked-by: Chunyan Zhang <zhang.lyra@gmail.com>
> ---
>  drivers/thermal/sprd_thermal.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c
> index 3682edb2f466..2778971aaf03 100644
> --- a/drivers/thermal/sprd_thermal.c
> +++ b/drivers/thermal/sprd_thermal.c
> @@ -388,6 +388,7 @@ static int sprd_thm_probe(struct platform_device *pdev)
>  		sen = devm_kzalloc(&pdev->dev, sizeof(*sen), GFP_KERNEL);
>  		if (!sen) {
>  			ret = -ENOMEM;
> +			of_node_put(sen_child);

Why not a new label for the rollback routine?

eg. goto out_of_node_put;

Or a new function devm_for_each_available_child_of_node() ?

>  			goto disable_clk;
>  		}
>  
> @@ -397,12 +398,14 @@ static int sprd_thm_probe(struct platform_device *pdev)
>  		ret = of_property_read_u32(sen_child, "reg", &sen->id);
>  		if (ret) {
>  			dev_err(&pdev->dev, "get sensor reg failed");
> +			of_node_put(sen_child);
>  			goto disable_clk;
>  		}
>  
>  		ret = sprd_thm_sensor_calibration(sen_child, thm, sen);
>  		if (ret) {
>  			dev_err(&pdev->dev, "efuse cal analysis failed");
> +			of_node_put(sen_child);
>  			goto disable_clk;
>  		}
>  
> @@ -416,6 +419,7 @@ static int sprd_thm_probe(struct platform_device *pdev)
>  			dev_err(&pdev->dev, "register thermal zone failed %d\n",
>  				sen->id);
>  			ret = PTR_ERR(sen->tzd);
> +			of_node_put(sen_child);
>  			goto disable_clk;
>  		}
>  
>
Krzysztof Kozlowski June 14, 2021, 7:16 p.m. UTC | #2
On 14/06/2021 19:28, Daniel Lezcano wrote:
> On 28/05/2021 13:50, Krzysztof Kozlowski wrote:
>> Early exits from for_each_available_child_of_node() should decrement the
>> node reference counter.  Reported by Coccinelle:
>>
>>   drivers/thermal/sprd_thermal.c:387:1-23: WARNING:
>>     Function "for_each_child_of_node" should have of_node_put() before goto around lines 391.
>>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
>> Acked-by: Chunyan Zhang <zhang.lyra@gmail.com>
>> ---
>>  drivers/thermal/sprd_thermal.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c
>> index 3682edb2f466..2778971aaf03 100644
>> --- a/drivers/thermal/sprd_thermal.c
>> +++ b/drivers/thermal/sprd_thermal.c
>> @@ -388,6 +388,7 @@ static int sprd_thm_probe(struct platform_device *pdev)
>>  		sen = devm_kzalloc(&pdev->dev, sizeof(*sen), GFP_KERNEL);
>>  		if (!sen) {
>>  			ret = -ENOMEM;
>> +			of_node_put(sen_child);
> 
> Why not a new label for the rollback routine?
> 
> eg. goto out_of_node_put;

Indeed, this should work. When loops end, the sen_child is set to NULL
so of_node_putting it should be fine.

> 
> Or a new function devm_for_each_available_child_of_node() ?

Since there are multiple flavors of this for_each_loop, that might be
too much...


Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c
index 3682edb2f466..2778971aaf03 100644
--- a/drivers/thermal/sprd_thermal.c
+++ b/drivers/thermal/sprd_thermal.c
@@ -388,6 +388,7 @@  static int sprd_thm_probe(struct platform_device *pdev)
 		sen = devm_kzalloc(&pdev->dev, sizeof(*sen), GFP_KERNEL);
 		if (!sen) {
 			ret = -ENOMEM;
+			of_node_put(sen_child);
 			goto disable_clk;
 		}
 
@@ -397,12 +398,14 @@  static int sprd_thm_probe(struct platform_device *pdev)
 		ret = of_property_read_u32(sen_child, "reg", &sen->id);
 		if (ret) {
 			dev_err(&pdev->dev, "get sensor reg failed");
+			of_node_put(sen_child);
 			goto disable_clk;
 		}
 
 		ret = sprd_thm_sensor_calibration(sen_child, thm, sen);
 		if (ret) {
 			dev_err(&pdev->dev, "efuse cal analysis failed");
+			of_node_put(sen_child);
 			goto disable_clk;
 		}
 
@@ -416,6 +419,7 @@  static int sprd_thm_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev, "register thermal zone failed %d\n",
 				sen->id);
 			ret = PTR_ERR(sen->tzd);
+			of_node_put(sen_child);
 			goto disable_clk;
 		}