Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: qcom-pm8xxx-xoadc: use scoped device_for_each_child_node()

Switch to device_for_each_child_node_scoped() to simplify the code by
removing the need for calls to fwnode_handle_put() in the error path.

This prevents possible memory leaks if new error paths are added without
the required call to fwnode_handle_put().

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://patch.msgid.link/20240926-iio_device_for_each_child_node_scoped-v1-1-64ca8a424578@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Javier Carrasco and committed by
Jonathan Cameron
db44b37a ee3bf0c1

+3 -5
+3 -5
drivers/iio/adc/qcom-pm8xxx-xoadc.c
··· 821 821 822 822 static int pm8xxx_xoadc_parse_channels(struct pm8xxx_xoadc *adc) 823 823 { 824 - struct fwnode_handle *child; 825 824 struct pm8xxx_chan_info *ch; 826 825 int ret; 827 826 int i; ··· 843 844 return -ENOMEM; 844 845 845 846 i = 0; 846 - device_for_each_child_node(adc->dev, child) { 847 + device_for_each_child_node_scoped(adc->dev, child) { 847 848 ch = &adc->chans[i]; 848 849 ret = pm8xxx_xoadc_parse_channel(adc->dev, child, 849 850 adc->variant->channels, 850 851 &adc->iio_chans[i], 851 852 ch); 852 - if (ret) { 853 - fwnode_handle_put(child); 853 + if (ret) 854 854 return ret; 855 - } 855 + 856 856 i++; 857 857 } 858 858