Skip to contentSkip to conversation

ACPI: MRRM: Silence error code static checker warning

PATCH Applied Dan Carpenter 2 participants 2 messages May 27, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: MRRM: Silence error code static checker warning

The error code is not set correctly on if kasprintf() fails. On the first iteration it would return -EINVAL and subsequent iterations would return success. Set it to -ENOMEM.

In real life, this allocation will not fail and if it did the system will not boot so this change is mostly to silence static checker warnings more than anything else.

Fixes 04f53540f791 ("ACPI: MRRM: Add /sys files to describe memory ranges")
---
 drivers/acpi/acpi_mrrm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/acpi_mrrm.c +3 -1
index 2f22f013959a..70088cdfde13 100644
@@ -156,8 +156,10 @@ static __init int add_boot_memory_ranges(void)
 
 	for (int i = 0; i < mrrm_mem_entry_num; i++) {
 		name = kasprintf(GFP_KERNEL, "range%d", i);
-		if (!name)
+		if (!name) {
+			ret = -ENOMEM;
 			break;
+		}
 
 		kobj = kobject_create_and_add(name, pkobj);
 
Signature · 1 line
2.47.2
maintainer Applied
#1 lore raw
Quoted 22 lines · Dan Carpenter

The error code is not set correctly on if kasprintf() fails. On the first iteration it would return -EINVAL and subsequent iterations would return success. Set it to -ENOMEM.

In real life, this allocation will not fail and if it did the system will not boot so this change is mostly to silence static checker warnings more than anything else.

Fixes 04f53540f791 ("ACPI: MRRM: Add /sys files to describe memory ranges")
---
 drivers/acpi/acpi_mrrm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/acpi_mrrm.c +0 -0
index 2f22f013959a..70088cdfde13 100644
@@ -156,8 +156,10 @@ static __init int add_boot_memory_ranges(void)
 
        for (int i = 0; i < mrrm_mem_entry_num; i++) {

drivers/acpi/acpi_mrrm.c static __init int add_boot_memory_ranges(void)

Quoted 10 lines
drivers/acpi/acpi_mrrm.c +3 -2
                name = kasprintf(GFP_KERNEL, "range%d", i);
-               if (!name)
+               if (!name) {
+                       ret = -ENOMEM;
                        break;
+               }
 
                kobj = kobject_create_and_add(name, pkobj);
 
--

Applied, thanks!