[PATCH 1/4] device property: Introduce fwnode_graph_for_each_endpoint_scoped()

G.N. Zhou guoniu.zhou at nxp.com
Tue Jun 23 19:54:55 PDT 2026


Hi Frank,

> -----Original Message-----
> From: Frank Li (OSS) <frank.li at oss.nxp.com>
> Sent: Monday, June 22, 2026 10:30 PM
> To: Andy Shevchenko <andriy.shevchenko at linux.intel.com>; Daniel Scally
> <djrscally at gmail.com>; Heikki Krogerus <heikki.krogerus at linux.intel.com>;
> Sakari Ailus <sakari.ailus at linux.intel.com>; Greg Kroah-Hartman
> <gregkh at linuxfoundation.org>; Rafael J. Wysocki <rafael at kernel.org>; Danilo
> Krummrich <dakr at kernel.org>; Mauro Carvalho Chehab
> <mchehab at kernel.org>; Dafna Hirschfeld <dafna at fastmail.com>; Laurent
> Pinchart <laurent.pinchart at ideasonboard.com>; Heiko Stuebner
> <heiko at sntech.de>; Bryan O'Donoghue <bryan.odonoghue at linaro.org>;
> Vladimir Zapolskiy <vladimir.zapolskiy at linaro.org>; Loic Poulain
> <loic.poulain at oss.qualcomm.com>
> Cc: driver-core at lists.linux.dev; linux-acpi at vger.kernel.org; linux-
> kernel at vger.kernel.org; linux-media at vger.kernel.org; linux-
> rockchip at lists.infradead.org; linux-arm-kernel at lists.infradead.org; linux-arm-
> msm at vger.kernel.org; imx at lists.linux.dev; G.N. Zhou
> <guoniu.zhou at nxp.com>; Frank Li <frank.li at nxp.com>
> Subject: [PATCH 1/4] device property: Introduce
> fwnode_graph_for_each_endpoint_scoped()
> 
> From: Frank Li <Frank.Li at nxp.com>
> 
> Similar to recently propose for_each_child_of_node_scoped() this new version
> of the loop macro instantiates a new local struct fwnode_handle * that uses the
> __free(fwnode_handle) auto cleanup handling so that if a reference to a node is
> held on early exit from the loop the reference will be released. If the loop runs
> to completion, the child pointer will be NULL and no action will be taken.
> 
> The reason this is useful is that it removes the need for
> fwnode_handle_put() on early loop exits.  If there is a need to retain the
> reference, then return_ptr(child) or no_free_ptr(child) may be used to safely
> disable the auto cleanup.
> 
> Signed-off-by: Frank Li <Frank.Li at nxp.com>

Reviewed-by: Guoniu Zhou <guoniu.zhou at oss.nxp.com>

> ---
>  include/linux/property.h | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/include/linux/property.h b/include/linux/property.h index
> 14c304db46648..ade194c462d42 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -545,6 +545,11 @@ unsigned int
> fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode,
>  	for (child = fwnode_graph_get_next_endpoint(fwnode, NULL); child;
> 	\
>  	     child = fwnode_graph_get_next_endpoint(fwnode, child))
> 
> +#define fwnode_graph_for_each_endpoint_scoped(fwnode, child)
> 		\
> +	for (struct fwnode_handle *child __free(fwnode_handle) =
> 	\
> +			fwnode_graph_get_next_endpoint(fwnode, NULL);
> 		\
> +	     child; child = fwnode_graph_get_next_endpoint(fwnode, child))
> +
>  int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
>  				struct fwnode_endpoint *endpoint);
> 
> 
> --
> 2.43.0



More information about the linux-arm-kernel mailing list