History

device property: Add functions for accessing node's parents

Add two convenience functions for accessing node's parents: fwnode_count_parents() returns the number of parent nodes a given node has. fwnode_get_nth_parent() returns node's parent at a given distance from the node itself.

Sakari Ailus committed 7 years ago

Commit 87e5e951 parent a57b7fb2 files · +49 −0Browse files

Unified · Split

2 files
  1. drivers/base/property.c +46 −0
  2. include/linux/property.h +3 −0
drivers/base/property.c+46−0
@@ -590,6 +590,52 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode) · 589 unmodified lines
590}590}
591EXPORT_SYMBOL_GPL(fwnode_get_next_parent);591EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
592 592
593/**
594 * fwnode_count_parents - Return the number of parents a node has
595 * @fwnode: The node the parents of which are to be counted
596 *
597 * Returns the number of parents a node has.
598 */
599unsigned int fwnode_count_parents(const struct fwnode_handle *fwnode)
600{
601 struct fwnode_handle *__fwnode;
602 unsigned int count;
603
604 __fwnode = fwnode_get_parent(fwnode);
605
606 for (count = 0; __fwnode; count++)
607 __fwnode = fwnode_get_next_parent(__fwnode);
608
609 return count;
610}
611EXPORT_SYMBOL_GPL(fwnode_count_parents);
612
613/**
614 * fwnode_get_nth_parent - Return an nth parent of a node
615 * @fwnode: The node the parent of which is requested
616 * @depth: Distance of the parent from the node
617 *
618 * Returns the nth parent of a node. If there is no parent at the requested
619 * @depth, %NULL is returned. If @depth is 0, the functionality is equivalent to
620 * fwnode_handle_get(). For @depth == 1, it is fwnode_get_parent() and so on.
621 *
622 * The caller is responsible for calling fwnode_handle_put() for the returned
623 * node.
624 */
625struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode,
626 unsigned int depth)
627{
628 unsigned int i;
629
630 fwnode_handle_get(fwnode);
631
632 for (i = 0; i < depth && fwnode; i++)
633 fwnode = fwnode_get_next_parent(fwnode);
634
635 return fwnode;
636}
637EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
638
593/**639/**
594 * fwnode_get_next_child_node - Return the next child node handle for a node640 * fwnode_get_next_child_node - Return the next child node handle for a node
595 * @fwnode: Firmware node to find the next child node for.641 * @fwnode: Firmware node to find the next child node for.
include/linux/property.h+3−0
@@ -83,6 +83,9 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, · 82 unmodified lines
83struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);83struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
84struct fwnode_handle *fwnode_get_next_parent(84struct fwnode_handle *fwnode_get_next_parent(
85 struct fwnode_handle *fwnode);85 struct fwnode_handle *fwnode);
86unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
87struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
88 unsigned int depth);
86struct fwnode_handle *fwnode_get_next_child_node(89struct fwnode_handle *fwnode_get_next_child_node(
87 const struct fwnode_handle *fwnode, struct fwnode_handle *child);90 const struct fwnode_handle *fwnode, struct fwnode_handle *child);
88struct fwnode_handle *fwnode_get_next_available_child_node(91struct fwnode_handle *fwnode_get_next_available_child_node(

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t