config->name = ofnode_get_name(node);
- for (subnode = ofnode_first_subnode(node);
- ofnode_valid(subnode);
- subnode = ofnode_next_subnode(subnode)) {
+ ofnode_for_each_subnode(subnode, node) {
struct tegra_xusb_padctl_group *group;
int err;
return err;
}
- for (subnode = ofnode_first_subnode(node);
- ofnode_valid(subnode);
- subnode = ofnode_next_subnode(subnode)) {
+ ofnode_for_each_subnode(subnode, node) {
struct tegra_xusb_padctl_config *config = &padctl->config;
debug("%s: subnode=%s\n", __func__, ofnode_get_name(subnode));
if (!ofnode_valid(timings))
return -EINVAL;
- for (i = 0, node = ofnode_first_subnode(timings);
- ofnode_valid(node) && i != index;
- node = ofnode_first_subnode(node))
- i++;
+ i = 0;
+ ofnode_for_each_subnode(node, timings) {
+ if (i++ == index)
+ break;
+ }
if (!ofnode_valid(node))
return -EINVAL;
config->flash_erase_value = ofnode_read_s32_default(flash_node,
"erase-value", -1);
- for (node = ofnode_first_subnode(flash_node); ofnode_valid(node);
- node = ofnode_next_subnode(node)) {
+ ofnode_for_each_subnode(node, flash_node) {
const char *name = ofnode_get_name(node);
enum ec_flash_region region;
debug("%s for '%s' at node offset: %d\n", __func__, pmic->name,
dev_of_offset(pmic));
- for (node = ofnode_first_subnode(parent);
- ofnode_valid(node);
- node = ofnode_next_subnode(node)) {
+ ofnode_for_each_subnode(node, parent) {
node_name = ofnode_get_name(node);
debug("* Found child node: '%s'\n", node_name);
int ofnode_read_resource_byname(ofnode node, const char *name,
struct resource *res);
+/**
+ * ofnode_for_each_subnode() - iterate over all subnodes of a parent
+ *
+ * @node: child node (ofnode, lvalue)
+ * @parent: parent node (ofnode)
+ *
+ * This is a wrapper around a for loop and is used like so:
+ *
+ * ofnode node;
+ *
+ * ofnode_for_each_subnode(node, parent) {
+ * Use node
+ * ...
+ * }
+ *
+ * Note that this is implemented as a macro and @node is used as
+ * iterator in the loop. The parent variable can be a constant or even a
+ * literal.
+ */
+#define ofnode_for_each_subnode(node, parent) \
+ for (node = ofnode_first_subnode(parent); \
+ ofnode_valid(node); \
+ node = ofnode_next_subnode(node))
+
#endif