All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Pedro Mariano <pedro.mariano@usp.br>
To: anand.ashok.dumbre@xilinx.com, jic23@kernel.org, michal.simek@amd.com
Cc: Pedro Mariano <pedro.mariano@usp.br>,
	Roberto Bolgheroni <robertobolgheroni@usp.br>,
	linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [PATCH] iio: adc: xilinx-ams: Use device_for_each_child_node_scoped()
Date: Wed, 24 Apr 2024 19:53:00 -0300	[thread overview]
Message-ID: <20240424225302.47004-1-pedro.mariano@usp.br> (raw)

Using device_for_each_child_node_scoped instead of
device_for_each_child_node automatically releases the handle on early exit
which reduces the chance of bugs that cause resource leaks.

Co-developed-by: Roberto Bolgheroni <robertobolgheroni@usp.br>
Signed-off-by: Roberto Bolgheroni <robertobolgheroni@usp.br>
Signed-off-by: Pedro Mariano <pedro.mariano@usp.br>
---
 drivers/iio/adc/xilinx-ams.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c
index f0b71a122..7f5571d9d 100644
--- a/drivers/iio/adc/xilinx-ams.c
+++ b/drivers/iio/adc/xilinx-ams.c
@@ -1261,7 +1261,6 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
 	struct ams *ams = iio_priv(indio_dev);
 	struct iio_chan_spec *ams_channels, *dev_channels;
 	struct device *dev = indio_dev->dev.parent;
-	struct fwnode_handle *child = NULL;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
 	size_t ams_size;
 	int ret, ch_cnt = 0, i, rising_off, falling_off;
@@ -1283,13 +1282,11 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
 		num_channels += ret;
 	}
 
-	fwnode_for_each_child_node(fwnode, child) {
+	fwnode_for_each_child_node_scoped(fwnode, child) {
 		if (fwnode_device_is_available(child)) {
 			ret = ams_init_module(indio_dev, child, ams_channels + num_channels);
-			if (ret < 0) {
-				fwnode_handle_put(child);
+			if (ret < 0)
 				return ret;
-			}
 
 			num_channels += ret;
 		}
-- 
2.44.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Pedro Mariano <pedro.mariano@usp.br>
To: anand.ashok.dumbre@xilinx.com, jic23@kernel.org, michal.simek@amd.com
Cc: Pedro Mariano <pedro.mariano@usp.br>,
	Roberto Bolgheroni <robertobolgheroni@usp.br>,
	linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [PATCH] iio: adc: xilinx-ams: Use device_for_each_child_node_scoped()
Date: Wed, 24 Apr 2024 19:53:00 -0300	[thread overview]
Message-ID: <20240424225302.47004-1-pedro.mariano@usp.br> (raw)

Using device_for_each_child_node_scoped instead of
device_for_each_child_node automatically releases the handle on early exit
which reduces the chance of bugs that cause resource leaks.

Co-developed-by: Roberto Bolgheroni <robertobolgheroni@usp.br>
Signed-off-by: Roberto Bolgheroni <robertobolgheroni@usp.br>
Signed-off-by: Pedro Mariano <pedro.mariano@usp.br>
---
 drivers/iio/adc/xilinx-ams.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c
index f0b71a122..7f5571d9d 100644
--- a/drivers/iio/adc/xilinx-ams.c
+++ b/drivers/iio/adc/xilinx-ams.c
@@ -1261,7 +1261,6 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
 	struct ams *ams = iio_priv(indio_dev);
 	struct iio_chan_spec *ams_channels, *dev_channels;
 	struct device *dev = indio_dev->dev.parent;
-	struct fwnode_handle *child = NULL;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
 	size_t ams_size;
 	int ret, ch_cnt = 0, i, rising_off, falling_off;
@@ -1283,13 +1282,11 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
 		num_channels += ret;
 	}
 
-	fwnode_for_each_child_node(fwnode, child) {
+	fwnode_for_each_child_node_scoped(fwnode, child) {
 		if (fwnode_device_is_available(child)) {
 			ret = ams_init_module(indio_dev, child, ams_channels + num_channels);
-			if (ret < 0) {
-				fwnode_handle_put(child);
+			if (ret < 0)
 				return ret;
-			}
 
 			num_channels += ret;
 		}
-- 
2.44.0


             reply	other threads:[~2024-04-24 22:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-24 22:53 Pedro Mariano [this message]
2024-04-24 22:53 ` [PATCH] iio: adc: xilinx-ams: Use device_for_each_child_node_scoped() Pedro Mariano
2024-04-27  9:13 ` Marcelo Schmitt
2024-04-27  9:13   ` Marcelo Schmitt
2024-04-28 16:17   ` Jonathan Cameron
2024-04-28 16:17     ` Jonathan Cameron
2024-04-29  6:28     ` Michal Simek
2024-04-29  6:28       ` Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240424225302.47004-1-pedro.mariano@usp.br \
    --to=pedro.mariano@usp.br \
    --cc=anand.ashok.dumbre@xilinx.com \
    --cc=jic23@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=robertobolgheroni@usp.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.