arm64: cacheinfo: Simplify init_cache_level()
PATCH 1/1 arm64: cacheinfo: Simplify init_cache_level()
acpi_get_cache_info() already sets fw_level to 0 on failure, so drop the redundant check and the manual assignment.
Use unsigned int for fw_level to match the expected type, and remove the now-unused local ret variable.
--- arch/arm64/kernel/cacheinfo.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
arch/arm64/kernel/cacheinfo.c +4 -8
@@ -67,19 +67,15 @@ int early_cache_level(unsigned int cpu)int init_cache_level (unsigned int cpu) { -unsigned int level, leaves; -int fw_level, ret; +unsigned int level, leaves, fw_level;struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu);detect_cache_level (&level, &leaves); -if (acpi_disabled) { +if (acpi_disabled) fw_level =of_find_last_cache_level (cpu); - }else { - ret =acpi_get_cache_info (cpu, &fw_level,NULL ); -if (ret <0 ) - fw_level =0 ; - } +else +acpi_get_cache_info (cpu, &fw_level,NULL );if (level < fw_level) {/*
Hi Thorsten,
Quoted 2 lines · Thorsten Blum
acpi_get_cache_info()already setsfw_levelto 0 on failure, so drop the redundant check and the manual assignment.
This doesn't seem to be the case when CONFIG_ACPI_PPTT is not defined. Can the dummy implementation in include/linux/cacheinfo.h be called from init_cache_level()? For the implementation in drivers/acpi/pptt.c levels is documented as "Number of levels if success." and so would be good to mention what happens in the error case if it needs to be relied on.
Thanks,
Ben
Quoted 38 lines
Use unsigned int for
fw_levelto match the expected type, and remove the now-unused local ret variable.Signed-off-by Thorsten Blum <[email protected]>--- arch/arm64/kernel/cacheinfo.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)arch/arm64/kernel/cacheinfo.c +4
-8@@ -67,19 +67,15 @@ int early_cache_level(unsigned int cpu)int init_cache_level (unsigned int cpu) { -unsigned int level, leaves; -int fw_level, ret; +unsigned int level, leaves, fw_level;struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu);detect_cache_level (&level, &leaves); -if (acpi_disabled) { +if (acpi_disabled) fw_level =of_find_last_cache_level (cpu); - }else { - ret =acpi_get_cache_info (cpu, &fw_level,NULL ); -if (ret <0 ) - fw_level =0 ; - } +else +acpi_get_cache_info (cpu, &fw_level,NULL );if (level < fw_level) {/*
Hi Ben,
Quoted 8 lines · Ben Horgan
Hi Thorsten,
Quoted 2 lines · Thorsten Blum
acpi_get_cache_info()already setsfw_levelto 0 on failure, so drop the redundant check and the manual assignment.This doesn't seem to be the case when
CONFIG_ACPI_PPTTis not defined. Can the dummy implementation ininclude/linux/cacheinfo.hbe called frominit_cache_level()? For the implementation in
On arm64, ACPI_PPTT is selected when ACPI is enabled. When ACPI is disabled, acpi_disabled = 1 and init_cache_level() won't call the stub.
Quoted 2 lines
drivers/acpi/pptt.clevels is documented as "Number of levels if success." and so would be good to mention what happens in the error case if it needs to be relied on.
Below the parameter descriptions, it already says:
"Errors caused by lack of a PPTT table, or otherwise, return 0
indicating we didn't find any cache levels."
Thanks,
Thorsten
Hi Thorsten,
Quoted 6 lines · Thorsten Blum
Hi Ben,
Quoted 3 lines · Ben Horgan
Hi Thorsten,
On 04/11/2026 08:36, Thorsten Blum wrote:
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
acpi_get_cache_info()already setsfw_levelto 0 on failure, so drop the redundant check and the manual assignment.This doesn't seem to be the case when
CONFIG_ACPI_PPTTis not defined. Can the dummy implementation ininclude/linux/cacheinfo.hbe called frominit_cache_level()? For the implementation inOn arm64,
ACPI_PPTTis selected when ACPI is enabled. When ACPI is disabled,acpi_disabled= 1 andinit_cache_level()won't call the stub.
Ok, that's true.
Quoted 8 lines
Quoted 3 lines
drivers/acpi/pptt.clevels is documented as "Number of levels if success." and so would be good to mention what happens in the error case if it needs to be relied on.Below the parameter descriptions, it already says:
"Errors caused by lack of a PPTT table, or otherwise, return 0
indicating we didn't find any cache levels."
Ah yes, I should have read on.
Thanks,
Ben
Quoted 3 lines
Thanks,
Thorsten
Catalin Marinas
maintainerQuoted 26 lines · Thorsten Blum
acpi_get_cache_info()already setsfw_levelto 0 on failure, so drop the redundant check and the manual assignment.Use unsigned int for
fw_levelto match the expected type, and remove the now-unused local ret variable.Signed-off-by Thorsten Blum <[email protected]>--- arch/arm64/kernel/cacheinfo.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)arch/arm64/kernel/cacheinfo.c +1
-2@@ -67,19 +67,15 @@ int early_cache_level(unsigned int cpu)int init_cache_level (unsigned int cpu) { -unsigned int level, leaves; -int fw_level, ret; +unsigned int level, leaves, fw_level;struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu);detect_cache_level (&level, &leaves);
arch/arm64/kernel/cacheinfo.c int early_cache_level(unsigned int cpu) · line 78
Quoted 10 lines
arch/arm64/kernel/cacheinfo.c +3
-6-if (acpi_disabled) { +if (acpi_disabled) fw_level =of_find_last_cache_level (cpu); - }else { - ret =acpi_get_cache_info (cpu, &fw_level,NULL ); -if (ret <0 ) - fw_level =0 ; - } +else +acpi_get_cache_info (cpu, &fw_level,NULL );
I wouldn't assume the caller always sets *levels to 0. It may do this now but the kernel-doc is not entirely clear. It claims that it sets it only on success with some muddled text about returning 0 on failure, which I guess may have been intended as setting *levels to 0.
This also relies on ACPI_PPTT being selected which is true for arm64 but we can't simplify the checks here just because of Kconfig options. It doesn't cost us anything to check the return value, the patch doesn't make the code easier to read. So, NAK.
Signature · 1 line
Catalin