Skip to contentSkip to conversation

hwmon: ads1015.c: Add of_node_put() before return

PATCH In review Nishka Dasgupta 2 participants 2 messages Jul 6, 2019 – Jul 8, 2019 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

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.

---
 drivers/hwmon/ads1015.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hwmon/ads1015.c +2 -0
index 3727a3762eb8..a0d62f6fa4b6 100644
@@ -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
maintainer
#1 lore raw
Quoted 7 lines · Nishka Dasgupta

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.

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
index 3727a3762eb8..a0d62f6fa4b6 100644
@@ -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;
 			}
 		}