Commit 1693d2a7 authored by Jonathan Cameron's avatar Jonathan Cameron

iio: adc: max11410: Use device_for_each_child_node_scoped()

Switching to the _scoped() version removes the need for manual
calling of fwnode_handle_put() in the paths where the code
exits the loop early. In this case that's all in error paths.
Reviewed-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20240217164249.921878-6-jic23@kernel.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 365130fd
...@@ -696,7 +696,6 @@ static int max11410_parse_channels(struct max11410_state *st, ...@@ -696,7 +696,6 @@ static int max11410_parse_channels(struct max11410_state *st,
struct device *dev = &st->spi_dev->dev; struct device *dev = &st->spi_dev->dev;
struct max11410_channel_config *cfg; struct max11410_channel_config *cfg;
struct iio_chan_spec *channels; struct iio_chan_spec *channels;
struct fwnode_handle *child;
u32 reference, sig_path; u32 reference, sig_path;
const char *node_name; const char *node_name;
u32 inputs[2], scale; u32 inputs[2], scale;
...@@ -720,7 +719,7 @@ static int max11410_parse_channels(struct max11410_state *st, ...@@ -720,7 +719,7 @@ static int max11410_parse_channels(struct max11410_state *st,
if (!st->channels) if (!st->channels)
return -ENOMEM; return -ENOMEM;
device_for_each_child_node(dev, child) { device_for_each_child_node_scoped(dev, child) {
node_name = fwnode_get_name(child); node_name = fwnode_get_name(child);
if (fwnode_property_present(child, "diff-channels")) { if (fwnode_property_present(child, "diff-channels")) {
ret = fwnode_property_read_u32_array(child, ret = fwnode_property_read_u32_array(child,
...@@ -735,47 +734,37 @@ static int max11410_parse_channels(struct max11410_state *st, ...@@ -735,47 +734,37 @@ static int max11410_parse_channels(struct max11410_state *st,
inputs[1] = 0; inputs[1] = 0;
chanspec.differential = 0; chanspec.differential = 0;
} }
if (ret) { if (ret)
fwnode_handle_put(child);
return ret; return ret;
}
if (inputs[0] > MAX11410_CHANNEL_INDEX_MAX || if (inputs[0] > MAX11410_CHANNEL_INDEX_MAX ||
inputs[1] > MAX11410_CHANNEL_INDEX_MAX) { inputs[1] > MAX11410_CHANNEL_INDEX_MAX)
fwnode_handle_put(child);
return dev_err_probe(&indio_dev->dev, -EINVAL, return dev_err_probe(&indio_dev->dev, -EINVAL,
"Invalid channel index for %s, should be less than %d\n", "Invalid channel index for %s, should be less than %d\n",
node_name, node_name,
MAX11410_CHANNEL_INDEX_MAX + 1); MAX11410_CHANNEL_INDEX_MAX + 1);
}
cfg = &st->channels[chan_idx]; cfg = &st->channels[chan_idx];
reference = MAX11410_REFSEL_AVDD_AGND; reference = MAX11410_REFSEL_AVDD_AGND;
fwnode_property_read_u32(child, "adi,reference", &reference); fwnode_property_read_u32(child, "adi,reference", &reference);
if (reference > MAX11410_REFSEL_MAX) { if (reference > MAX11410_REFSEL_MAX)
fwnode_handle_put(child);
return dev_err_probe(&indio_dev->dev, -EINVAL, return dev_err_probe(&indio_dev->dev, -EINVAL,
"Invalid adi,reference value for %s, should be less than %d.\n", "Invalid adi,reference value for %s, should be less than %d.\n",
node_name, MAX11410_REFSEL_MAX + 1); node_name, MAX11410_REFSEL_MAX + 1);
}
if (!max11410_get_vrefp(st, reference) || if (!max11410_get_vrefp(st, reference) ||
(!max11410_get_vrefn(st, reference) && reference <= 2)) { (!max11410_get_vrefn(st, reference) && reference <= 2))
fwnode_handle_put(child);
return dev_err_probe(&indio_dev->dev, -EINVAL, return dev_err_probe(&indio_dev->dev, -EINVAL,
"Invalid VREF configuration for %s, either specify corresponding VREF regulators or change adi,reference property.\n", "Invalid VREF configuration for %s, either specify corresponding VREF regulators or change adi,reference property.\n",
node_name); node_name);
}
sig_path = MAX11410_PGA_SIG_PATH_BUFFERED; sig_path = MAX11410_PGA_SIG_PATH_BUFFERED;
fwnode_property_read_u32(child, "adi,input-mode", &sig_path); fwnode_property_read_u32(child, "adi,input-mode", &sig_path);
if (sig_path > MAX11410_SIG_PATH_MAX) { if (sig_path > MAX11410_SIG_PATH_MAX)
fwnode_handle_put(child);
return dev_err_probe(&indio_dev->dev, -EINVAL, return dev_err_probe(&indio_dev->dev, -EINVAL,
"Invalid adi,input-mode value for %s, should be less than %d.\n", "Invalid adi,input-mode value for %s, should be less than %d.\n",
node_name, MAX11410_SIG_PATH_MAX + 1); node_name, MAX11410_SIG_PATH_MAX + 1);
}
fwnode_property_read_u32(child, "settling-time-us", fwnode_property_read_u32(child, "settling-time-us",
&cfg->settling_time_us); &cfg->settling_time_us);
...@@ -793,10 +782,8 @@ static int max11410_parse_channels(struct max11410_state *st, ...@@ -793,10 +782,8 @@ static int max11410_parse_channels(struct max11410_state *st,
cfg->scale_avail = devm_kcalloc(dev, MAX11410_SCALE_AVAIL_SIZE * 2, cfg->scale_avail = devm_kcalloc(dev, MAX11410_SCALE_AVAIL_SIZE * 2,
sizeof(*cfg->scale_avail), sizeof(*cfg->scale_avail),
GFP_KERNEL); GFP_KERNEL);
if (!cfg->scale_avail) { if (!cfg->scale_avail)
fwnode_handle_put(child);
return -ENOMEM; return -ENOMEM;
}
scale = max11410_get_scale(st, *cfg); scale = max11410_get_scale(st, *cfg);
for (i = 0; i < MAX11410_SCALE_AVAIL_SIZE; i++) { for (i = 0; i < MAX11410_SCALE_AVAIL_SIZE; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment