hwmon: ads1015.c: Add of_node_put() before return
PATCH 1/1 hwmon: ads1015.c: Add of_node_put() before return
Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return in two places.
Issue found with Coccinelle.
Signed-off-by Nishka Dasgupta <[email protected]>
--- drivers/hwmon/ads1015.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/ads1015.c +2 -0
@@ -195,6 +195,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)if (pga >6 ) {dev_err (&client->dev,"invalid gain on %pOF\n" , node); +of_node_put (node);return -EINVAL ; } }
@@ -204,6 +205,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)if (data_rate >7 ) {dev_err (&client->dev,"invalid data_rate on %pOF\n" , node); +of_node_put (node);return -EINVAL ; } }
Signature · 1 line
2.19.1
Guenter Roeck
maintainerQuoted 7 lines · Nishka Dasgupta
Each iteration of
for_each_child_of_nodeputs the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add anof_node_putbefore the return in two places.
Issue found with Coccinelle.Signed-off-by Nishka Dasgupta <[email protected]>
The ads1015 driver is about to be removed from the hwmon subsystem in v5.4 (see https://patchwork.kernel.org/patch/11026555/), so I won't apply any cleanup patches to it.
Thanks,
Guenter
Quoted 24 lines
--- drivers/hwmon/ads1015.c | 2 ++ 1 file changed, 2 insertions(+)drivers/hwmon/ads1015.c +2
-0@@ -195,6 +195,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)if (pga >6 ) {dev_err (&client->dev,"invalid gain on %pOF\n" , node); +of_node_put (node);return -EINVAL ; } }@@ -204,6 +205,7 @@ static int ads1015_get_channels_config_of(struct i2c_client *client)if (data_rate >7 ) {dev_err (&client->dev,"invalid data_rate on %pOF\n" , node); +of_node_put (node);return -EINVAL ; } }