Commit 24622259 authored by Jonathan Cameron's avatar Jonathan Cameron

iio: adc: stm32: 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.

Note this would have made the bug fixed in the previous path much
less likely as it allows for direct returns.

Took advantage of dev_err_probe() to futher simplify things given no
longer a need for the goto err.

Cc: Olivier Moysan <olivier.moysan@foss.st.com>
Tested-by: default avatarFabrice Gasnier <fabrice.gasnier@foss.st.com>
Acked-by: default avatarFabrice Gasnier <fabrice.gasnier@foss.st.com>
Link: https://lore.kernel.org/r/20240330185305.1319844-5-jic23@kernel.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 3735ca0b
...@@ -2187,59 +2187,52 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, ...@@ -2187,59 +2187,52 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
struct iio_chan_spec *channels) struct iio_chan_spec *channels)
{ {
const struct stm32_adc_info *adc_info = adc->cfg->adc_info; const struct stm32_adc_info *adc_info = adc->cfg->adc_info;
struct fwnode_handle *child; struct device *dev = &indio_dev->dev;
const char *name; const char *name;
int val, scan_index = 0, ret; int val, scan_index = 0, ret;
bool differential; bool differential;
u32 vin[2]; u32 vin[2];
device_for_each_child_node(&indio_dev->dev, child) { device_for_each_child_node_scoped(dev, child) {
ret = fwnode_property_read_u32(child, "reg", &val); ret = fwnode_property_read_u32(child, "reg", &val);
if (ret) { if (ret)
dev_err(&indio_dev->dev, "Missing channel index %d\n", ret); return dev_err_probe(dev, ret,
goto err; "Missing channel index\n");
}
ret = fwnode_property_read_string(child, "label", &name); ret = fwnode_property_read_string(child, "label", &name);
/* label is optional */ /* label is optional */
if (!ret) { if (!ret) {
if (strlen(name) >= STM32_ADC_CH_SZ) { if (strlen(name) >= STM32_ADC_CH_SZ)
dev_err(&indio_dev->dev, "Label %s exceeds %d characters\n", return dev_err_probe(dev, -EINVAL,
name, STM32_ADC_CH_SZ); "Label %s exceeds %d characters\n",
ret = -EINVAL; name, STM32_ADC_CH_SZ);
goto err;
}
strscpy(adc->chan_name[val], name, STM32_ADC_CH_SZ); strscpy(adc->chan_name[val], name, STM32_ADC_CH_SZ);
ret = stm32_adc_populate_int_ch(indio_dev, name, val); ret = stm32_adc_populate_int_ch(indio_dev, name, val);
if (ret == -ENOENT) if (ret == -ENOENT)
continue; continue;
else if (ret) else if (ret)
goto err; return ret;
} else if (ret != -EINVAL) { } else if (ret != -EINVAL) {
dev_err(&indio_dev->dev, "Invalid label %d\n", ret); return dev_err_probe(dev, ret, "Invalid label\n");
goto err;
} }
if (val >= adc_info->max_channels) { if (val >= adc_info->max_channels)
dev_err(&indio_dev->dev, "Invalid channel %d\n", val); return dev_err_probe(dev, -EINVAL,
ret = -EINVAL; "Invalid channel %d\n", val);
goto err;
}
differential = false; differential = false;
ret = fwnode_property_read_u32_array(child, "diff-channels", vin, 2); ret = fwnode_property_read_u32_array(child, "diff-channels", vin, 2);
/* diff-channels is optional */ /* diff-channels is optional */
if (!ret) { if (!ret) {
differential = true; differential = true;
if (vin[0] != val || vin[1] >= adc_info->max_channels) { if (vin[0] != val || vin[1] >= adc_info->max_channels)
dev_err(&indio_dev->dev, "Invalid channel in%d-in%d\n", return dev_err_probe(dev, -EINVAL,
vin[0], vin[1]); "Invalid channel in%d-in%d\n",
ret = -EINVAL; vin[0], vin[1]);
goto err;
}
} else if (ret != -EINVAL) { } else if (ret != -EINVAL) {
dev_err(&indio_dev->dev, "Invalid diff-channels property %d\n", ret); return dev_err_probe(dev, ret,
goto err; "Invalid diff-channels property\n");
} }
stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val, stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val,
...@@ -2248,11 +2241,9 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, ...@@ -2248,11 +2241,9 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
val = 0; val = 0;
ret = fwnode_property_read_u32(child, "st,min-sample-time-ns", &val); ret = fwnode_property_read_u32(child, "st,min-sample-time-ns", &val);
/* st,min-sample-time-ns is optional */ /* st,min-sample-time-ns is optional */
if (ret && ret != -EINVAL) { if (ret && ret != -EINVAL)
dev_err(&indio_dev->dev, "Invalid st,min-sample-time-ns property %d\n", return dev_err_probe(dev, ret,
ret); "Invalid st,min-sample-time-ns property\n");
goto err;
}
stm32_adc_smpr_init(adc, channels[scan_index].channel, val); stm32_adc_smpr_init(adc, channels[scan_index].channel, val);
if (differential) if (differential)
...@@ -2262,11 +2253,6 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, ...@@ -2262,11 +2253,6 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
} }
return scan_index; return scan_index;
err:
fwnode_handle_put(child);
return ret;
} }
static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping) static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping)
......
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