Re: [RFC PATCH 1/4] of: Add cleanup.h based autorelease via __free(device_node) markings.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Dec 17, 2023 at 06:46:45PM +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> 
> The recent addition of scope based cleanup support to the kernel
> provides a convenient tool to reduce the chances of leaking reference
> counts where of_node_put() should have been called in an error path.
> 
> This enables
> 	struct device_node *child __free(device_node) = NULL;
> 
> 	for_each_child_of_node(np, child) {
> 		if (test)
> 			return test;
> 	}
> 
> with no need for a manual call of of_node_put()
> 
> In this simile example the gains are small but there are some very

typo

> complex error handling cases burried in these loops that wil be
> greatly simplified by enabling early returns with out the need
> for this manual of_node_put() call.

Neat!

I guess that now that the coccinelle check has fixed many, we can update 
it to the new way and start fixing them all again. We should update the 
coccinelle script with the new way. See 
scripts/coccinelle/iterators/for_each_child.cocci.

> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> ---
>  include/linux/of.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 6a9ddf20e79a..50e882ee91da 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -13,6 +13,7 @@
>   */
>  #include <linux/types.h>
>  #include <linux/bitops.h>
> +#include <linux/cleanup.h>
>  #include <linux/errno.h>
>  #include <linux/kobject.h>
>  #include <linux/mod_devicetable.h>
> @@ -134,6 +135,7 @@ static inline struct device_node *of_node_get(struct device_node *node)
>  }
>  static inline void of_node_put(struct device_node *node) { }
>  #endif /* !CONFIG_OF_DYNAMIC */
> +DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))

of_node_put() can be called with NULL, so do we need the "if (_T)"?

Rob




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux