From patchwork Mon Jan 1 17:26: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: 13508669 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 0B0388BEA; Mon, 1 Jan 2024 17:26:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NDEVmXt7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F27B2C433CD; Mon, 1 Jan 2024 17:26:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704130016; bh=XhmZrqz6FVo7Im9712sd5TE93erFrXegh2LKQfoag6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NDEVmXt7bguP4UJ3dRk028QfF57QWf8Rsxelnhujd71JUAqpmdsHUOX2jzo3Sv/Va 9L7yoYIyvS/XVS+SRKbVgfS+67yZViRJA/EHOly6cDrCySxKEdsqGjAH+zPqoo1fHZ 6rp5HdPEOqN6WS9sHokLdL6BXyFKIDhr9UNMbuJOAEAAb+TpqxEtfQVeaLy+SXZQr1 JOUeUCjqwv5Yf07qGdNPAucZla2/BZfdkIF/WVGYDCpF4eWfGVybYJ10Aio2WRwvxk YEbbEmxtXq5diFPEQJ2lbV1bgBwLALZxB5nUH58yTiWrEPqyavxcPYR8mzn3SFB/Eu V6sAEz916jx5w== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus Cc: =?utf-8?q?Nuno_S=C3=A1?= , 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: [RFC PATCH 04/13] iio: adc: qcom-spmi-adc5: Use __free(fwnode_handle) to replace fwnode_handle_put() calls Date: Mon, 1 Jan 2024 17:26:02 +0000 Message-ID: <20240101172611.694830-5-jic23@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240101172611.694830-1-jic23@kernel.org> References: <20240101172611.694830-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@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 within the device_for_each_child_node(dev, child) loop. On normal exit from that loop no fwnode_handle reference will be held and the child pointer will be NULL thus making the automatically run fwnode_handle_put() a noop. 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. Signed-off-by: Jonathan Cameron Cc: Dmitry Baryshkov Cc: Marijn Suijten --- drivers/iio/adc/qcom-spmi-adc5.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c index b6b612d733ff..36d3912d36df 100644 --- a/drivers/iio/adc/qcom-spmi-adc5.c +++ b/drivers/iio/adc/qcom-spmi-adc5.c @@ -825,7 +825,7 @@ 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; + struct fwnode_handle *child __free(fwnode_handle) = NULL; unsigned int index = 0; int ret; @@ -851,10 +851,8 @@ static int adc5_get_fw_data(struct adc5_chip *adc) device_for_each_child_node(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;