add a function to browse at reverse order the tree

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
diff --git a/tree.c b/tree.c
index 0a9c119..516e832 100644
--- a/tree.c
+++ b/tree.c
@@ -224,6 +224,20 @@
 	return tree_for_each(tree->next, cb, data);
 }
 
+int tree_for_each_reverse(struct tree *tree, tree_cb_t cb, void *data)
+{
+	if (!tree)
+		return 0;
+
+	if (cb(tree, data))
+		return -1;
+
+	if (tree_for_each_reverse(tree->prev, cb, data))
+		return -1;
+
+	return tree_for_each_reverse(tree->parent, cb, data);
+}
+
 int tree_for_each_parent(struct tree *tree, tree_cb_t cb, void *data)
 {
 	if (!tree)
diff --git a/tree.h b/tree.h
index 176dd23..2af4a5a 100644
--- a/tree.h
+++ b/tree.h
@@ -46,4 +46,6 @@
 
 extern int tree_for_each(struct tree *tree, tree_cb_t cb, void *data);
 
+extern int tree_for_each_reverse(struct tree *tree, tree_cb_t cb, void *data);
+
 extern int tree_for_each_parent(struct tree *tree, tree_cb_t cb, void *data);