Skip to content

Commit 5cc342d

Browse files
mhennerichgastmaier
authored andcommitted
iio: adc: ad9081: Use scoped iteration for child nodes
Convert all instances of for_each_child_of_node() to for_each_child_of_node_scoped() in the ad9081_parse_dt_tx() and ad9081_parse_dt_rx() functions. This ensures proper reference counting and automatic cleanup of child nodes, reducing the risk of memory leaks or dangling references. This change also removes redundant of_node_put() calls for child nodes, as for_each_child_of_node_scoped() handles cleanup automatically. Signed-off-by: Michael Hennerich <[email protected]> (cherry picked from commit 4642532)
1 parent 0f63d65 commit 5cc342d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

drivers/iio/adc/ad9081.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,7 +4187,7 @@ static void ad9081_dt_err(struct ad9081_phy *phy, const char *prop)
41874187

41884188
static int ad9081_parse_dt_tx(struct ad9081_phy *phy, struct device_node *np)
41894189
{
4190-
struct device_node *of_channels, *of_chan;
4190+
struct device_node *of_channels;
41914191
struct device_node *of_trx_path;
41924192
u32 reg, index, tmp, value;
41934193
bool has_long_time = false, has_long_thresh = false;
@@ -4240,7 +4240,7 @@ static int ad9081_parse_dt_tx(struct ad9081_phy *phy, struct device_node *np)
42404240
return ret;
42414241
}
42424242

4243-
for_each_child_of_node(of_channels, of_chan) {
4243+
for_each_child_of_node_scoped(of_channels, of_chan) {
42444244
ret = of_property_read_u32(of_chan, "reg", &reg);
42454245
if (!ret && (reg < ARRAY_SIZE(phy->tx_main_shift))) {
42464246
of_property_read_u64(of_chan,
@@ -4398,7 +4398,7 @@ static int ad9081_parse_dt_tx(struct ad9081_phy *phy, struct device_node *np)
43984398
return ret;
43994399
}
44004400

4401-
for_each_child_of_node(of_channels, of_chan) {
4401+
for_each_child_of_node_scoped(of_channels, of_chan) {
44024402
ret = of_property_read_u32(of_chan, "reg", &reg);
44034403
if (!ret && (reg < ARRAY_SIZE(phy->tx_chan_shift))) {
44044404
u32 val;
@@ -4439,7 +4439,7 @@ static int ad9081_parse_dt_tx(struct ad9081_phy *phy, struct device_node *np)
44394439
phy->jrx_link_watchdog_en = of_property_read_bool(of_channels,
44404440
"adi,jrx-link-watchdog-enable");
44414441

4442-
for_each_child_of_node(of_channels, of_chan) {
4442+
for_each_child_of_node_scoped(of_channels, of_chan) {
44434443
ret = of_property_read_u32(of_chan, "reg", &reg);
44444444
if (!ret && (reg < ARRAY_SIZE(phy->jrx_link_tx))) {
44454445
ad9081_parse_jesd_link_dt(phy, of_chan,
@@ -4448,7 +4448,6 @@ static int ad9081_parse_dt_tx(struct ad9081_phy *phy, struct device_node *np)
44484448
dev_err(&phy->spi->dev,
44494449
"Missing or invalid reg property in tx jesd-links node (%d)\n",
44504450
reg);
4451-
of_node_put(of_chan);
44524451
break;
44534452
}
44544453
}
@@ -4461,7 +4460,7 @@ static int ad9081_parse_dt_tx(struct ad9081_phy *phy, struct device_node *np)
44614460

44624461
static int ad9081_parse_dt_rx(struct ad9081_phy *phy, struct device_node *np)
44634462
{
4464-
struct device_node *of_channels, *of_chan;
4463+
struct device_node *of_channels;
44654464
struct device_node *of_trx_path;
44664465
u32 reg, tmp, nz;
44674466
int ret, i;
@@ -4498,7 +4497,7 @@ static int ad9081_parse_dt_rx(struct ad9081_phy *phy, struct device_node *np)
44984497
return -ENODEV;
44994498
}
45004499

4501-
for_each_child_of_node(of_channels, of_chan) {
4500+
for_each_child_of_node_scoped(of_channels, of_chan) {
45024501
ret = of_property_read_u32(of_chan, "reg", &reg);
45034502
if (!ret && (reg < ARRAY_SIZE(phy->tx_main_shift))) {
45044503
of_property_read_u64(of_chan,
@@ -4544,7 +4543,7 @@ static int ad9081_parse_dt_rx(struct ad9081_phy *phy, struct device_node *np)
45444543
return -ENODEV;
45454544
}
45464545

4547-
for_each_child_of_node(of_channels, of_chan) {
4546+
for_each_child_of_node_scoped(of_channels, of_chan) {
45484547
ret = of_property_read_u32(of_chan, "reg", &reg);
45494548
if (!ret && (reg < ARRAY_SIZE(phy->rx_fddc_shift))) {
45504549
u32 mode;
@@ -4613,7 +4612,7 @@ static int ad9081_parse_dt_rx(struct ad9081_phy *phy, struct device_node *np)
46134612
phy->ad9081.serdes_info.ser_settings.lane_settings[i].post_emp_setting =
46144613
lane_cfg[i];
46154614

4616-
for_each_child_of_node(of_channels, of_chan) {
4615+
for_each_child_of_node_scoped(of_channels, of_chan) {
46174616
ret = of_property_read_u32(of_chan, "reg", &reg);
46184617
if (!ret && (reg < ARRAY_SIZE(phy->jtx_link_rx))) {
46194618
ad9081_parse_jesd_link_dt(phy, of_chan,
@@ -4622,7 +4621,6 @@ static int ad9081_parse_dt_rx(struct ad9081_phy *phy, struct device_node *np)
46224621
dev_err(&phy->spi->dev,
46234622
"Missing or invalid reg property in rx jesd-links node (%d)\n",
46244623
reg);
4625-
of_node_put(of_chan);
46264624
break;
46274625
}
46284626
}

0 commit comments

Comments
 (0)