Skip to content

Commit c5042a9

Browse files
committed
device property: Introduce device_for_each_child_node_scoped()
JIRA: https://issues.redhat.com/browse/RHEL-66957 CVE: CVE-2024-50197 commit 365130f Author: Jonathan Cameron <Jonathan.Cameron@huawei.com> Date: Sat Feb 17 16:42:38 2024 +0000 device property: Introduce device_for_each_child_node_scoped() 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. Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> Link: https://lore.kernel.org/r/20240217164249.921878-5-jic23@kernel.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Steve Best <sbest@redhat.com>
1 parent 9fed417 commit c5042a9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

include/linux/property.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ struct fwnode_handle *device_get_next_child_node(const struct device *dev,
141141
for (child = device_get_next_child_node(dev, NULL); child; \
142142
child = device_get_next_child_node(dev, child))
143143

144+
#define device_for_each_child_node_scoped(dev, child) \
145+
for (struct fwnode_handle *child __free(fwnode_handle) = \
146+
device_get_next_child_node(dev, NULL); \
147+
child; child = device_get_next_child_node(dev, child))
148+
144149
struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
145150
const char *childname);
146151
struct fwnode_handle *device_get_named_child_node(const struct device *dev,

0 commit comments

Comments
 (0)