Skip to content

Commit

Permalink
iio: frequency: adf4371: fix possible leak
Browse files Browse the repository at this point in the history
When returning early from a device_for_each_child_node() loop, we need
to call fwnode_handle_put() on the child node so it does not leak. For
that make use of device_for_each_child_node_scoped() which will
automatically drop the node reference as soon as go out of the loop
scope.

Fixes: c8e6b34 ("iio: frequency: adf4371: Introduce channel child nodes")
Signed-off-by: Nuno Sa <[email protected]>
  • Loading branch information
nunojsa committed Oct 10, 2024
1 parent f313cf0 commit 0cf8b29
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/iio/frequency/adf4371.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/gcd.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/sysfs.h>
#include <linux/spi/spi.h>
Expand Down Expand Up @@ -1077,7 +1078,6 @@ static int adf4371_parse_dt(struct adf4371_state *st)
{
unsigned char num_channels;
unsigned int channel, tmp;
struct fwnode_handle *child;
int ret, i;

if(device_property_read_bool(&st->spi->dev, "adi,spi-3wire-enable"))
Expand Down Expand Up @@ -1147,7 +1147,7 @@ static int adf4371_parse_dt(struct adf4371_state *st)
if (num_channels > st->chip_info->num_channels)
return -EINVAL;

device_for_each_child_node(&st->spi->dev, child) {
device_for_each_child_node_scoped(&st->spi->dev, child) {
ret = fwnode_property_read_u32(child, "reg", &channel);
if (ret)
return ret;
Expand Down

0 comments on commit 0cf8b29

Please sign in to comment.