aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Rowand <frank.rowand@sony.com>2018-07-12 17:00:07 -0400
committerRob Herring <robh@kernel.org>2018-07-16 10:41:32 -0400
commitb9952b5218added5577e4a3443969bc20884cea9 (patch)
treeea6672754a6ec83753a9a3b63bbb3dd0c68ec708
parenta47c9b3943164453d4f580ea174a6ddcb37554c3 (diff)
of: overlay: update phandle cache on overlay apply and remove
A comment in the review of the patch adding the phandle cache said that the cache would have to be updated when modules are applied and removed. This patch implements the cache updates. Fixes: 0b3ce78e90fc ("of: cache phandle nodes to reduce cost of of_find_node_by_phandle()") Reported-by: Alan Tull <atull@kernel.org> Suggested-by: Alan Tull <atull@kernel.org> Signed-off-by: Frank Rowand <frank.rowand@sony.com> Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r--drivers/of/base.c6
-rw-r--r--drivers/of/of_private.h2
-rw-r--r--drivers/of/overlay.c11
3 files changed, 16 insertions, 3 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 848f549164cd..466e3c8582f0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -102,7 +102,7 @@ static u32 phandle_cache_mask;
102 * - the phandle lookup overhead reduction provided by the cache 102 * - the phandle lookup overhead reduction provided by the cache
103 * will likely be less 103 * will likely be less
104 */ 104 */
105static void of_populate_phandle_cache(void) 105void of_populate_phandle_cache(void)
106{ 106{
107 unsigned long flags; 107 unsigned long flags;
108 u32 cache_entries; 108 u32 cache_entries;
@@ -134,8 +134,7 @@ out:
134 raw_spin_unlock_irqrestore(&devtree_lock, flags); 134 raw_spin_unlock_irqrestore(&devtree_lock, flags);
135} 135}
136 136
137#ifndef CONFIG_MODULES 137int of_free_phandle_cache(void)
138static int __init of_free_phandle_cache(void)
139{ 138{
140 unsigned long flags; 139 unsigned long flags;
141 140
@@ -148,6 +147,7 @@ static int __init of_free_phandle_cache(void)
148 147
149 return 0; 148 return 0;
150} 149}
150#if !defined(CONFIG_MODULES)
151late_initcall_sync(of_free_phandle_cache); 151late_initcall_sync(of_free_phandle_cache);
152#endif 152#endif
153 153
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index 891d780c076a..216175d11d3d 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -79,6 +79,8 @@ int of_resolve_phandles(struct device_node *tree);
79#if defined(CONFIG_OF_OVERLAY) 79#if defined(CONFIG_OF_OVERLAY)
80void of_overlay_mutex_lock(void); 80void of_overlay_mutex_lock(void);
81void of_overlay_mutex_unlock(void); 81void of_overlay_mutex_unlock(void);
82int of_free_phandle_cache(void);
83void of_populate_phandle_cache(void);
82#else 84#else
83static inline void of_overlay_mutex_lock(void) {}; 85static inline void of_overlay_mutex_lock(void) {};
84static inline void of_overlay_mutex_unlock(void) {}; 86static inline void of_overlay_mutex_unlock(void) {};
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 7baa53e5b1d7..eda57ef12fd0 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -804,6 +804,8 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree,
804 goto err_free_overlay_changeset; 804 goto err_free_overlay_changeset;
805 } 805 }
806 806
807 of_populate_phandle_cache();
808
807 ret = __of_changeset_apply_notify(&ovcs->cset); 809 ret = __of_changeset_apply_notify(&ovcs->cset);
808 if (ret) 810 if (ret)
809 pr_err("overlay changeset entry notify error %d\n", ret); 811 pr_err("overlay changeset entry notify error %d\n", ret);
@@ -1046,8 +1048,17 @@ int of_overlay_remove(int *ovcs_id)
1046 1048
1047 list_del(&ovcs->ovcs_list); 1049 list_del(&ovcs->ovcs_list);
1048 1050
1051 /*
1052 * Disable phandle cache. Avoids race condition that would arise
1053 * from removing cache entry when the associated node is deleted.
1054 */
1055 of_free_phandle_cache();
1056
1049 ret_apply = 0; 1057 ret_apply = 0;
1050 ret = __of_changeset_revert_entries(&ovcs->cset, &ret_apply); 1058 ret = __of_changeset_revert_entries(&ovcs->cset, &ret_apply);
1059
1060 of_populate_phandle_cache();
1061
1051 if (ret) { 1062 if (ret) {
1052 if (ret_apply) 1063 if (ret_apply)
1053 devicetree_state_flags |= DTSF_REVERT_FAIL; 1064 devicetree_state_flags |= DTSF_REVERT_FAIL;