From patchwork Sun Jan 14 17:20: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: 762714 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 896357472; Sun, 14 Jan 2024 17:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F7OPfXHL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB017C43390; Sun, 14 Jan 2024 17:21:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705252894; bh=Xck5I1hYjTLAEfCDEfFC6mPWv+xN4t0mw2SUHT7GTaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F7OPfXHLujKyqjNZfAOKUsfhni0naubAbMp3pGysfIBYL6f3PutBMd3jJxdv4vHAF 6L4uNTNB28GX8Y1qStEiIi/7PL0H07+ijvqWwUCAfT22cE0mK2eubPnCHwjDGmgsqe hV52BnTKvcpbLJjGjJWTiztPdl8YJtmaC7+uwdtZqKFGq4qoo4RWSHGwF2S+YiuQGg 4rP8iXuEc/pK9g6k2sOiqerUvStLzDUAhRPtESnn6MHs9nGN5Ut4NipQO/OM80ep+S wrAiziIWhVX3urK99FhopXyrfUdyxwssw1wE4KEErwn9OQjgTDlhcA0apeoOsOV/aF 69B3gAeYNxF0A== 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: [PATCH 11/13] iio: dac: ad5770r: Use __free(fwnode_handle) to replace fwnode_handle_put() calls Date: Sun, 14 Jan 2024 17:20:07 +0000 Message-ID: <20240114172009.179893-12-jic23@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240114172009.179893-1-jic23@kernel.org> References: <20240114172009.179893-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. Cc: Nuno Sá Signed-off-by: Jonathan Cameron --- drivers/iio/dac/ad5770r.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/iio/dac/ad5770r.c b/drivers/iio/dac/ad5770r.c index f66d67402e43..782a04406576 100644 --- a/drivers/iio/dac/ad5770r.c +++ b/drivers/iio/dac/ad5770r.c @@ -515,7 +515,7 @@ static int ad5770r_channel_config(struct ad5770r_state *st) { int ret, tmp[2], min, max; unsigned int num; - struct fwnode_handle *child; + struct fwnode_handle *child __free(fwnode_handle) = NULL; num = device_get_child_node_count(&st->spi->dev); if (num != AD5770R_MAX_CHANNELS) @@ -524,30 +524,24 @@ static int ad5770r_channel_config(struct ad5770r_state *st) device_for_each_child_node(&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)