From patchwork Sat Feb 24 12:32:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570396 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89D801392 for ; Sat, 24 Feb 2024 12:32:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777960; cv=none; b=Gcy8osd0gAW86N5mjTMXFjG+HofVgRri+Sd1FN+F74KzE2XSBn32iCYtkFF3kyFvTQlS0DMFVDdHT12Xpou5Tq/L5AQS4xWz1EJxilZiYsZczwB/IH6/vXSCdvtghBmMQ+tktXEVmyj9lG+3ITojpctaMwppd7i8fOzUBYFAYu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777960; c=relaxed/simple; bh=g7P8BFC7UVt5OhkHHbMVRot0JK3hmmyssZqx+vth2V4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S5AcnizEPve4ROu9GDjXDFQ/w436Azk7YSZPDyEubaqcKDfixUudDTd3HxeZoyoWpBJ+OrrO5C5KNcjydcxW3ioABEhVBY1JYNGMdU0sq7P0tZ7U24UsN4AZQSrchIMZ24ECiS2nxMk0TXQ1zPECoyw4pYNZfBUGXerUgcnnGQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MbzXauHZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MbzXauHZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24995C433C7; Sat, 24 Feb 2024 12:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777960; bh=g7P8BFC7UVt5OhkHHbMVRot0JK3hmmyssZqx+vth2V4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MbzXauHZx6ZGYl1HF9RANfh5yWISMyZeqqCoMxxPaxzj1n6palsCrCYKUUilR3JYw noQNG+lLhdHF3ogrVRgRMGZQixoFumh7n0b69ZLzLGY2TdKTmQFW6n1nKinlYhuXL8 9tybfQ0oHpKwgRGuHZ1RPe1Jud7FBQAeZmkc08z/hltD3bGJGSlQZj6s7UciAMYYWy fczxzblzvRu543DDOVPIKYET0XtJ7NuQov16PFN9SN2xbsvWFCt5I0eOmP2QAN+Kwj B+4t+YIWlVn/JEtKBid6bXCdULnbPnF096My2BkAdH4GHOvM6HeXITmXarigEShUj/ WoW2/yWuT/HKA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 1/9] iio: temp: ltc2983: Use __free(fwnode_handle) and device_for_each_node_scoped() Date: Sat, 24 Feb 2024 12:32:07 +0000 Message-ID: <20240224123215.161469-2-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This use of the new cleanup.h scope based freeing infrastructure allows us to exit directly from error conditions and in the good path with the reference obtained from fwnode_find_reference() (which may be an error pointer) automatically released. Similarly the _scoped() version of device_for_each_child_node() removes the need for the manual calling of fwnode_handl_put() in paths where the code exits the loop early. Tidy up some unusual indentation in a dev_dbg() whilst here. Cc: Cosmin Tanislav Cc: Nuno Sá Signed-off-by: Jonathan Cameron Reviewed-by: Nuno Sa --- v5: Add the device_for_each_child_node_scoped() change (Nuno) --- drivers/iio/temperature/ltc2983.c | 137 +++++++++++------------------- 1 file changed, 50 insertions(+), 87 deletions(-) diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c index fcb96c44d954..7d5473e7b500 100644 --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -656,7 +656,6 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data const struct ltc2983_sensor *sensor) { struct ltc2983_thermocouple *thermo; - struct fwnode_handle *ref; u32 oc_current; int ret; @@ -703,7 +702,8 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data return ERR_PTR(-EINVAL); } - ref = fwnode_find_reference(child, "adi,cold-junction-handle", 0); + struct fwnode_handle *ref __free(fwnode_handle) = + fwnode_find_reference(child, "adi,cold-junction-handle", 0); if (IS_ERR(ref)) { ref = NULL; } else { @@ -714,7 +714,7 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data * the error right away. */ dev_err(&st->spi->dev, "Property reg must be given\n"); - goto fail; + return ERR_PTR(ret); } } @@ -725,22 +725,15 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data thermo->custom = __ltc2983_custom_sensor_new(st, child, propname, false, 16384, true); - if (IS_ERR(thermo->custom)) { - ret = PTR_ERR(thermo->custom); - goto fail; - } + if (IS_ERR(thermo->custom)) + return ERR_CAST(thermo->custom); } /* set common parameters */ thermo->sensor.fault_handler = ltc2983_thermocouple_fault_handler; thermo->sensor.assign_chan = ltc2983_thermocouple_assign_chan; - fwnode_handle_put(ref); return &thermo->sensor; - -fail: - fwnode_handle_put(ref); - return ERR_PTR(ret); } static struct ltc2983_sensor * @@ -750,14 +743,14 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, struct ltc2983_rtd *rtd; int ret = 0; struct device *dev = &st->spi->dev; - struct fwnode_handle *ref; u32 excitation_current = 0, n_wires = 0; rtd = devm_kzalloc(dev, sizeof(*rtd), GFP_KERNEL); if (!rtd) return ERR_PTR(-ENOMEM); - ref = fwnode_find_reference(child, "adi,rsense-handle", 0); + struct fwnode_handle *ref __free(fwnode_handle) = + fwnode_find_reference(child, "adi,rsense-handle", 0); if (IS_ERR(ref)) { dev_err(dev, "Property adi,rsense-handle missing or invalid"); return ERR_CAST(ref); @@ -766,7 +759,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, ret = fwnode_property_read_u32(ref, "reg", &rtd->r_sense_chan); if (ret) { dev_err(dev, "Property reg must be given\n"); - goto fail; + return ERR_PTR(ret); } ret = fwnode_property_read_u32(child, "adi,number-of-wires", &n_wires); @@ -787,8 +780,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, break; default: dev_err(dev, "Invalid number of wires:%u\n", n_wires); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } @@ -798,8 +790,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, if (n_wires == 2 || n_wires == 3) { dev_err(dev, "Rotation not allowed for 2/3 Wire RTDs"); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } rtd->sensor_config |= LTC2983_RTD_C_ROTATE(1); } else { @@ -829,16 +820,14 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, "Invalid rsense chann:%d to use in kelvin rsense", rtd->r_sense_chan); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } if (sensor->chan < min || sensor->chan > max) { dev_err(dev, "Invalid chann:%d for the rtd config", sensor->chan); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } else { /* same as differential case */ @@ -846,8 +835,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, dev_err(&st->spi->dev, "Invalid chann:%d for RTD", sensor->chan); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } @@ -856,10 +844,8 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, rtd->custom = __ltc2983_custom_sensor_new(st, child, "adi,custom-rtd", false, 2048, false); - if (IS_ERR(rtd->custom)) { - ret = PTR_ERR(rtd->custom); - goto fail; - } + if (IS_ERR(rtd->custom)) + return ERR_CAST(rtd->custom); } /* set common parameters */ @@ -901,18 +887,13 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, dev_err(&st->spi->dev, "Invalid value for excitation current(%u)", excitation_current); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } fwnode_property_read_u32(child, "adi,rtd-curve", &rtd->rtd_curve); - fwnode_handle_put(ref); return &rtd->sensor; -fail: - fwnode_handle_put(ref); - return ERR_PTR(ret); } static struct ltc2983_sensor * @@ -921,7 +902,6 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s { struct ltc2983_thermistor *thermistor; struct device *dev = &st->spi->dev; - struct fwnode_handle *ref; u32 excitation_current = 0; int ret = 0; @@ -929,7 +909,8 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s if (!thermistor) return ERR_PTR(-ENOMEM); - ref = fwnode_find_reference(child, "adi,rsense-handle", 0); + struct fwnode_handle *ref __free(fwnode_handle) = + fwnode_find_reference(child, "adi,rsense-handle", 0); if (IS_ERR(ref)) { dev_err(dev, "Property adi,rsense-handle missing or invalid"); return ERR_CAST(ref); @@ -938,7 +919,7 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s ret = fwnode_property_read_u32(ref, "reg", &thermistor->r_sense_chan); if (ret) { dev_err(dev, "rsense channel must be configured...\n"); - goto fail; + return ERR_PTR(ret); } if (fwnode_property_read_bool(child, "adi,single-ended")) { @@ -958,8 +939,7 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s dev_err(&st->spi->dev, "Invalid chann:%d for differential thermistor", sensor->chan); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } /* check custom sensor */ @@ -978,10 +958,8 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s propname, steinhart, 64, false); - if (IS_ERR(thermistor->custom)) { - ret = PTR_ERR(thermistor->custom); - goto fail; - } + if (IS_ERR(thermistor->custom)) + return ERR_CAST(thermistor->custom); } /* set common parameters */ thermistor->sensor.fault_handler = ltc2983_common_fault_handler; @@ -1005,8 +983,7 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s LTC2983_SENSOR_THERMISTOR_STEINHART) { dev_err(&st->spi->dev, "Auto Range not allowed for custom sensors\n"); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } thermistor->excitation_current = 0x0c; break; @@ -1047,16 +1024,11 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s dev_err(&st->spi->dev, "Invalid value for excitation current(%u)", excitation_current); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } - fwnode_handle_put(ref); return &thermistor->sensor; -fail: - fwnode_handle_put(ref); - return ERR_PTR(ret); } static struct ltc2983_sensor * @@ -1349,8 +1321,7 @@ static irqreturn_t ltc2983_irq_handler(int irq, void *data) static int ltc2983_parse_dt(struct ltc2983_data *st) { struct device *dev = &st->spi->dev; - struct fwnode_handle *child; - int ret = 0, chan = 0, channel_avail_mask = 0; + int ret, chan = 0, channel_avail_mask = 0; device_property_read_u32(dev, "adi,mux-delay-config-us", &st->mux_delay_config); @@ -1368,38 +1339,35 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) return -ENOMEM; st->iio_channels = st->num_channels; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct ltc2983_sensor sensor; ret = fwnode_property_read_u32(child, "reg", &sensor.chan); - if (ret) { - dev_err(dev, "reg property must given for child nodes\n"); - goto put_child; - } + if (ret) + return dev_err_probe(dev, ret, + "reg property must given for child nodes\n"); /* check if we have a valid channel */ if (sensor.chan < LTC2983_MIN_CHANNELS_NR || - sensor.chan > st->info->max_channels_nr) { - ret = -EINVAL; - dev_err(dev, "chan:%d must be from %u to %u\n", sensor.chan, - LTC2983_MIN_CHANNELS_NR, st->info->max_channels_nr); - goto put_child; - } else if (channel_avail_mask & BIT(sensor.chan)) { - ret = -EINVAL; - dev_err(dev, "chan:%d already in use\n", sensor.chan); - goto put_child; - } + sensor.chan > st->info->max_channels_nr) + return dev_err_probe(dev, -EINVAL, + "chan:%d must be from %u to %u\n", + sensor.chan, + LTC2983_MIN_CHANNELS_NR, + st->info->max_channels_nr); + + if (channel_avail_mask & BIT(sensor.chan)) + return dev_err_probe(dev, -EINVAL, + "chan:%d already in use\n", + sensor.chan); ret = fwnode_property_read_u32(child, "adi,sensor-type", &sensor.type); - if (ret) { - dev_err(dev, + if (ret) + return dev_err_probe(dev, ret, "adi,sensor-type property must given for child nodes\n"); - goto put_child; - } dev_dbg(dev, "Create new sensor, type %u, chann %u", - sensor.type, - sensor.chan); + sensor.type, sensor.chan); if (sensor.type >= LTC2983_SENSOR_THERMOCOUPLE && sensor.type <= LTC2983_SENSOR_THERMOCOUPLE_CUSTOM) { @@ -1426,17 +1394,15 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) sensor.type == LTC2983_SENSOR_ACTIVE_TEMP) { st->sensors[chan] = ltc2983_temp_new(child, st, &sensor); } else { - dev_err(dev, "Unknown sensor type %d\n", sensor.type); - ret = -EINVAL; - goto put_child; + return dev_err_probe(dev, -EINVAL, + "Unknown sensor type %d\n", + sensor.type); } - if (IS_ERR(st->sensors[chan])) { - dev_err(dev, "Failed to create sensor %ld", - PTR_ERR(st->sensors[chan])); - ret = PTR_ERR(st->sensors[chan]); - goto put_child; - } + if (IS_ERR(st->sensors[chan])) + return dev_err_probe(dev, PTR_ERR(st->sensors[chan]), + "Failed to create sensor\n"); + /* set generic sensor parameters */ st->sensors[chan]->chan = sensor.chan; st->sensors[chan]->type = sensor.type; @@ -1446,9 +1412,6 @@ static int ltc2983_parse_dt(struct ltc2983_data *st) } return 0; -put_child: - fwnode_handle_put(child); - return ret; } static int ltc2983_eeprom_cmd(struct ltc2983_data *st, unsigned int cmd, From patchwork Sat Feb 24 12:32:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570397 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4FA325750 for ; Sat, 24 Feb 2024 12:32:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777963; cv=none; b=qSPBbDgSXjEUZB2Gq0/i/i2jwfY++kK2AYZBvhhppNCvpKvoBxruib9UR8Qh2ZA/TCSPLrMkBs5RBjVl2Z943RMUhv493Tn2ZNGQxc6SJ0MtKXKq+sHctPQkGGwVaqxvDhCe3aBzpwyS1PsubKxuuHZF811Fswvg1OCA9tHp9YY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777963; c=relaxed/simple; bh=t+c4BrYzejAt75RJ2Qxn/cvI2ZbHxIHAKbFEFaGQriQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WL0sliia8Pk4IycsVQHXtQMl9IYOkprZ4FDBk0PwlNKYRzk7IwLDzLwUqxT7SXNgr/zN85Qmxnfys76usFD9dsbYCT3fAEwYhrDG+cda4lSJ/98p4d9Wy5pDOiF0rJqX1O+WB8NBuuHBlvSRBVDH2OzPiNsp9i+id7R+k9lCXDU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lHbtwH0g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lHbtwH0g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B37FC433F1; Sat, 24 Feb 2024 12:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777963; bh=t+c4BrYzejAt75RJ2Qxn/cvI2ZbHxIHAKbFEFaGQriQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lHbtwH0gBbUspXnXUD87aqkbifjZVV1oGVDPhiTPxX6xQXKxBWQGYiWyuxKVwizQt GLUR0gxdXKbhWn2JJRmOa760WI8P3JInvc/u0iuSSbFJsuwjxKAoPa+WIDJuZaylx7 1FBph2IjVbsr0tIyPAhfb16lKdpH6+pfboP+uX2QlPd09BHKicFlK6IF7M8yKzpvuP HWL2Uv2RtlJNY56S1ldnLlahqio1uOSPG9POp/Agwo4UC0XHC5X/8z2QDk6+2BYs9T ZiBOsg/BEiCE23jwFHYz79FZbzHAMdvtEWgMvvbJAZhoxc7TsL/6H5Qtu3QmRL1kFu crTFmU56yRaGA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 2/9] iio: adc: mcp3564: Use device_for_each_child_node_scoped() Date: Sat, 24 Feb 2024 12:32:08 +0000 Message-ID: <20240224123215.161469-3-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron 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. Cc: Marius Cristea Signed-off-by: Jonathan Cameron --- drivers/iio/adc/mcp3564.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c index 311b613b6057..e2ae13f1e842 100644 --- a/drivers/iio/adc/mcp3564.c +++ b/drivers/iio/adc/mcp3564.c @@ -998,7 +998,6 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) struct mcp3564_state *adc = iio_priv(indio_dev); struct device *dev = &adc->spi->dev; struct iio_chan_spec *channels; - struct fwnode_handle *child; struct iio_chan_spec chanspec = mcp3564_channel_template; struct iio_chan_spec temp_chanspec = mcp3564_temp_channel_template; struct iio_chan_spec burnout_chanspec = mcp3564_burnout_channel_template; @@ -1025,7 +1024,7 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) if (!channels) return dev_err_probe(dev, -ENOMEM, "Can't allocate memory\n"); - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { node_name = fwnode_get_name(child); if (fwnode_property_present(child, "diff-channels")) { @@ -1033,26 +1032,25 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) "diff-channels", inputs, ARRAY_SIZE(inputs)); + if (ret) + return ret; + chanspec.differential = 1; } else { ret = fwnode_property_read_u32(child, "reg", &inputs[0]); + if (ret) + return ret; chanspec.differential = 0; inputs[1] = MCP3564_AGND; } - if (ret) { - fwnode_handle_put(child); - return ret; - } if (inputs[0] > MCP3564_INTERNAL_VCM || - inputs[1] > MCP3564_INTERNAL_VCM) { - fwnode_handle_put(child); + inputs[1] > MCP3564_INTERNAL_VCM) return dev_err_probe(&indio_dev->dev, -EINVAL, "Channel index > %d, for %s\n", MCP3564_INTERNAL_VCM + 1, node_name); - } chanspec.address = (inputs[0] << 4) | inputs[1]; chanspec.channel = inputs[0]; From patchwork Sat Feb 24 12:32:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570398 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F2BD18021 for ; Sat, 24 Feb 2024 12:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777968; cv=none; b=Y9BF4Qj891dCuJ4xmCwGzkS7eNvFIa6ldDu4aaERM29YX3KJLHvLYN2XZZYv9nz2QyEn4x9JcdFDLXAI0p+Zwqe5G/kVSVj853d6+JQTybYM0ZNCdCXukQu/cPWEPP36gcE8PFqAUvrda7N5G4X1pth5w3+gkmlXnJ+8ZIX8ixs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777968; c=relaxed/simple; bh=6GckLYsNuC3zH2eXzNl8m+O6ErjjCU39FK09wLysA60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gjg20o5YgDMoQROZRteNKjECkaHmK3/fhaReW3CvSzh3iLa+r+maizd/8RIsFxbKCcVr8JuG6SKJUB//G5dy/xh/M5FGv2KBokuTJDrHy0ywLuUb4o7QKvPAKqhvvJ66w+Z6S7b+wOv8JpZk4jEqCynrkJ1xq9kZMlu312/ZVNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BaY6ydiz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BaY6ydiz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25A4EC433C7; Sat, 24 Feb 2024 12:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777968; bh=6GckLYsNuC3zH2eXzNl8m+O6ErjjCU39FK09wLysA60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BaY6ydizNTADS0yVPv9BK8paMTjO1yjvPZ6mdg+FAsS2ul7toHILUnuZphBH4SXyP 3MO3uqhbCU43ajciYMinwq7nAiGo7vDR8aaFlrR5QeXjXw1wIdcx6NOoFdPFx02ick GFT5rNZE+KEfrohGg12n9p5DOc2cTkQJPaanmpoXQsA2jxOHoQv79GItCxPmbh414A Ds26lYYALhybK6f+/MGGneAgn9eJmQtxoeNT3iJN3c1oH04bmhsUrYxcso3w4dXxG+ ZQY0KzRWuoPqCRYvAhcA+pUVDVN9shemmfR1jUIKbDfg7fOu9F/RLzBEvPIFAOZGMk zDJR3LcJjOmhQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 3/9] iio: adc: qcom-spmi-adc5: Use device_for_each_child_node_scoped() Date: Sat, 24 Feb 2024 12:32:09 +0000 Message-ID: <20240224123215.161469-4-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron 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. A slightly less convincing usecase than many as all the failure paths are wrapped up in a call to a per fwnode_handle utility function. The complexity in that function is sufficient that it makes sense to factor it out even if it this new auto cleanup would enable simpler returns if the code was inline at the call site. Hence I've left it alone. Cc: Marijn Suijten Reviewed-by: Dmitry Baryshkov Signed-off-by: Jonathan Cameron --- drivers/iio/adc/qcom-spmi-adc5.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c index b6b612d733ff..9b69f40beed8 100644 --- a/drivers/iio/adc/qcom-spmi-adc5.c +++ b/drivers/iio/adc/qcom-spmi-adc5.c @@ -825,7 +825,6 @@ static int adc5_get_fw_data(struct adc5_chip *adc) const struct adc5_channels *adc_chan; struct iio_chan_spec *iio_chan; struct adc5_channel_prop prop, *chan_props; - struct fwnode_handle *child; unsigned int index = 0; int ret; @@ -849,12 +848,10 @@ static int adc5_get_fw_data(struct adc5_chip *adc) if (!adc->data) adc->data = &adc5_data_pmic; - device_for_each_child_node(adc->dev, child) { + device_for_each_child_node_scoped(adc->dev, child) { ret = adc5_get_fw_channel_data(adc, &prop, child, adc->data); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } prop.scale_fn_type = adc->data->adc_chans[prop.channel].scale_fn_type; From patchwork Sat Feb 24 12:32:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570399 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F48A18021 for ; Sat, 24 Feb 2024 12:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777973; cv=none; b=G2hM9oXCbsG3aKk28MxWpuR0v3ncS4xTjex3MdOQ43UdS52xyjNB+ZD13p1j2LaZMr8LTl0kfnrwtybeQpJXl4hpnrrVytOeDtJRPsaO5GdD14IjbicyqA4da+liyxRF7ZMIiRywPg9ZG8SXHwD/HfhxPafwwJTRMSi1qglspT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777973; c=relaxed/simple; bh=ox+Evaxjxa0J6imV8DxSC0CTBfvsevk1voCwRwmjOl0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iDDgULD3KTZBjW9593FCU3SIplOajjA9n5By2aTyyjgyDk34zeTmSwJYsZN/kvXjkl3ImIUznMxRj1DHE0saYLboqmyt5GNYvwIiHIPcHQkZM7snmR/vAl1LWl8fYodru+Ir6Iz/feEiYQQYfrKYpuMf7TB2+mPom/JcB1aZHTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cGvCKoPc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cGvCKoPc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A147FC433F1; Sat, 24 Feb 2024 12:32:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777973; bh=ox+Evaxjxa0J6imV8DxSC0CTBfvsevk1voCwRwmjOl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cGvCKoPc6B34cOGbpt3YYEwdpY5p/A1MQ4s0fYn/IjPfB/bfd8w0Ta47+7ioKfHEM njNbOcIU5iRZpwsZVIsAIxdjDDdRzV9CiPoLDacF5P6l1cqcTh7wh1bwpoNS7A5EFz Qh3ehvrje7Jd/p/FENqKTaOgdFBsfFgYSe2AIHHE0JjkI4cpNSHsK1/+fX7Jq9uNqh 9brTzJzlUSiVdWYXGiKvDD3s1GDKYtrRv2EgzDcFUEURJqCoJMVtxL0OXHGlrh76jW JBx+2lE/2SvkesQEGV4aDDoa/9hikLpMR7Kz7wD69HgiQPV26zn6MVViFkk7e25yIV R99SWe7Zeg5wA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 4/9] iio: adc: rzg2l_adc: Use device_for_each_child_node_scoped() Date: Sat, 24 Feb 2024 12:32:10 +0000 Message-ID: <20240224123215.161469-5-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron 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. Cc: Lad Prabhakar Signed-off-by: Jonathan Cameron Reviewed-by: Lad Prabhakar --- drivers/iio/adc/rzg2l_adc.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c index 0921ff2d9b3a..cd3a7e46ea53 100644 --- a/drivers/iio/adc/rzg2l_adc.c +++ b/drivers/iio/adc/rzg2l_adc.c @@ -302,7 +302,6 @@ static irqreturn_t rzg2l_adc_isr(int irq, void *dev_id) static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l_adc *adc) { struct iio_chan_spec *chan_array; - struct fwnode_handle *fwnode; struct rzg2l_adc_data *data; unsigned int channel; int num_channels; @@ -330,17 +329,13 @@ static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l return -ENOMEM; i = 0; - device_for_each_child_node(&pdev->dev, fwnode) { + device_for_each_child_node_scoped(&pdev->dev, fwnode) { ret = fwnode_property_read_u32(fwnode, "reg", &channel); - if (ret) { - fwnode_handle_put(fwnode); + if (ret) return ret; - } - if (channel >= RZG2L_ADC_MAX_CHANNELS) { - fwnode_handle_put(fwnode); + if (channel >= RZG2L_ADC_MAX_CHANNELS) return -EINVAL; - } chan_array[i].type = IIO_VOLTAGE; chan_array[i].indexed = 1; From patchwork Sat Feb 24 12:32:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570400 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18C7932C8B for ; Sat, 24 Feb 2024 12:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777978; cv=none; b=oKWXX+fpQ6Mr65dQe9p2ZUBXUmgz2035LZb3lyUB+QYsQDpOjC0224lL5UznOzsgFosa6TmkxRur5/JletWuvfMbL86udyXfMCJzQgPmhwwsCKd/8++RfRMVAd+dTp62ZntSVmdR3ebGpC76ybMc1XpasOv/AmfMyGow4vfpMGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777978; c=relaxed/simple; bh=+awu/pMPXaxGOjhhfZLr5yugyhOcnWpANtrhyYVzyiM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fxkcmuo98a4O3XIgIlueA06N+k6Laob9ZJUPQH/agtpqeBgmy9SuC59Xpv7vBKmrsf9HUO3ez2HDHRJ6jPiw4bu/Gqo/5eLh2K2glTb1mA1P9artsVGREaokjHvqPCxirDH5uEzBdRp4SwxZo7Sr+ufyhkPGDEUkiR8adqKMYLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i0goBnDO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i0goBnDO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6CCBC43390; Sat, 24 Feb 2024 12:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777977; bh=+awu/pMPXaxGOjhhfZLr5yugyhOcnWpANtrhyYVzyiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i0goBnDOadxuC5IIiwXXcFADWkV7n1bHNioTAQUBt4ZPGuCYA8NjWS9N10ml5Msz8 oY1hGuyu9B2k3G9B+Mo/5m+sFTVY6ZFpQGg3qknB8uqRtqDriH5Ao8zch8H+c+fbh8 zb+ThMLuh7ljymzSNapho2Lf9HrLqNvfYLfqht8qHuwrfiq/7Mx9HAoSoFS4NPGJcg INkFykCQmP11K2Fxf+I+G23g7dBXHgKeVXnEO2B6FKwsREY1wPVEABtH0txTiD/2eo oimy/BgZm3LxPJGLYrqdcEtFG9OGbYzG1GBwwRz5FuPOhEgB/sF1MWFMZjUR2rtrHp 3VOspZnAqUKkA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 5/9] iio: adc: stm32: Use device_for_each_child_node_scoped() Date: Sat, 24 Feb 2024 12:32:11 +0000 Message-ID: <20240224123215.161469-6-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron 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 includes a probable fix as in one path an error message was printed with ret == 0. Took advantage of dev_err_probe() to futher simplify things given no longer a need for the goto err. Cc: Olivier Moysan Cc: Fabrice Gasnier Signed-off-by: Jonathan Cameron Tested-by: Fabrice Gasnier Acked-by: Fabrice Gasnier --- v5: Use a local struct device pointer. Add brackets back I shouldn't have dropped. Andy had a number of other comments but they would be unrelated changes so I'm leaving them for a future patch set. --- drivers/iio/adc/stm32-adc.c | 61 +++++++++++++++---------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index b5d3c9cea5c4..36add95212c3 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -2187,58 +2187,52 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, struct iio_chan_spec *channels) { const struct stm32_adc_info *adc_info = adc->cfg->adc_info; - struct fwnode_handle *child; + struct device *dev = &indio_dev->dev; const char *name; int val, scan_index = 0, ret; bool differential; 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); - if (ret) { - dev_err(&indio_dev->dev, "Missing channel index %d\n", ret); - goto err; - } + if (ret) + return dev_err_probe(dev, ret, + "Missing channel index\n"); ret = fwnode_property_read_string(child, "label", &name); /* label is optional */ if (!ret) { - if (strlen(name) >= STM32_ADC_CH_SZ) { - dev_err(&indio_dev->dev, "Label %s exceeds %d characters\n", - name, STM32_ADC_CH_SZ); - ret = -EINVAL; - goto err; - } + if (strlen(name) >= STM32_ADC_CH_SZ) + return dev_err_probe(dev, -EINVAL, + "Label %s exceeds %d characters\n", + 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); if (ret == -ENOENT) continue; else if (ret) - goto err; + return ret; } else if (ret != -EINVAL) { - dev_err(&indio_dev->dev, "Invalid label %d\n", ret); - goto err; + return dev_err_probe(dev, ret, "Invalid label\n"); } - if (val >= adc_info->max_channels) { - dev_err(&indio_dev->dev, "Invalid channel %d\n", val); - ret = -EINVAL; - goto err; - } + if (val >= adc_info->max_channels) + return dev_err_probe(dev, -EINVAL, + "Invalid channel %d\n", val); differential = false; ret = fwnode_property_read_u32_array(child, "diff-channels", vin, 2); /* diff-channels is optional */ if (!ret) { differential = true; - if (vin[0] != val || vin[1] >= adc_info->max_channels) { - dev_err(&indio_dev->dev, "Invalid channel in%d-in%d\n", - vin[0], vin[1]); - goto err; - } + if (vin[0] != val || vin[1] >= adc_info->max_channels) + return dev_err_probe(dev, -EINVAL, + "Invalid channel in%d-in%d\n", + vin[0], vin[1]); } else if (ret != -EINVAL) { - dev_err(&indio_dev->dev, "Invalid diff-channels property %d\n", ret); - goto err; + return dev_err_probe(dev, ret, + "Invalid diff-channels property\n"); } stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val, @@ -2247,11 +2241,9 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, val = 0; ret = fwnode_property_read_u32(child, "st,min-sample-time-ns", &val); /* st,min-sample-time-ns is optional */ - if (ret && ret != -EINVAL) { - dev_err(&indio_dev->dev, "Invalid st,min-sample-time-ns property %d\n", - ret); - goto err; - } + if (ret && ret != -EINVAL) + return dev_err_probe(dev, ret, + "Invalid st,min-sample-time-ns property\n"); stm32_adc_smpr_init(adc, channels[scan_index].channel, val); if (differential) @@ -2261,11 +2253,6 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, } return scan_index; - -err: - fwnode_handle_put(child); - - return ret; } static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping) From patchwork Sat Feb 24 12:32:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570401 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AEDA32C8B for ; Sat, 24 Feb 2024 12:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777983; cv=none; b=FrSWmratK/UtPQeOg2HaftwWFpIlngneyLFcnGfccnB45qdeNPtLqKLljT1QE2sHHulx8vUMW4iwRl+jHpds+/ooES0biiqR5Zx/tioRN8Ik1yHY9OjRNyHbM1dEbjN9XkWpmLBnATwMxwBeLkSXVfxaU/kypb+pOFLPRU7LWoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777983; c=relaxed/simple; bh=ruJKwM0lQj1GeEvjHu7rz30w3dvlpzqaiQm4QjXLSRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AAimkQeZdWHwe35aORSBAJHALd5XluuIPRi7wyr2XZpjRxweBSvHJYIsso9IdUZHi11ycZDLyGx8vyTRo3ddLvoe6hXRAPDwEBzWF8hQaMxfT+22Cr1t4giHHvYsrEi/irdTdAzIEhWuzJ70pQupj56lFcTGklpKMpzNfFEOUUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KNvZSFxQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KNvZSFxQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 139C9C43394; Sat, 24 Feb 2024 12:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777983; bh=ruJKwM0lQj1GeEvjHu7rz30w3dvlpzqaiQm4QjXLSRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KNvZSFxQ57z8qwv42y5bR8MHGIpfqJwITmR0dM6QOrvkAdvsniVfSQBzmIkYcgorg k51ieQs1Q/B5vYoUy4gRuyImerCNCm3koaGdp+mKNojsX/1cCcqPY/pp9dUWuftm/a LrazDP5s1ZyrojbWXgduQU7+VC6tiwwUlWowYcuYXod3tcxCenqYVKfQhElFdt4Ib/ 7KGktbDCx/RCiEyq4PnfaIYtLCJq8ONZiQIc0nji39bXRcUeG7D/TUdRItKW0NJ5mn ztmWVEqLm4BADCkdF08Z7td02z4ABjSPYV24HlkMaEAaric6vhRHuP0xVvttGPT2Ts U1/piFX2wGFeA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 6/9] iio: adc: ti-ads1015: Use device_for_each_child_node_scoped() Date: Sat, 24 Feb 2024 12:32:12 +0000 Message-ID: <20240224123215.161469-7-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron 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. Cc: Marek Vasut Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ti-ads1015.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 6ae967e4d8fa..d3363d02f292 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -902,10 +902,9 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ads1015_data *data = iio_priv(indio_dev); struct device *dev = &client->dev; - struct fwnode_handle *node; int i = -1; - device_for_each_child_node(dev, node) { + device_for_each_child_node_scoped(dev, node) { u32 pval; unsigned int channel; unsigned int pga = ADS1015_DEFAULT_PGA; @@ -927,7 +926,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) pga = pval; if (pga > 5) { dev_err(dev, "invalid gain on %pfw\n", node); - fwnode_handle_put(node); return -EINVAL; } } @@ -936,7 +934,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) data_rate = pval; if (data_rate > 7) { dev_err(dev, "invalid data_rate on %pfw\n", node); - fwnode_handle_put(node); return -EINVAL; } } From patchwork Sat Feb 24 12:32:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570402 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B0B518021 for ; Sat, 24 Feb 2024 12:33:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777989; cv=none; b=q3mIj7mEf55LRZy72cur+4egd0WcdcDveeG90XUziimmIdA6kDSKOPRJSXLMhRg0UG+/GqHoE/rXzCZah+dqtIYQ5tIUAT3ISNyAS78t+jNS+92ubJi7JIjIw3fpMU7rwTxovwnlRUZ+Bjl1jvM9ASnJX+R7bFS55mOp8KKCmCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777989; c=relaxed/simple; bh=7C5/bV8FIlY7Lha11lXdJR+AQbt/4ZZdKI46DPQNgkE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kaVKO9jmMx8zKXGUJTTyGeem28GHp46P1JJVcC+83NCMhO2VMN6ZMeRR0HWdGjniRUJ2nSanUxrIjsZiI6KyuBQ9fvGIaV7T09us5QlUdJvnZoiVZ+8CryLzuXzn3+jPCki+f99xn1Yl0efAw3sMXmH5Wgubamb0LKgjofzpOHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CEANi+lA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CEANi+lA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C752AC43390; Sat, 24 Feb 2024 12:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777989; bh=7C5/bV8FIlY7Lha11lXdJR+AQbt/4ZZdKI46DPQNgkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CEANi+lA0hb7+hlW43PdA+a72NL5oT2MmA/PMZQKO9RYvWO/w6LroR2JlUPf80zoY q6a3nlKEJLsX46CfhfpYVWtdvN/3I9ydATL/qw3xX5ITkK+z3VDPodnTbh60Ms9PfP zYPwD9nAW+mN0jJ+5H8UEwvN9mcfUHpQKGXn/5OgOPHKmbMTTiUGZfKZdG0+NdB7SA UOxDijPBrt3fLDmMBoshZnQdWxYq7kC7sjz8U+5eGcsyfm1wYgRaIICMbj4eFEKIfE 3R3h9E5uWb7cllPfSR1MpdpPrjL/8f+6UaCox8IrGOQoo9dEGnEbLrbdOnCVX1Nq1a ViBDB0mDduQbg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 7/9] iio: adc: ti-ads131e08: Use device_for_each_child_node_scoped() Date: Sat, 24 Feb 2024 12:32:13 +0000 Message-ID: <20240224123215.161469-8-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron 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. Cc: Tomislav Denis Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ti-ads131e08.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/ti-ads131e08.c b/drivers/iio/adc/ti-ads131e08.c index fcfc46254313..f653654f7c5d 100644 --- a/drivers/iio/adc/ti-ads131e08.c +++ b/drivers/iio/adc/ti-ads131e08.c @@ -694,7 +694,6 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) struct ads131e08_channel_config *channel_config; struct device *dev = &st->spi->dev; struct iio_chan_spec *channels; - struct fwnode_handle *node; unsigned int channel, tmp; int num_channels, i, ret; @@ -736,10 +735,10 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) return -ENOMEM; i = 0; - device_for_each_child_node(dev, node) { + device_for_each_child_node_scoped(dev, node) { ret = fwnode_property_read_u32(node, "reg", &channel); if (ret) - goto err_child_out; + return ret; ret = fwnode_property_read_u32(node, "ti,gain", &tmp); if (ret) { @@ -747,7 +746,7 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) } else { ret = ads131e08_pga_gain_to_field_value(st, tmp); if (ret < 0) - goto err_child_out; + return ret; channel_config[i].pga_gain = tmp; } @@ -758,7 +757,7 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) } else { ret = ads131e08_validate_channel_mux(st, tmp); if (ret) - goto err_child_out; + return ret; channel_config[i].mux = tmp; } @@ -784,10 +783,6 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) st->channel_config = channel_config; return 0; - -err_child_out: - fwnode_handle_put(node); - return ret; } static void ads131e08_regulator_disable(void *data) From patchwork Sat Feb 24 12:32:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570403 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BD3518021 for ; Sat, 24 Feb 2024 12:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777994; cv=none; b=h/a13d2aiaCe81/LOM6fL1TTTf4ISPWX2Y4x9n53N/wY6XJlmmRmh9GoZexcH3qsztdj5BvMQYR0KM6di76ILB/ZPLSudhbesTsUnAia2ITYeOoS0CZ4lrzorV2iFCbeo4lTxCiwhY+mVgzivW3q+e7YY+3m83UMkXbuNWlb600= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777994; c=relaxed/simple; bh=ZEX5V6rA/qW9iOHSltdQCogQSODPZOZ+ahDrhUmzuXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OFru3B52ijbe8PYZ0os5QjPnJ9HYwmNny2PESlVHrYmPIh3aHJ5K6ADQwvTV5EXIkpkpF7VwwgQrZrb/u6nRDu8Rjj3lCsEy7niq2Vl2jHZEKc+16zCq73sTqIB6YslSUJ4XPED7i/4Pdn5BpDhKLC6V9s1OFLWOVOY1tTgTz7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BHnaQHCW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BHnaQHCW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D10D4C433F1; Sat, 24 Feb 2024 12:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777993; bh=ZEX5V6rA/qW9iOHSltdQCogQSODPZOZ+ahDrhUmzuXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BHnaQHCWVKlV7sgvKhsgqCGbIyU1922hMsOKjubselcgzAfEYtvnKA4RGOMwTZRV0 vXfomgzxAW0EqrBwiSD6HBdQ6aRqawrxvpG8/qtI9lj4M5JVx9grc5igV/CoeADki5 lSOl9zM9lUZJJ1nBeqEWIFkU3bCnR9LkRuOGIN3IXYSSmsFIMAntAk8Pj0AI6euGHv SeoayNIyiMlgsQpOFvO1A+qsFk7OSlh69CgzcJvijOrLayPXWbaJwcMx4lB97zF4ik +Me7O5Lrxzy3qL+0mhaPFKZ0qv9JQOOP1/jUoOvto8rc4TBG/u+Jx2Arve2Z1ucwKc bnhR4pjF0llnQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 8/9] iio: dac: ad3552r: Use device_for_each_child_node_scoped() Date: Sat, 24 Feb 2024 12:32:14 +0000 Message-ID: <20240224123215.161469-9-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron 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. Removing the goto err; statements also allows more extensive use of dev_err_probe() further simplifying the code. Cc: Mihail Chindris Signed-off-by: Jonathan Cameron --- drivers/iio/dac/ad3552r.c | 51 +++++++++++++++------------------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/drivers/iio/dac/ad3552r.c b/drivers/iio/dac/ad3552r.c index a492e8f2fc0f..e14a065b29ca 100644 --- a/drivers/iio/dac/ad3552r.c +++ b/drivers/iio/dac/ad3552r.c @@ -880,7 +880,6 @@ static void ad3552r_reg_disable(void *reg) static int ad3552r_configure_device(struct ad3552r_desc *dac) { struct device *dev = &dac->spi->dev; - struct fwnode_handle *child; struct regulator *vref; int err, cnt = 0, voltage, delta = 100000; u32 vals[2], val, ch; @@ -949,53 +948,45 @@ static int ad3552r_configure_device(struct ad3552r_desc *dac) return -ENODEV; } - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { err = fwnode_property_read_u32(child, "reg", &ch); - if (err) { - dev_err(dev, "mandatory reg property missing\n"); - goto put_child; - } - if (ch >= AD3552R_NUM_CH) { - dev_err(dev, "reg must be less than %d\n", - AD3552R_NUM_CH); - err = -EINVAL; - goto put_child; - } + if (err) + return dev_err_probe(dev, err, + "mandatory reg property missing\n"); + if (ch >= AD3552R_NUM_CH) + return dev_err_probe(dev, -EINVAL, + "reg must be less than %d\n", + AD3552R_NUM_CH); if (fwnode_property_present(child, "adi,output-range-microvolt")) { err = fwnode_property_read_u32_array(child, "adi,output-range-microvolt", vals, 2); - if (err) { - dev_err(dev, + if (err) + return dev_err_probe(dev, err, "adi,output-range-microvolt property could not be parsed\n"); - goto put_child; - } err = ad3552r_find_range(dac->chip_id, vals); - if (err < 0) { - dev_err(dev, - "Invalid adi,output-range-microvolt value\n"); - goto put_child; - } + if (err < 0) + return dev_err_probe(dev, err, + "Invalid adi,output-range-microvolt value\n"); + val = err; err = ad3552r_set_ch_value(dac, AD3552R_CH_OUTPUT_RANGE_SEL, ch, val); if (err) - goto put_child; + return err; dac->ch_data[ch].range = val; } else if (dac->chip_id == AD3542R_ID) { - dev_err(dev, - "adi,output-range-microvolt is required for ad3542r\n"); - err = -EINVAL; - goto put_child; + return dev_err_probe(dev, -EINVAL, + "adi,output-range-microvolt is required for ad3542r\n"); } else { err = ad3552r_configure_custom_gain(dac, child, ch); if (err) - goto put_child; + return err; } ad3552r_calc_gain_and_offset(dac, ch); @@ -1003,7 +994,7 @@ static int ad3552r_configure_device(struct ad3552r_desc *dac) err = ad3552r_set_ch_value(dac, AD3552R_CH_SELECT, ch, 1); if (err < 0) - goto put_child; + return err; dac->channels[cnt] = AD3552R_CH_DAC(ch); ++cnt; @@ -1021,10 +1012,6 @@ static int ad3552r_configure_device(struct ad3552r_desc *dac) dac->num_ch = cnt; return 0; -put_child: - fwnode_handle_put(child); - - return err; } static int ad3552r_init(struct ad3552r_desc *dac) From patchwork Sat Feb 24 12:32:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13570404 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8A3C18021 for ; Sat, 24 Feb 2024 12:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777999; cv=none; b=EE9GD+EbsI/HIKD8HRVwNAcfOr8fLRsO5b3Y80WCx6GFc92p7K5HYQtJkyNVqLF9Ct+N27wc16K4umM/XQuTfi/adstfEcbsTAsJnq04/d/3sBf1xrr4FZpLd4M31Kzc86/DlVD7rHRVzkbMej7g3lzRbQrt3XMYocU6KlKNAlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708777999; c=relaxed/simple; bh=bG+TeFde3DyITfgrg0EFAq3aPgezHodRADkhJV7nv3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lHE4rkg6k9EiJpGGnfv7GpC6yR7uPAoZCPhLEVUfmoKOR3zk6GnGcV0khDn6zAMXp2bqnnDD79SuhtmzVpNMS+MVppp34l2xCy4zaCX7esGZkUsQqjB3iF4UotDP17HeBo/NExfOUMSns/GT3x739IoqBLcPO+LMmf+qO4xO18U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DWwEAJgg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DWwEAJgg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58EDDC43394; Sat, 24 Feb 2024 12:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708777999; bh=bG+TeFde3DyITfgrg0EFAq3aPgezHodRADkhJV7nv3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DWwEAJggptZzuDWJrnzPhXSyPGmCw/RoapJA6CGZMHvRd+Xs4efRuzx+slcnrJMBE lARvDp2FI5WkV7IopInR+JllUB2SARrBmXX39NELNdsoiNgyShkEpvfJNX6HfcyntW Dowc06ChD9vJB3XAuHA+n4iYDeaPKH2cLP46sOVBDEhH0UAEfIaXbKtbmhEh2SVUrL Ixw6T08gaA9zP/p4BmAsZ4eVlECbzZTJXEOrw+1pLq2ox4vIcUjknXX3hy1k0mHkjQ 2uMoVgWvj0F5a1hgcey0JMCExi8qBrYUs7p0k52IZislaVaHRHDVdK67xsLmx1Y1Pu xK2NV/+ValckA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Jonathan Cameron Subject: [PATCH v5 9/9] iio: dac: ad5770r: Use device_for_each_child_node_scoped() Date: Sat, 24 Feb 2024 12:32:15 +0000 Message-ID: <20240224123215.161469-10-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240224123215.161469-1-jic23@kernel.org> References: <20240224123215.161469-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron 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. Cc: Nuno Sá Signed-off-by: Jonathan Cameron --- drivers/iio/dac/ad5770r.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/iio/dac/ad5770r.c b/drivers/iio/dac/ad5770r.c index f66d67402e43..c360ebf5297a 100644 --- a/drivers/iio/dac/ad5770r.c +++ b/drivers/iio/dac/ad5770r.c @@ -515,39 +515,32 @@ static int ad5770r_channel_config(struct ad5770r_state *st) { int ret, tmp[2], min, max; unsigned int num; - struct fwnode_handle *child; num = device_get_child_node_count(&st->spi->dev); if (num != AD5770R_MAX_CHANNELS) return -EINVAL; - device_for_each_child_node(&st->spi->dev, child) { + device_for_each_child_node_scoped(&st->spi->dev, child) { ret = fwnode_property_read_u32(child, "reg", &num); if (ret) - goto err_child_out; - if (num >= AD5770R_MAX_CHANNELS) { - ret = -EINVAL; - goto err_child_out; - } + return ret; + if (num >= AD5770R_MAX_CHANNELS) + return -EINVAL; ret = fwnode_property_read_u32_array(child, "adi,range-microamp", tmp, 2); if (ret) - goto err_child_out; + return ret; min = tmp[0] / 1000; max = tmp[1] / 1000; ret = ad5770r_store_output_range(st, min, max, num); if (ret) - goto err_child_out; + return ret; } return 0; - -err_child_out: - fwnode_handle_put(child); - return ret; } static int ad5770r_init(struct ad5770r_state *st)