Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

OF: Check if all target phandles in fragment are valid

Before we perform the overlay, we check if the target phandle
references are valid. This is just a sanity check to make sure
that all the nodes being referred to by the target property indeed
exist in the live tree, before performing the overlay.

Signed-off-by: Joel A Fernandes <joelagnel@ti.com>
  • Loading branch information...
commit a9eb5d9545daeb68294578f2d32c28226c8c13c7 1 parent 98229d1
Joel A Fernandes authored
Showing with 40 additions and 0 deletions.
  1. +39 −0 drivers/of/overlay.c
  2. +1 −0  include/linux/of.h
View
39 drivers/of/overlay.c
@@ -833,4 +833,43 @@ int of_free_overlay_info(int count, struct of_overlay_info *ovinfo_tab)
}
EXPORT_SYMBOL(of_free_overlay_info);
+int of_check_fragment_phandles(struct device_node *resolve)
+{
+ struct device_node *child, *grandchild, *refnode;
+ int is_fragment, err = 0;
+ phandle phandle;
+
+ for_each_child_of_node(resolve, child) {
+ /* check if fragment */
+ is_fragment = 0;
+ for_each_child_of_node(child, grandchild)
+ if(strcmp(grandchild->name, "__overlay__") == 0)
+ is_fragment = 1;
+ if(is_fragment == 0)
+ continue;
+ pr_debug("%s: Fragment found: %s\n", __func__, child->full_name);
+
+ err = of_property_read_u32(child, "target", &phandle);
+ if(err != 0) {
+ pr_err("%s: Could not read target property in'%s'\n",
+ __func__, child->full_name);
+ goto err_fail;
+ }
+ pr_debug("%s: Checking target phandle: %x\n", __func__, phandle);
+
+ refnode = of_find_node_by_phandle(phandle);
+ if(refnode == NULL) {
+ pr_err("%s: Could not find node with phandle '%x'\n",
+ __func__, phandle);
+ err = -ENOENT;
+ goto err_fail;
+ }
+ pr_debug("%s: phandle checked, Node found: %s\n"
+ __func, refnode->full_name);
+ of_node_put(refnode);
+ }
+err_fail:
+ return err;
+}
+EXPORT_SYMBOL(of_check_fragment_phandles);
View
1  include/linux/of.h
@@ -742,6 +742,7 @@ int of_fill_overlay_info(struct device_node *info_node,
int of_build_overlay_info(struct device_node *tree,
int *cntp, struct of_overlay_info **ovinfop);
int of_free_overlay_info(int cnt, struct of_overlay_info *ovinfo);
+int of_check_fragment_phandles(struct device_node *resolve);
#else
Please sign in to comment.
Something went wrong with that request. Please try again.