Skip to content

Commit 28c5d4e

Browse files
morimotogeertu
authored andcommitted
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 <[email protected]> Tested-by: Yusuke Goda <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 8918283 commit 28c5d4e

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
@@ -465,6 +465,20 @@ static bool __of_device_is_available(const struct device_node *device)
465465
__of_device_is_status(device, ok);
466466
}
467467

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

667+
/**
668+
* of_get_next_reserved_child - Find the next reserved child node
669+
* @node: parent node
670+
* @prev: previous child of the parent node, or NULL to get first
671+
*
672+
* This function is like of_get_next_child(), except that it
673+
* automatically skips any disabled nodes (i.e. status = "disabled").
674+
*/
675+
struct device_node *of_get_next_reserved_child(const struct device_node *node,
676+
struct device_node *prev)
677+
{
678+
return of_get_next_status_child(node, prev, __of_device_is_reserved);
679+
}
680+
EXPORT_SYMBOL(of_get_next_reserved_child);
681+
653682
/**
654683
* of_get_next_cpu_node - Iterate on cpu nodes
655684
* @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
@@ -294,6 +294,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
294294
struct device_node *prev);
295295
extern struct device_node *of_get_next_available_child(
296296
const struct device_node *node, struct device_node *prev);
297+
extern struct device_node *of_get_next_reserved_child(
298+
const struct device_node *node, struct device_node *prev);
297299

298300
extern struct device_node *of_get_compatible_child(const struct device_node *parent,
299301
const char *compatible);
@@ -541,6 +543,12 @@ static inline struct device_node *of_get_next_available_child(
541543
return NULL;
542544
}
543545

546+
static inline struct device_node *of_get_next_reserved_child(
547+
const struct device_node *node, struct device_node *prev)
548+
{
549+
return NULL;
550+
}
551+
544552
static inline struct device_node *of_find_node_with_property(
545553
struct device_node *from, const char *prop_name)
546554
{
@@ -1431,6 +1439,9 @@ static inline int of_property_read_s32(const struct device_node *np,
14311439
#define for_each_available_child_of_node(parent, child) \
14321440
for (child = of_get_next_available_child(parent, NULL); child != NULL; \
14331441
child = of_get_next_available_child(parent, child))
1442+
#define for_each_reserved_child_of_node(parent, child) \
1443+
for (child = of_get_next_reserved_child(parent, NULL); child != NULL; \
1444+
child = of_get_next_reserved_child(parent, child))
14341445

14351446
#define for_each_of_cpu_node(cpu) \
14361447
for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \

0 commit comments

Comments
 (0)