From patchwork Mon Jan 1 17:25: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: 13508655 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 88BE48BE0; Mon, 1 Jan 2024 17:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oCtC1+8c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02C6AC433C8; Mon, 1 Jan 2024 17:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704129994; bh=BRaVc0TznsbmBTXUWQHMuKv0f+AicWQysz8AaK2k0wQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oCtC1+8cB8LW0WFsDQJXZUsSo12ZPPD138R80YVZ1abB+98mjBIuKs7MUKkFqrjPE JljALIHKOUiAMO7eUmIgGrk4GnBf8t5Z2W71ZHAzPH7udeNEIylwC69xx0uw6B0wBn CgYWGmnCtjubX1lNzVeO/VgeFFoIEk1JAOkn2ayB1T/yml9tAIXs96JPANjNs79sLk dF+vGd+tkgL4NnnFoMZhH6m79NrwJ00hS5BBZHwDs1OjgUi/BjS5t7BuIGfeRa1CPD VY3PUds8yhXU0fSVlL4xbOAzpvOkul6g3ov/e3zte5+x/gXH+l3wZDPXeMIFwN7Kpg XJ+18cbU4EPoA== 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 01/13] device property: Add cleanup.h based fwnode_handle_put() scope based cleanup. Date: Mon, 1 Jan 2024 17:25:59 +0000 Message-ID: <20240101172611.694830-2-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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This allows the following struct fwnode_handle *child __free(kfree) = NULL; device_for_each_child_node(dev, child) { if (false) return -EINVAL; } without the fwnode_handle_put() call which tends to complicate early exits from such loops and lead to resource leak bugs. Can also be used where the fwnode_handle was obtained from a call such as fwnode_find_reference() as it will safely do nothing if IS_ERR() is true. Signed-off-by: Jonathan Cameron --- include/linux/property.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 2b8f07fc68a9..135ac540f8fe 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -161,6 +162,7 @@ struct fwnode_handle *device_get_named_child_node(const struct device *dev, struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode); void fwnode_handle_put(struct fwnode_handle *fwnode); +DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T)) int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name);