Message ID | 20190706132357.3185-1-nishkadg.linux@gmail.com (mailing list archive) |
---|---|
State | Rejected |
Headers | show |
Series | hwmon: ads1015.c: Add of_node_put() before return | expand |
On Sat, Jul 06, 2019 at 06:53:57PM +0530, Nishka Dasgupta wrote: > 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 <nishkadg.linux@gmail.com> 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 > --- > drivers/hwmon/ads1015.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c > index 3727a3762eb8..a0d62f6fa4b6 100644 > --- a/drivers/hwmon/ads1015.c > +++ b/drivers/hwmon/ads1015.c > @@ -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; > } > }
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c index 3727a3762eb8..a0d62f6fa4b6 100644 --- a/drivers/hwmon/ads1015.c +++ b/drivers/hwmon/ads1015.c @@ -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; } }
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 <nishkadg.linux@gmail.com> --- drivers/hwmon/ads1015.c | 2 ++ 1 file changed, 2 insertions(+)