Skip to content

Commit b9952b5

Browse files
frowandrobherring
authored andcommitted
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: 0b3ce78 ("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>
1 parent a47c9b3 commit b9952b5

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎drivers/of/base.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static u32 phandle_cache_mask;
102102
* - the phandle lookup overhead reduction provided by the cache
103103
* will likely be less
104104
*/
105-
static void of_populate_phandle_cache(void)
105+
void of_populate_phandle_cache(void)
106106
{
107107
unsigned long flags;
108108
u32 cache_entries;
@@ -134,8 +134,7 @@ static void of_populate_phandle_cache(void)
134134
raw_spin_unlock_irqrestore(&devtree_lock, flags);
135135
}
136136

137-
#ifndef CONFIG_MODULES
138-
static int __init of_free_phandle_cache(void)
137+
int of_free_phandle_cache(void)
139138
{
140139
unsigned long flags;
141140

@@ -148,6 +147,7 @@ static int __init of_free_phandle_cache(void)
148147

149148
return 0;
150149
}
150+
#if !defined(CONFIG_MODULES)
151151
late_initcall_sync(of_free_phandle_cache);
152152
#endif
153153

‎drivers/of/of_private.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ int of_resolve_phandles(struct device_node *tree);
7979
#if defined(CONFIG_OF_OVERLAY)
8080
void of_overlay_mutex_lock(void);
8181
void of_overlay_mutex_unlock(void);
82+
int of_free_phandle_cache(void);
83+
void of_populate_phandle_cache(void);
8284
#else
8385
static inline void of_overlay_mutex_lock(void) {};
8486
static inline void of_overlay_mutex_unlock(void) {};

‎drivers/of/overlay.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree,
804804
goto err_free_overlay_changeset;
805805
}
806806

807+
of_populate_phandle_cache();
808+
807809
ret = __of_changeset_apply_notify(&ovcs->cset);
808810
if (ret)
809811
pr_err("overlay changeset entry notify error %d\n", ret);
@@ -1046,8 +1048,17 @@ int of_overlay_remove(int *ovcs_id)
10461048

10471049
list_del(&ovcs->ovcs_list);
10481050

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+
10491057
ret_apply = 0;
10501058
ret = __of_changeset_revert_entries(&ovcs->cset, &ret_apply);
1059+
1060+
of_populate_phandle_cache();
1061+
10511062
if (ret) {
10521063
if (ret_apply)
10531064
devicetree_state_flags |= DTSF_REVERT_FAIL;

0 commit comments

Comments
 (0)