Skip to contentSkip to conversation

mach-snapdragon: dram: fix SMEM error pointer check

PATCH In review Vandhiadevan Karunamoorthy 2 participants 2 messages Oct 20 – Oct 22

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

PATCH 1/1 mach-snapdragon: dram: fix SMEM error pointer check

qcom_smem_get() reports failure with an ERR_PTR(), for example -ENOENT when the item is missing or -EPROBE_DEFER when SMEM is not ready, and never returns NULL. The check in qcom_parse_memory_smem() only tests for NULL, so an error pointer is treated as a valid RAM partition table and header->version is then dereferenced.

Use IS_ERR_OR_NULL() and return the error from qcom_smem_get() so that qcom_parse_memory() reports a missing memory map through its existing error path instead of faulting on a bogus pointer.

Fixes ed40a06be832 ("mach-snapdragon: support parsing memory map from SMEM")
---
 arch/arm/mach-snapdragon/dram.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/mach-snapdragon/dram.c +3 -2
index 0b97b698322..04b6d167848 100644
@@ -8,6 +8,7 @@
 
 #include <asm-generic/unaligned.h>
 #include <dm.h>
+#include <linux/err.h>
 #include <log.h>
 #include <sort.h>
 #include <soc/qcom/smem.h>
@@ -92,9 +93,9 @@ static int qcom_parse_memory_smem(phys_addr_t *ram_end)
 	}
 
 	header = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_USABLE_RAM_PARTITION_TABLE, &size);
-	if (!header) {
+	if (IS_ERR_OR_NULL(header)) {
 		debug("Failed to find SMEM partition.\n");
-		return -ENODEV;
+		return header ? PTR_ERR(header) : -ENODEV;
 	}
 
 	ver = header->version;

---
base-commit: e36b675ebc4c41f1f4187c46d363d581c371d538
change-id: 20261020-dram-smem-errptr-e070f4d5e8fe

Best regards,

Signature · 1 line
Vandhiadevan Karunamoorthy <[email protected]>