Skip to contentSkip to conversation

ACPI: APEI: EINJ: Fix check and iounmap of uninitialized pointer p

PATCH Applied Colin Ian King 4 participants 7 messages Jun 24, 2025 – Jun 26, 2025

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

PATCH 1/1 ACPI: APEI: EINJ: Fix check and iounmap of uninitialized pointer p

In the case where a request_mem_region call fails and pointer r is null the error exit path via label 'out' will check for a non-null pointer p and try to iounmap it. However, pointer p has not been assigned a value at this point, so it may potentially contain any garbage value. Fix this by ensuring pointer p is initialized to NULL.

Fixes 1a35c88302a3 ("ACPI: APEI: EINJ: Fix kernel test sparse warnings")
---
 drivers/acpi/apei/einj-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/einj-core.c +1 -1
index 7930acd1d3f3..fc801587df8e 100644
@@ -401,7 +401,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
 	u32 table_size;
 	int rc = -EIO;
 	struct acpi_generic_address *trigger_param_region = NULL;
-	struct acpi_einj_trigger __iomem *p;
+	struct acpi_einj_trigger __iomem *p = NULL;
 
 	r = request_mem_region(trigger_paddr, sizeof(trigger_tab),
 			       "APEI EINJ Trigger Table");
Signature · 1 line
2.50.0
#1 lore raw
Quoted 9 lines · Colin Ian King

In the case where a request_mem_region call fails and pointer r is null the error exit path via label 'out' will check for a non-null pointer p and try to iounmap it. However, pointer p has not been assigned a value at this point, so it may potentially contain any garbage value. Fix this by ensuring pointer p is initialized to NULL.

Fixes 1a35c88302a3 ("ACPI: APEI: EINJ: Fix kernel test sparse warnings")

---

Good catch. Apparently this isn't in my allyesconfig. It's weird the zero day bot didn't catch this either.

regards,
dan carpenter

#2 lore raw
Quoted 7 lines · Dan Carpenter
Quoted 6 lines · Colin Ian King

In the case where a request_mem_region call fails and pointer r is null the error exit path via label 'out' will check for a non-null pointer p and try to iounmap it. However, pointer p has not been assigned a value at this point, so it may potentially contain any garbage value. Fix this by ensuring pointer p is initialized to NULL.

Quoted 6 lines
Quoted 3 lines
Fixes 1a35c88302a3 ("ACPI: APEI: EINJ: Fix kernel test sparse warnings")

---

Good catch. Apparently this isn't in my allyesconfig. It's weird the zero day bot didn't catch this either.

Never mind. This is definitely in my allyesconfig.

regards,
dan carpenter

#3 lore raw
In reply to Colin Ian King
Quoted 17 lines · Colin Ian King

In the case where a request_mem_region call fails and pointer r is null the error exit path via label 'out' will check for a non-null pointer p and try to iounmap it. However, pointer p has not been assigned a value at this point, so it may potentially contain any garbage value. Fix this by ensuring pointer p is initialized to NULL.

Fixes 1a35c88302a3 ("ACPI: APEI: EINJ: Fix kernel test sparse warnings")
---
 drivers/acpi/apei/einj-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/einj-core.c +0 -0
index 7930acd1d3f3..fc801587df8e 100644

drivers/acpi/apei/einj-core.c static int __einj_error_trigger(u64 trigger_paddr, u32 type, · line 404

Quoted 5 lines
drivers/acpi/apei/einj-core.c +1 -1
@@ -401,7 +401,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
 	u32 table_size;
 	int rc = -EIO;
 	struct acpi_generic_address *trigger_param_region = NULL;
-	struct acpi_einj_trigger __iomem *p;
+	struct acpi_einj_trigger __iomem *p = NULL;

Apparently my review of these was pretty weak... :-/

That said; Why not skip a goto as well?

Ira

drivers/acpi/apei/einj-core.c +1 -2
index d6d7e36e3647..fae01795e7f6 100644
@@ -410,7 +410,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
                       (unsigned long long)trigger_paddr,
                       (unsigned long long)trigger_paddr +
                            sizeof(trigger_tab) - 1);
-               goto out;
+               return -EIO;
        }
        p = ioremap_cache(trigger_paddr, sizeof(*p));
        if (!p) {
@@ -502,7 +502,6 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
                           table_size - sizeof(trigger_tab));
 out_rel_header:
        release_mem_region(trigger_paddr, sizeof(trigger_tab));
-out:
        if (p)
                iounmap(p);
 
#4 lore raw
Quoted 26 lines · Ira Weiny
Quoted 17 lines · Colin Ian King

In the case where a request_mem_region call fails and pointer r is null the error exit path via label 'out' will check for a non-null pointer p and try to iounmap it. However, pointer p has not been assigned a value at this point, so it may potentially contain any garbage value. Fix this by ensuring pointer p is initialized to NULL.

Fixes 1a35c88302a3 ("ACPI: APEI: EINJ: Fix kernel test sparse warnings")
---
  drivers/acpi/apei/einj-core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/einj-core.c +0 -0
index 7930acd1d3f3..fc801587df8e 100644

