Skip to content

Commit 183f1d0

Browse files
Dong Aishenglinusw
authored andcommitted
dt: add of_get_child_count helper function
Currently most code to get child count in kernel are almost same, add a helper to implement this function for dt to use. Cc: Grant Likely <grant.likely@secretlab.ca> Acked-by: Rob Herring <rob.herring@calxeda.com> Acked-by: Stephen Warren <swarren@wwwdotorg.org> Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 4650b7c commit 183f1d0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/linux/of.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
193193
for (child = of_get_next_child(parent, NULL); child != NULL; \
194194
child = of_get_next_child(parent, child))
195195

196+
static inline int of_get_child_count(const struct device_node *np)
197+
{
198+
struct device_node *child;
199+
int num = 0;
200+
201+
for_each_child_of_node(np, child)
202+
num++;
203+
204+
return num;
205+
}
206+
196207
extern struct device_node *of_find_node_with_property(
197208
struct device_node *from, const char *prop_name);
198209
#define for_each_node_with_property(dn, prop_name) \
@@ -300,6 +311,11 @@ static inline bool of_have_populated_dt(void)
300311
#define for_each_child_of_node(parent, child) \
301312
while (0)
302313

314+
static inline int of_get_child_count(const struct device_node *np)
315+
{
316+
return 0;
317+
}
318+
303319
static inline int of_device_is_compatible(const struct device_node *device,
304320
const char *name)
305321
{

0 commit comments

Comments
 (0)