Files
LibreELEC.tv/projects/Amlogic/devices/AMLGX/patches/linux/amlogic-0038-TEST-device-property-Add-scoped-fwnode-child-node-it.patch
Christian Hewitt ec432fefb2 linux: update Amlogic patches for Linux 6.16.y
Signed-off-by: Christian Hewitt <christianshewitt@gmail.com>
2025-09-12 09:12:27 +00:00

55 lines
2.2 KiB
Diff

From 5ddfb27c0b310e3431336250c2ccf2fda3d8ddb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Lessard?= <jefflessard3@gmail.com>
Date: Mon, 1 Sep 2025 12:16:39 -0400
Subject: [PATCH 38/54] TEST: device property: Add scoped fwnode child node
iterators
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Add scoped versions of fwnode child node iterators that automatically
handle reference counting cleanup using the __free() attribute:
- fwnode_for_each_child_node_scoped()
- fwnode_for_each_available_child_node_scoped()
These macros follow the same pattern as existing scoped iterators in the
kernel, ensuring fwnode references are automatically released when the
iterator variable goes out of scope. This prevents resource leaks and
eliminates the need for manual cleanup in error paths.
The implementation mirrors the non-scoped variants but uses
__free(fwnode_handle) for automatic resource management, providing a
safer and more convenient interface for drivers iterating over firmware
node children.
Signed-off-by: Jean-François Lessard <jefflessard3@gmail.com>
---
include/linux/property.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/linux/property.h b/include/linux/property.h
index f718dd4789e5..8d119ee9f04a 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -175,6 +175,16 @@ struct fwnode_handle *fwnode_get_next_available_child_node(
for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\
child = fwnode_get_next_available_child_node(fwnode, child))
+#define fwnode_for_each_child_node_scoped(fwnode, child) \
+ for (struct fwnode_handle *child __free(fwnode_handle) = \
+ fwnode_get_next_child_node(fwnode, NULL); \
+ child; child = fwnode_get_next_child_node(fwnode, child))
+
+#define fwnode_for_each_available_child_node_scoped(fwnode, child) \
+ for (struct fwnode_handle *child __free(fwnode_handle) = \
+ fwnode_get_next_available_child_node(fwnode, NULL); \
+ child; child = fwnode_get_next_available_child_node(fwnode, child))
+
struct fwnode_handle *device_get_next_child_node(const struct device *dev,
struct fwnode_handle *child);
--
2.34.1