iio: adc: ad4130: Use device_for_each_child_node_scoped() to simplify error paths.
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 30 Mar 2024 19:08:45 +0000 (19:08 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 6 Apr 2024 10:29:06 +0000 (11:29 +0100)
This loop definition removes the need for manual releasing of the fwnode_handle
in early exit paths (here an error path) allow simplfication of the code
and reducing the chance of future modificiations not releasing
fwnode_handle correctly.

Cc: Cosmin Tanislav <demonsingur@gmail.com>
Cc: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20240330190849.1321065-5-jic23@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad4130.c

index febb64e67955eec99761bfa1835de528e7f199c1..aaf1fb0ac447728815c810a9972cab5cc187aade 100644 (file)
@@ -1600,17 +1600,14 @@ static int ad4130_parse_fw_children(struct iio_dev *indio_dev)
 {
        struct ad4130_state *st = iio_priv(indio_dev);
        struct device *dev = &st->spi->dev;
-       struct fwnode_handle *child;
        int ret;
 
        indio_dev->channels = st->chans;
 
-       device_for_each_child_node(dev, child) {
+       device_for_each_child_node_scoped(dev, child) {
                ret = ad4130_parse_fw_channel(indio_dev, child);
-               if (ret) {
-                       fwnode_handle_put(child);
+               if (ret)
                        return ret;
-               }
        }
 
        return 0;