Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: Marius Cristea <marius.cristea@microchip.com>,
	Mihail Chindris <mihail.chindris@analog.com>,
	Marcelo Schmitt <marcelo.schmitt1@gmail.com>,
	Kim Seer Paller <kimseer.paller@analog.com>,
	Dumitru Ceclan <mitrutzceclan@gmail.com>,
	Cosmin Tanislav <demonsingur@gmail.com>,
	Nuno Sa <nuno.sa@analog.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: [PATCH 5/8] iio: adc: ad7173: Use device_for_each_child_node_scoped() to simplify error paths.
Date: Sat, 30 Mar 2024 19:08:46 +0000	[thread overview]
Message-ID: <20240330190849.1321065-6-jic23@kernel.org> (raw)
In-Reply-To: <20240330190849.1321065-1-jic23@kernel.org>

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

This loop definition automatically releases the fwnode_handle on early
exit such as the error cases seen here.  This reducing boilerplate and
the chance of a resource leak being introduced in future.

Cc: Dumitru Ceclan <mitrutzceclan@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/adc/ad7173.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
index 4ff6ce46b02c..f6d29abe1d04 100644
--- a/drivers/iio/adc/ad7173.c
+++ b/drivers/iio/adc/ad7173.c
@@ -910,7 +910,6 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
 	struct device *dev = indio_dev->dev.parent;
 	struct iio_chan_spec *chan_arr, *chan;
 	unsigned int ain[2], chan_index = 0;
-	struct fwnode_handle *child;
 	int ref_sel, ret;
 
 	chan_arr = devm_kcalloc(dev, sizeof(*indio_dev->channels),
@@ -940,23 +939,19 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
 		chan_index++;
 	}
 
-	device_for_each_child_node(dev, child) {
+	device_for_each_child_node_scoped(dev, child) {
 		chan = &chan_arr[chan_index];
 		chan_st_priv = &chans_st_arr[chan_index];
 		ret = fwnode_property_read_u32_array(child, "diff-channels",
 						     ain, ARRAY_SIZE(ain));
-		if (ret) {
-			fwnode_handle_put(child);
+		if (ret)
 			return ret;
-		}
 
 		if (ain[0] >= st->info->num_inputs ||
-		    ain[1] >= st->info->num_inputs) {
-			fwnode_handle_put(child);
+		    ain[1] >= st->info->num_inputs)
 			return dev_err_probe(dev, -EINVAL,
 				"Input pin number out of range for pair (%d %d).\n",
 				ain[0], ain[1]);
-		}
 
 		ret = fwnode_property_match_property_string(child,
 							    "adi,reference-select",
@@ -968,24 +963,19 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
 			ref_sel = ret;
 
 		if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF &&
-		    !st->info->has_int_ref) {
-			fwnode_handle_put(child);
+		    !st->info->has_int_ref)
 			return dev_err_probe(dev, -EINVAL,
 				"Internal reference is not available on current model.\n");
-		}
 
-		if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) {
-			fwnode_handle_put(child);
+		if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2)
 			return dev_err_probe(dev, -EINVAL,
 				"External reference 2 is not available on current model.\n");
-		}
 
 		ret = ad7173_get_ref_voltage_milli(st, ref_sel);
-		if (ret < 0) {
-			fwnode_handle_put(child);
+		if (ret < 0)
 			return dev_err_probe(dev, ret,
 					     "Cannot use reference %u\n", ref_sel);
-		}
+
 		if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF)
 			st->adc_mode |= AD7173_ADC_MODE_REF_EN;
 		chan_st_priv->cfg.ref_sel = ref_sel;
-- 
2.44.0


  parent reply	other threads:[~2024-03-30 19:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-30 19:08 [PATCH 0/8] IIO: More use of device_for_each_child_node_scoped() and __free() Jonathan Cameron
2024-03-30 19:08 ` [PATCH 1/8] iio: adc: ab8500-gpadc: Allow COMPILE_TEST builds Jonathan Cameron
2024-04-04 11:36   ` Linus Walleij
2024-04-05 10:36     ` Jonathan Cameron
2024-04-06 10:27       ` Jonathan Cameron
2024-04-08  9:16         ` Linus Walleij
2024-04-13  9:57           ` Jonathan Cameron
2024-04-15  7:06             ` Linus Walleij
2024-03-30 19:08 ` [PATCH 2/8] iio: adc: ab8500-gpadc: Fix kernel-doc parameter names Jonathan Cameron
2024-04-04 11:36   ` Linus Walleij
2024-03-30 19:08 ` [PATCH 3/8] iio: adc: ab8500-gpadc: Use device_for_each_child_node_scoped() to simplify erorr paths Jonathan Cameron
2024-04-04 11:37   ` Linus Walleij
2024-03-30 19:08 ` [PATCH 4/8] iio: adc: ad4130: Use device_for_each_child_node_scoped() to simplify error paths Jonathan Cameron
2024-03-30 19:08 ` Jonathan Cameron [this message]
2024-03-30 19:08 ` [PATCH 6/8] iio: frequency: admfm2000: " Jonathan Cameron
2024-03-30 19:08 ` [PATCH 7/8] iio: dac: ad3552: Use __free(fwnode_handle) to simplify error handling Jonathan Cameron
2024-03-30 19:08 ` [PATCH 8/8] iio: adc: pac1934: Use device_for_each_available_child_node_scoped() " Jonathan Cameron
2024-04-04  9:09 ` [PATCH 0/8] IIO: More use of device_for_each_child_node_scoped() and __free() Nuno Sá
2024-04-06 10:29   ` Jonathan Cameron

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=20240330190849.1321065-6-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=demonsingur@gmail.com \
    --cc=kimseer.paller@analog.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=marius.cristea@microchip.com \
    --cc=mihail.chindris@analog.com \
    --cc=mitrutzceclan@gmail.com \
    --cc=nuno.sa@analog.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox