From patchwork Sat Mar 30 18:52:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611650 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 B664A2E3E5 for ; Sat, 30 Mar 2024 18:53:26 +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=1711824806; cv=none; b=Qe3N8UeSOyVJMD9EnnsmP8JCYT4t+iGn8gNc78gFmWqJ6K1DtGeb/RvPkBu+waclzPnlSgn6Qfr84xrBiYfvREqwjgqBLtw1VOEFnCwuGrwaTl2nRJBIgb8i9UQjIMW/k2BfSjCNezcG+LfPcGyiFjTxaOEoop4gB8ArAD//dJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711824806; c=relaxed/simple; bh=t+c4BrYzejAt75RJ2Qxn/cvI2ZbHxIHAKbFEFaGQriQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q8kI5RpTe8rqADevoaBrGdow1YOJLiwc5QWGvS5Yl294K+elBukB61TCtlk7i1QXS6sdkURIAZ80Vd7x4aLi/hobIpTv3yL4tI6xf7yNfeNepDvgnlH3rBU9Xv3wTZ7t6EY7zbv1qZymE+lL1IZNuU1pBeYN66BfUk48n8i/feE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lv2w+yS2; 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="lv2w+yS2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EEC4C433F1; Sat, 30 Mar 2024 18:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711824806; bh=t+c4BrYzejAt75RJ2Qxn/cvI2ZbHxIHAKbFEFaGQriQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lv2w+yS2argUWG6/gjobWEqNWS+BQoiaTWOOZdIulXZyccVv54CWxk4VBTmN6YiZL FmIXs/0t5eNgjIAToFUouVfHho5q1rI3mgZqoIcLcq16an+J7dtP5Bn9/fKnSOvHfo 46S02dVtMQ3RUmtbfHG2/ByJ9ZkDBA2dsi7aq57zJ/WUFDYKmWwjXuJpT47QUwkAI/ S2g+evi7fZuSaOq5JGCvsr2+kc+kBuPz1gtlpam58dj5oP71NeGiv52XogQ4t8wMXw GVf5JzqD6oA2Fx8ImXCiSfwztQbQJc89Oum/zOtOJRzVB19MhrqoGYJC4VeDcB9tPQ Dlw1Hrh/NPk9Q== 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 v6 1/8] iio: adc: mcp3564: Use device_for_each_child_node_scoped() Date: Sat, 30 Mar 2024 18:52:58 +0000 Message-ID: <20240330185305.1319844-2-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330185305.1319844-1-jic23@kernel.org> References: <20240330185305.1319844-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 Mar 30 18:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611651 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 189372E3E5 for ; Sat, 30 Mar 2024 18:53:30 +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=1711824811; cv=none; b=YxmNF+krvXbiyVNVE35pYYgCU4MHDbAWc1CSk6xsfYLlO5wgK7G/BapLwFHdFA5BzFO9kWOvUnpRzL5Rue9AGvU39OiQK1jMzNE63Qlzs99b9yGbosN5qGSHHJJ1X+1OXNAgC3C80DXIzUUmN4unMG8AHxt+zdj/yQCA2UuYhTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711824811; c=relaxed/simple; bh=6GckLYsNuC3zH2eXzNl8m+O6ErjjCU39FK09wLysA60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j0xd1jmROWwMhfagkXOJ+ps/EdEBTFo5Yc4yJAMeQk0IjBSZkiorOyYpWVJkGtJPtbFvcvasasGM0pCVtOIBe5junv/eadmCj9qaNZeOEliVI+UvnCT/Zf0QYqMBecrGhg5rOzqYfODBG16zz3LXGJ7dWUYwF/9fD3BMrwlSeRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qcr2f2kF; 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="qcr2f2kF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA70EC433C7; Sat, 30 Mar 2024 18:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711824810; bh=6GckLYsNuC3zH2eXzNl8m+O6ErjjCU39FK09wLysA60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qcr2f2kF52THMLloiyJj4FzmpfmsPfEKfMzrgDXGtBxIlLQXsCfYIIspKBLH+bn++ CqFxPusnD9Ax1KrS6gf7sXlcX78gWzQhwIjCZjpOzP6MlDYJH4UqqFdATiEK/Po0zs 3WGJB+H6K7bZzyTxB05zM4SZhX8uUxlJkzWXxzlCHSPlFNN87kgdlKT2tZzLbkxKfP bueXiFtVBq+nPqhRgpadNLgZVodc3guoePARQMMbdzYb8//QYXJwR74Y0RxPAISrus MLCVQK4dBcH+wq2W4d2xPqzmm3QRYKGbMMr6DSH5eWTZxtvO4G9DMNdBvVhX0oTc63 oo5URrnozD7lQ== 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 v6 2/8] iio: adc: qcom-spmi-adc5: Use device_for_each_child_node_scoped() Date: Sat, 30 Mar 2024 18:52:59 +0000 Message-ID: <20240330185305.1319844-3-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330185305.1319844-1-jic23@kernel.org> References: <20240330185305.1319844-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 Mar 30 18:53:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611652 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 234A53BBD8 for ; Sat, 30 Mar 2024 18:53:35 +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=1711824816; cv=none; b=GbU3V6LM7FQJO3yWZy3dT0HcXlPAo3l4FKQ5Sa0U40hSuggu/B8Z6fDWxyfPateVx+OMI5O+2UlAkfJD/WSMfLo29hkxUSQFlcxNi+JgtMXY+xyeH2oKpSxylV8ONvAdL0bu2iXb3XdTsh2aDBH/LnsDe5xkYDBxvZZPRIVdaPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711824816; c=relaxed/simple; bh=PSB86HBqhFM/Jq33fgYAZAnTAFpcofY1CqBhWw+Va8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sPDqEEMcSFMFXKuigEWfB9obQ1ke3/TgFhLegI7AGxZNTRMiSoKWSumCC7onDL83C0jRIjc2b0Z1NPDqtqFL6Mku6+Q8qyS4LYPpkgr4hIYQkr+QAh3FzjqdgpI4eQDjfcOM83i25spFnTqHaddeobJ9X16IhMotafad+QrJqWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uVATFS1Q; 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="uVATFS1Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44A2CC43390; Sat, 30 Mar 2024 18:53:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711824815; bh=PSB86HBqhFM/Jq33fgYAZAnTAFpcofY1CqBhWw+Va8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uVATFS1Q+iIuiZK2V/CYsMnJh1zPLPVNiaZTOwyC6+ymdgVl448jBvymVyvEd96p4 5AJNVKIviuwSvdZYRTYL09wyZM1iL2EiV0h51TL4xQmn6yaa+ypME6b8HeheipJCOx PHe4kFws3Q0NfiSp0ThfM5ze37RZKI5320xoVxforPrRPoLXoXr5XXwV/5PEPRnNgx oJ0uRueSk4oshtl4NpxtWTlIy5gaGyFgKbbz4dcu43QsPt8Yz0LMcUlryO81Hz4kcc 9PZqYwOU5lLdnNXEqWqb7C0yraYYNGcZOAfcNFUBrgYGHMdn9MrKQXRSoACFyfibSs QeU79dPgrkY1Q== 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 v6 3/8] iio: adc: stm32: Fixing err code to not indicate success Date: Sat, 30 Mar 2024 18:53:00 +0000 Message-ID: <20240330185305.1319844-4-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330185305.1319844-1-jic23@kernel.org> References: <20240330185305.1319844-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 path would result in returning 0 / success on an error path. Cc: Olivier Moysan Cc: Fabrice Gasnier Fixes: 95bc818404b2 ("iio: adc: stm32-adc: add support of generic channels binding") Signed-off-by: Jonathan Cameron Reviewed-by: Fabrice Gasnier --- drivers/iio/adc/stm32-adc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index b5d3c9cea5c4..283c20757106 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -2234,6 +2234,7 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, 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]); + ret = -EINVAL; goto err; } } else if (ret != -EINVAL) { From patchwork Sat Mar 30 18:53:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611653 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 CBF922E3E5 for ; Sat, 30 Mar 2024 18:53: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=1711824820; cv=none; b=ESPImAwBxSmH2QGk5nuBcfhrjt/6EygIMA2H7YBohgBEAwWAd2FVb9V/87tdQ6mZu8bzT1xRfrQQLwMaNwAxtp9aIa+7ZuWgoNfPlVGT5IpDLMK/LztWJ8a8BFakkf0t97WVLGPvFJ89nvkoJmSpW4ClEu0Rkeo/fnFGCzDwD/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711824820; c=relaxed/simple; bh=GyZokidgfiKOI3dm6Xikc4mrpsDk2vVQCCEtCsT2gqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UayW1Yr8X0xL7ncn7NR4NOf4VVx9sgj4ZoT0bnRHluxziRv1dAfczYKqC9oYMLQhnD5GJMimVsxzWZArTbuVNdclZ+Q6hQaIi4GlJnPb7m+s9W+fLGvdKZ42zdF7b4GDVMFSRiHU74xxoI8dZUN3p7WQT9DbUgLZSuiuTW1jIwo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u7dHe0Fn; 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="u7dHe0Fn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D401C433F1; Sat, 30 Mar 2024 18:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711824820; bh=GyZokidgfiKOI3dm6Xikc4mrpsDk2vVQCCEtCsT2gqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u7dHe0FnnZuLcYUOa8Y1bj/phv/03qUdfH5DGggdFM9kqJwC/RuB78OeuKWouZP3Y sRFgY0CYWEfyWZ0ASaKLYUrodkvrOT2YWeqO3EzFAFJZU3q/QruICnR7n0VRLFOfd4 NMj4DXrYbU0TEYCeyR2EaD72CztVCg2/7Ep67h4RK++HzMdTA+GMkWVv3ntTaHWTST kXDtOwrbzQ8lSB1MpRrz4xBG4l6RqmZM0T7JtRAxAWIezJ+18P6MPbT7+AHzm3rfGM derqrCYFkjq2oQHNI5mULAVZGczt+akMh0LVI1mLY1SJ5fwOMM1asy12IEXWzHFR6U W6mMEXTWZXidg== 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 v6 4/8] iio: adc: stm32: Use device_for_each_child_node_scoped() Date: Sat, 30 Mar 2024 18:53:01 +0000 Message-ID: <20240330185305.1319844-5-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330185305.1319844-1-jic23@kernel.org> References: <20240330185305.1319844-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 would have made the bug fixed in the previous path much less likely as it allows for direct returns. 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 Tested-by: Fabrice Gasnier Acked-by: Fabrice Gasnier Signed-off-by: Jonathan Cameron --- drivers/iio/adc/stm32-adc.c | 62 ++++++++++++++----------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index 283c20757106..36add95212c3 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -2187,59 +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]); - ret = -EINVAL; - 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, @@ -2248,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) @@ -2262,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 Mar 30 18:53:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611654 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 9E8A92E3E5 for ; Sat, 30 Mar 2024 18:53:46 +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=1711824826; cv=none; b=m6qhQQVc/jNoXcxdZTzdiKXiLsP2+Hoau5+tLW3sT6/KOO3L7ge2B3f1bp1/4WXZ7SxAWRyaPk5aGyz4+BldjNXdaaG8uSkSR2Rz6gMVc/wwWzktUAet+OChM1kolHRDK5+4aAivlqY8z6bf2MwTgg7yF3nQRrGBqzbyXE0M4Xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711824826; c=relaxed/simple; bh=ruJKwM0lQj1GeEvjHu7rz30w3dvlpzqaiQm4QjXLSRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=asNrYIz2ic2XCfpkONdkdzaZiT32LAJlttkhB7XlVziBb5boJlov7pKRJKXAgI8Z3i23Wn0I4MbSxI6th3e/dwst3nNkA3OzO32BgXLZuv4ew5XENeshzGg9WisJGIYQF0h7u5wu260sRewyBqLIPO0M4rL05xE3VIW6CIOQFBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NIfRsIHG; 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="NIfRsIHG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8F18C43399; Sat, 30 Mar 2024 18:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711824826; bh=ruJKwM0lQj1GeEvjHu7rz30w3dvlpzqaiQm4QjXLSRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NIfRsIHGRUveOz2y1fL7MpofW7mdoXO4G8u4KrOiZzoNTGOgna37NRM4Oinuzh70g T7fFW/hAMIwMSQEUVWNbgC8wDkijh7yEl2JctNoP+8CHaMFgMWw0xccZgZ1bXamIk9 iGcyjiaBsIlsBQg5ARjLVMgPHRBtwtDxwEqx5Glymgs2HtoIUUxJEIr6gtJplZkRHy fhe5l5WbnuY8zKw6iOlPxXvgi+c3CiJaEcjJbnt+TbgvhPzoEan7OKExakWi++zN1w MOFiKVHtV3mJ2nSOmxyKpE9x2s3CodFxP5SQ3MHbyiXbm+n1nBlWmGufffwLDMNimp IEyxs24Rj+SWA== 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 v6 5/8] iio: adc: ti-ads1015: Use device_for_each_child_node_scoped() Date: Sat, 30 Mar 2024 18:53:02 +0000 Message-ID: <20240330185305.1319844-6-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330185305.1319844-1-jic23@kernel.org> References: <20240330185305.1319844-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 Mar 30 18:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611655 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 C6D272E3E5 for ; Sat, 30 Mar 2024 18:53:52 +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=1711824832; cv=none; b=Wbfag9K274hiV/Oh+wpxKpnOvqglgmIxVeLwJrJE7FAoANyxTVmrvRKj+WyZtYZuWKwjeV7f9eyRpP+j08PKCedp5reN8PoZ/yxib1S+CmxvJ2Qs3ZE4cGabAeMrLR9KtBunNkUvfE25TBJIlfRcNHpKXkdV9+dwcDliqKro6b0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711824832; c=relaxed/simple; bh=7C5/bV8FIlY7Lha11lXdJR+AQbt/4ZZdKI46DPQNgkE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IAMkRJ8ZbYz+5WsTXes6dIJb2w/SxcGIPvhgc7DEtu5xm+D1icRmyFDfhyjUUCfOVFTAmY5pWjXjypYYvTyWq9E1l0doGwQxr+XL4llUA6OQKhWxYyAICKAzJhnMy4nowhkAUby+v9Csm4JBnqnbIOCx8i5FPTCwZoIYEYW85+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KFXZ7mPn; 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="KFXZ7mPn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB952C43390; Sat, 30 Mar 2024 18:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711824832; bh=7C5/bV8FIlY7Lha11lXdJR+AQbt/4ZZdKI46DPQNgkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KFXZ7mPnE9+zInmeW5/h1D1oYZsXsMQ2aSWlaEVI5eMiDRDHzjjevzVRPenONO3Ra RePlYPzKZnt3y+J5daHzW6l5kuC/GzJVzkfD+mLyZvG4DH/X3+j26MZpjRs0YYELXz DWe966QlPvL4JjMkphcN3dSwf8tR2NA33ajWehSHxIerXQPhdSE8FOlBbHnC2YTwdD BL4F/mHloTMs74GMsvPtdY03/Swy1T4mkoWz205vNlSnTkGzzWZNTHmI4X81fb4GLV cXl3hQj7X3C9JQh2rvD+wF5ryFCRVrr90RzqIvq4besP4j/uzj26kbyAIX5A+aRpxU jtvfibGmtIKSw== 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 v6 6/8] iio: adc: ti-ads131e08: Use device_for_each_child_node_scoped() Date: Sat, 30 Mar 2024 18:53:03 +0000 Message-ID: <20240330185305.1319844-7-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330185305.1319844-1-jic23@kernel.org> References: <20240330185305.1319844-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 Mar 30 18:53:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611656 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 494B82E3E5 for ; Sat, 30 Mar 2024 18:53: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=1711824838; cv=none; b=tO4FLFYU/jXxrJ7cOBYgJuI3lw+56pPwbZ9v2lQApIBISfCWH29YuB9pL5mFjYuK1pLST5PJ1EYsJ+7a7IoMwhM4RVB5Lbor/P79hTE6th/QbnnxxGLbJRF1HcO1nKhY8RKb7BN8jA+UzJIKYgbQ+ftXt6k8B43VsciCaIQvpVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711824838; c=relaxed/simple; bh=ZEX5V6rA/qW9iOHSltdQCogQSODPZOZ+ahDrhUmzuXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HO5+LgY665lbR/2bNcu7D8eeQaq52ACUc87IKoYVSmVOv9vtsObNgY/98Q8ApD8n3ENDpqiJqzkQ9t+hfFL5wHQ9kwAURKNvA52tVK6l0UVb+g0RtPilmCovSWVWv0k+36YrqXuJml5HddZRy0Yv8QVwWFzWmVeOwfT1lCEWk58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DL6QgJIF; 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="DL6QgJIF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7EE1C433C7; Sat, 30 Mar 2024 18:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711824837; bh=ZEX5V6rA/qW9iOHSltdQCogQSODPZOZ+ahDrhUmzuXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DL6QgJIFLGQNBn3eexFoRBN+yc12j0lsHANgcnuMBH7Xn0QShWgpoTj7b5WTjHbUl RBj9tK+aUGYj849qEp+baW373VDhr0E/CsT5CM7yMXIDp1CYnU350WHXKYAR6nLIiL K7liwidi4Q9FiI3kKoiZ3V4x02I4JIVL+1CBz548o/APhaJfaJYbTBCFJ7cj6URLhK YRrUbGEYb+Vxvc7t9X9V/xnceunV52rgRh6cttOtzCEuwAIsskW8WCz7T9NnV4U2Qb HIXwrxUiHz2zyIRUtp+gJ2k0Ucl9PopdQQOhr+OKWjYOr1LMXtRX6m+VnFJV8pI2U3 v1jiPHLYHIbGw== 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 v6 7/8] iio: dac: ad3552r: Use device_for_each_child_node_scoped() Date: Sat, 30 Mar 2024 18:53:04 +0000 Message-ID: <20240330185305.1319844-8-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330185305.1319844-1-jic23@kernel.org> References: <20240330185305.1319844-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 Reviewed-by: Nuno Sa --- 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 Mar 30 18:53:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13611657 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 6DD613D0D2 for ; Sat, 30 Mar 2024 18:54: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=1711824843; cv=none; b=izErZUV7dM0jNxR/lXBbcYkhpLiCc9yeU9M0kZzfWplKuYoyNwgKVgek/Pm3wQ8OZQdyCaHzldeSQgVlaiejmWIdlQTU5mgPSR3M4raPlCztRq0qc0TXEUfRsZtEJMdUJgsGsDz002rcFXR1lRTQxrnxBiUWS9VYb+qML6E5XSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711824843; c=relaxed/simple; bh=bG+TeFde3DyITfgrg0EFAq3aPgezHodRADkhJV7nv3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VezzQaEci+2VXHgl2JG5KwmTIGfgW+NPLrD+UTPGtGbcp5kq94l2uKPDi6C1wWtmHplBeMEh/KZc2rzVRHT19QlZl+LhsvaWsfm60Hf8MSWOr2CwYtQLd1DrOEJhvbx7c8YsNdqZgrWkCGrHFDdsnspTUMmq3kTgvsAQ+/XMx2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dea63eox; 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="Dea63eox" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93C62C433F1; Sat, 30 Mar 2024 18:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711824843; bh=bG+TeFde3DyITfgrg0EFAq3aPgezHodRADkhJV7nv3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dea63eoxYo5tNDPyNC0FXIEzYu0ETvTcYUQLfIt4XtAhTqB4+fZ2/Rozkr3baquyO 9XOHkOEYuC2v6dULvKQWuKAN7w5ipLRZsyg1Kmgn8hyPt0GSf9VHj5nuuzDkqX0BUW CHmbh23DqqyLPSYWDVumYPER3u2YDLUbzkW+gDO/l8I+Wofei6Mswh7P4MvReO69ZJ +TSqYbbnxJ0MgTJwG1+Q9UAEAVOI7xaAUttEsdg7+4k1tfHayLpBbIHV3amn/MQKhn Dx0KNecQHpOEAAw3AQPOwDQdoeMPdH0+pjujnEODfqekcGuZpkclRKW6IZU+vK7Eyd EGdsEkJbuXbQA== 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 v6 8/8] iio: dac: ad5770r: Use device_for_each_child_node_scoped() Date: Sat, 30 Mar 2024 18:53:05 +0000 Message-ID: <20240330185305.1319844-9-jic23@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240330185305.1319844-1-jic23@kernel.org> References: <20240330185305.1319844-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 Reviewed-by: Nuno Sa --- 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)