Skip to content

Commit 8a7d95f

Browse files
sudeep-hollagregkh
authored andcommitted
drivers/base: cacheinfo: validate device node for all the caches
On architectures that depend on DT for obtaining cache hierarcy, we need to validate the device node for all the cache indices, failing to do so might result in wrong information being exposed to the userspace. This is quite possible on initial/incomplete versions of the device trees. In such cases, it's better to bail out if all the required device nodes are not present. This patch adds checks for the validation of device node for all the caches and doesn't initialise the cacheinfo if there's any error. Reported-by: Mark Rutland <[email protected]> Acked-by: Mark Rutland <[email protected]> Signed-off-by: Sudeep Holla <[email protected]> Cc: stable <[email protected]> # 4.0 Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2071b95 commit 8a7d95f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/base/cacheinfo.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,21 @@ static int cache_setup_of_node(unsigned int cpu)
6262
return -ENOENT;
6363
}
6464

65-
while (np && index < cache_leaves(cpu)) {
65+
while (index < cache_leaves(cpu)) {
6666
this_leaf = this_cpu_ci->info_list + index;
6767
if (this_leaf->level != 1)
6868
np = of_find_next_cache_node(np);
6969
else
7070
np = of_node_get(np);/* cpu node itself */
71+
if (!np)
72+
break;
7173
this_leaf->of_node = np;
7274
index++;
7375
}
76+
77+
if (index != cache_leaves(cpu)) /* not all OF nodes populated */
78+
return -ENOENT;
79+
7480
return 0;
7581
}
7682

@@ -189,8 +195,11 @@ static int detect_cache_attributes(unsigned int cpu)
189195
* will be set up here only if they are not populated already
190196
*/
191197
ret = cache_shared_cpu_map_setup(cpu);
192-
if (ret)
198+
if (ret) {
199+
pr_warn("Unable to detect cache hierarcy from DT for CPU %d\n",
200+
cpu);
193201
goto free_ci;
202+
}
194203
return 0;
195204

196205
free_ci:

0 commit comments

Comments
 (0)