2021-10-18 12:17:55

by Jiabing Wan

[permalink] [raw]
Subject: [PATCH] hwmon: (tmp421) Add of_node_put() before return

Fix following coccicheck warning:
./drivers/hwmon/tmp421.c:416:1-23: WARNING: Function
for_each_child_of_node should have of_node_put() before return.

Early exits from for_each_child_of_node should decrement the
node reference counter.

Signed-off-by: Wan Jiabing <[email protected]>
---
drivers/hwmon/tmp421.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index 31e95b5749c8..1fd8d41d90c8 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -418,8 +418,10 @@ static int tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *d
continue;

err = tmp421_probe_child_from_dt(client, child, data);
- if (err)
+ if (err) {
+ of_node_put(child);
return err;
+ }
}

return 0;
--
2.20.1


2021-10-18 14:25:40

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH] hwmon: (tmp421) Add of_node_put() before return

On Mon, Oct 18, 2021 at 08:15:37AM -0400, Wan Jiabing wrote:
> Fix following coccicheck warning:
> ./drivers/hwmon/tmp421.c:416:1-23: WARNING: Function
> for_each_child_of_node should have of_node_put() before return.
>
> Early exits from for_each_child_of_node should decrement the
> node reference counter.
>
> Signed-off-by: Wan Jiabing <[email protected]>

Applied.

Thanks,
Guenter

> ---
> drivers/hwmon/tmp421.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
> index 31e95b5749c8..1fd8d41d90c8 100644
> --- a/drivers/hwmon/tmp421.c
> +++ b/drivers/hwmon/tmp421.c
> @@ -418,8 +418,10 @@ static int tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *d
> continue;
>
> err = tmp421_probe_child_from_dt(client, child, data);
> - if (err)
> + if (err) {
> + of_node_put(child);
> return err;
> + }
> }
>
> return 0;