Commit b16e2f69 authored by Sudeep Holla's avatar Sudeep Holla Committed by Greg Kroah-Hartman

drivers/base: cacheinfo: validate device node for all the caches

commit 8a7d95f9 upstream.

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: default avatarMark Rutland <mark.rutland@arm.com>
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7595f542
...@@ -62,15 +62,21 @@ static int cache_setup_of_node(unsigned int cpu) ...@@ -62,15 +62,21 @@ static int cache_setup_of_node(unsigned int cpu)
return -ENOENT; return -ENOENT;
} }
while (np && index < cache_leaves(cpu)) { while (index < cache_leaves(cpu)) {
this_leaf = this_cpu_ci->info_list + index; this_leaf = this_cpu_ci->info_list + index;
if (this_leaf->level != 1) if (this_leaf->level != 1)
np = of_find_next_cache_node(np); np = of_find_next_cache_node(np);
else else
np = of_node_get(np);/* cpu node itself */ np = of_node_get(np);/* cpu node itself */
if (!np)
break;
this_leaf->of_node = np; this_leaf->of_node = np;
index++; index++;
} }
if (index != cache_leaves(cpu)) /* not all OF nodes populated */
return -ENOENT;
return 0; return 0;
} }
...@@ -189,8 +195,11 @@ static int detect_cache_attributes(unsigned int cpu) ...@@ -189,8 +195,11 @@ static int detect_cache_attributes(unsigned int cpu)
* will be set up here only if they are not populated already * will be set up here only if they are not populated already
*/ */
ret = cache_shared_cpu_map_setup(cpu); ret = cache_shared_cpu_map_setup(cpu);
if (ret) if (ret) {
pr_warn("Unable to detect cache hierarcy from DT for CPU %d\n",
cpu);
goto free_ci; goto free_ci;
}
return 0; return 0;
free_ci: free_ci:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment