Skip to contentSkip to conversation

arm64: cacheinfo: Simplify init_cache_level()

PATCH In review Thorsten Blum 2 participants 4 messages Nov 4 arm64

lore
Share & tools
lore
#0 lore raw

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
index 309942b06c5b..881131fb4934 100644
@@ -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) {
 		/*
#1 lore raw

Hi Thorsten,

Quoted 2 lines · Thorsten Blum

acpi_get_cache_info() already sets fw_level to 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_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
index 309942b06c5b..881131fb4934 100644
@@ -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) {
 		/*
#2 lore raw

Hi Ben,

Quoted 8 lines · Ben Horgan

Hi Thorsten,

Quoted 2 lines · Thorsten Blum

acpi_get_cache_info() already sets fw_level to 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

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.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.

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

#3 lore raw

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 sets fw_level to 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

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.

Ok, that's true.

Quoted 8 lines
Quoted 3 lines

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.

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