drivers/acpi/apei/einj-core.c static int __einj_error_trigger(u64 trigger_paddr, u32 type, · line 404

Quoted 5 lines
drivers/acpi/apei/einj-core.c +1 -1
@@ -401,7 +401,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
  	u32 table_size;
  	int rc = -EIO;
  	struct acpi_generic_address *trigger_param_region = NULL;
-	struct acpi_einj_trigger __iomem *p;
+	struct acpi_einj_trigger __iomem *p = NULL;

Apparently my review of these was pretty weak... :-/

Quoted 1 line

That said; Why not skip a goto as well?

Because the goto uses a shared return path and hence reduces the amount of return epilogue used in the generated code.

Colin

Quoted 24 lines

Ira

drivers/acpi/apei/einj-core.c +1 -2
index d6d7e36e3647..fae01795e7f6 100644
@@ -410,7 +410,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
                        (unsigned long long)trigger_paddr,
                        (unsigned long long)trigger_paddr +
                             sizeof(trigger_tab) - 1);
-               goto out;
+               return -EIO;
         }
         p = ioremap_cache(trigger_paddr, sizeof(*p));
         if (!p) {
@@ -502,7 +502,6 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
                            table_size - sizeof(trigger_tab));
  out_rel_header:
         release_mem_region(trigger_paddr, sizeof(trigger_tab));
-out:
         if (p)
                 iounmap(p);
 
#5 lore raw
Quoted 27 lines · Colin King (gmail)
Quoted 26 lines · Ira Weiny
Quoted 17 lines · Colin Ian King

In the case where a request_mem_region call fails and pointer r is null the error exit path via label 'out' will check for a non-null pointer p and try to iounmap it. However, pointer p has not been assigned a value at this point, so it may potentially contain any garbage value. Fix this by ensuring pointer p is initialized to NULL.

Fixes 1a35c88302a3 ("ACPI: APEI: EINJ: Fix kernel test sparse warnings")
---
  drivers/acpi/apei/einj-core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/einj-core.c +0 -0
index 7930acd1d3f3..fc801587df8e 100644

drivers/acpi/apei/einj-core.c static int __einj_error_trigger(u64 trigger_paddr, u32 type, · line 404

Quoted 5 lines
drivers/acpi/apei/einj-core.c +1 -1
@@ -401,7 +401,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
  	u32 table_size;
  	int rc = -EIO;
  	struct acpi_generic_address *trigger_param_region = NULL;
-	struct acpi_einj_trigger __iomem *p;
+	struct acpi_einj_trigger __iomem *p = NULL;

Apparently my review of these was pretty weak... :-/

Quoted 4 lines
Quoted 1 line

That said; Why not skip a goto as well?

Because the goto uses a shared return path and hence reduces the amount of return epilogue used in the generated code.

Is that really important in a debugfs triggered code path?

I'm not seeing the benefit vs reducing the complexity of the code.

Frankly we probably aught to be using the new cleanup features in this function but I refrained from requesting such a big change.

Ira

Quoted 28 lines

Colin

Quoted 24 lines

Ira

drivers/acpi/apei/einj-core.c +1 -2
index d6d7e36e3647..fae01795e7f6 100644
@@ -410,7 +410,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
                        (unsigned long long)trigger_paddr,
                        (unsigned long long)trigger_paddr +
                             sizeof(trigger_tab) - 1);
-               goto out;
+               return -EIO;
         }
         p = ioremap_cache(trigger_paddr, sizeof(*p));
         if (!p) {
@@ -502,7 +502,6 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
                            table_size - sizeof(trigger_tab));
  out_rel_header:
         release_mem_region(trigger_paddr, sizeof(trigger_tab));
-out:
         if (p)
                 iounmap(p);
 
maintainer Applied
#6 lore raw
In reply to Colin King (gmail)
Quoted 28 lines · Colin King (gmail)
Quoted 26 lines · Ira Weiny
Quoted 17 lines · Colin Ian King

In the case where a request_mem_region call fails and pointer r is null the error exit path via label 'out' will check for a non-null pointer p and try to iounmap it. However, pointer p has not been assigned a value at this point, so it may potentially contain any garbage value. Fix this by ensuring pointer p is initialized to NULL.

Fixes 1a35c88302a3 ("ACPI: APEI: EINJ: Fix kernel test sparse warnings")
---
  drivers/acpi/apei/einj-core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/einj-core.c +0 -0
index 7930acd1d3f3..fc801587df8e 100644

drivers/acpi/apei/einj-core.c static int __einj_error_trigger(u64 trigger_paddr, u32 type, · line 404

Quoted 5 lines
drivers/acpi/apei/einj-core.c +1 -1
@@ -401,7 +401,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
     u32 table_size;
     int rc = -EIO;
     struct acpi_generic_address *trigger_param_region = NULL;
-    struct acpi_einj_trigger __iomem *p;
+    struct acpi_einj_trigger __iomem *p = NULL;

Apparently my review of these was pretty weak... :-/

Quoted 4 lines
Quoted 1 line

That said; Why not skip a goto as well?

Because the goto uses a shared return path and hence reduces the amount of return epilogue used in the generated code.

Applied, thanks!

Quoted 22 lines
Quoted 21 lines
drivers/acpi/apei/einj-core.c +1 -2
index d6d7e36e3647..fae01795e7f6 100644
@@ -410,7 +410,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
                        (unsigned long long)trigger_paddr,
                        (unsigned long long)trigger_paddr +
                             sizeof(trigger_tab) - 1);
-               goto out;
+               return -EIO;
         }
         p = ioremap_cache(trigger_paddr, sizeof(*p));
         if (!p) {
@@ -502,7 +502,6 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
                            table_size - sizeof(trigger_tab));
  out_rel_header:
         release_mem_region(trigger_paddr, sizeof(trigger_tab));
-out:
         if (p)
                 iounmap(p);