Skip to content

Commit f940a54

Browse files
committed
of: Add for_each_reserved_child_of_node()
JIRA: https://issues.redhat.com/browse/RHEL-77190 commit 28c5d4e Author: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Date: Wed Jan 10 01:14:50 2024 +0000 of: Add for_each_reserved_child_of_node() We would like to use for_each loop for status = "reserved" nodes. Add for_each_reserved_child_of_node() for it. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Tested-by: Yusuke Goda <yusuke.goda.sx@renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Rob Herring <robh@kernel.org> Link: https://lore.kernel.org/r/87a5pegfau.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Radu Rendec <rrendec@redhat.com>
1 parent 8b24722 commit f940a54

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

drivers/of/base.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,20 @@ static bool __of_device_is_available(const struct device_node *device)
464464
__of_device_is_status(device, ok);
465465
}
466466

467+
/**
468+
* __of_device_is_reserved - check if a device is reserved
469+
*
470+
* @device: Node to check for availability, with locks already held
471+
*
472+
* Return: True if the status property is set to "reserved", false otherwise
473+
*/
474+
static bool __of_device_is_reserved(const struct device_node *device)
475+
{
476+
static const char * const reserved[] = {"reserved", NULL};
477+
478+
return __of_device_is_status(device, reserved);
479+
}
480+
467481
/**
468482
* of_device_is_available - check if a device is available for use
469483
*
@@ -649,6 +663,21 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
649663
}
650664
EXPORT_SYMBOL(of_get_next_available_child);
651665

666+
/**
667+
* of_get_next_reserved_child - Find the next reserved child node
668+
* @node: parent node
669+
* @prev: previous child of the parent node, or NULL to get first
670+
*
671+
* This function is like of_get_next_child(), except that it
672+
* automatically skips any disabled nodes (i.e. status = "disabled").
673+
*/
674+
struct device_node *of_get_next_reserved_child(const struct device_node *node,
675+
struct device_node *prev)
676+
{
677+
return of_get_next_status_child(node, prev, __of_device_is_reserved);
678+
}
679+
EXPORT_SYMBOL(of_get_next_reserved_child);
680+
652681
/**
653682
* of_get_next_cpu_node - Iterate on cpu nodes
654683
* @prev: previous child of the /cpus node, or NULL to get first

include/linux/of.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
286286
struct device_node *prev);
287287
extern struct device_node *of_get_next_available_child(
288288
const struct device_node *node, struct device_node *prev);
289+
extern struct device_node *of_get_next_reserved_child(
290+
const struct device_node *node, struct device_node *prev);
289291

290292
extern struct device_node *of_get_compatible_child(const struct device_node *parent,
291293
const char *compatible);
@@ -533,6 +535,12 @@ static inline struct device_node *of_get_next_available_child(
533535
return NULL;
534536
}
535537

538+
static inline struct device_node *of_get_next_reserved_child(
539+
const struct device_node *node, struct device_node *prev)
540+
{
541+
return NULL;
542+
}
543+
536544
static inline struct device_node *of_find_node_with_property(
537545
struct device_node *from, const char *prop_name)
538546
{
@@ -1404,6 +1412,9 @@ static inline int of_property_read_s32(const struct device_node *np,
14041412
#define for_each_available_child_of_node(parent, child) \
14051413
for (child = of_get_next_available_child(parent, NULL); child != NULL; \
14061414
child = of_get_next_available_child(parent, child))
1415+
#define for_each_reserved_child_of_node(parent, child) \
1416+
for (child = of_get_next_reserved_child(parent, NULL); child != NULL; \
1417+
child = of_get_next_reserved_child(parent, child))
14071418

14081419
#define for_each_available_child_of_node_scoped(parent, child) \
14091420
for (struct device_node *child __free(device_node) = \

0 commit comments

Comments
 (0)