From 41124035a86106c58c6a50bd0dbe6501af6eb0b4 Mon Sep 17 00:00:00 2001 From: Jeremy Compostella Date: Fri, 17 Jan 2025 13:11:03 -0800 Subject: [PATCH] tree: Handle NULL pointer returned by smm_get_save_state() Since commit 64d9e8568172402d8078c2c80ba994da16f4745b ("cpu/x86/smm_module_hander: Set up a save state map"), the smm_get_save_state() function can return a NULL pointer. Therefore, it is crucial to ensure that code properly handles the potential for a NULL pointer return value from smm_get_save_state(). Change-Id: Ie263393ca7d9d6b5e9868c5f73240fc788116cd0 Signed-off-by: Jeremy Compostella Reviewed-on: https://review.coreboot.org/c/coreboot/+/86040 Tested-by: build bot (Jenkins) Reviewed-by: Elyes Haouas --- src/soc/amd/common/block/cpu/smm/smi_apmc.c | 2 ++ src/soc/intel/braswell/smihandler.c | 2 ++ src/soc/intel/broadwell/pch/smihandler.c | 2 ++ src/soc/intel/denverton_ns/smihandler.c | 2 ++ src/southbridge/intel/common/smihandler.c | 2 ++ src/southbridge/intel/lynxpoint/smihandler.c | 2 ++ 6 files changed, 12 insertions(+) diff --git a/src/soc/amd/common/block/cpu/smm/smi_apmc.c b/src/soc/amd/common/block/cpu/smm/smi_apmc.c index 9df6ae3132..7c98405e10 100644 --- a/src/soc/amd/common/block/cpu/smm/smi_apmc.c +++ b/src/soc/amd/common/block/cpu/smm/smi_apmc.c @@ -33,6 +33,8 @@ static void *find_save_state(int cmd) /* Check all nodes looking for the one that issued the IO */ for (core = 0; core < CONFIG_MAX_CPUS; core++) { state = smm_get_save_state(core); + if (!state) + continue; smm_io_trap = state->smm_io_trap_offset; /* Check for Valid IO Trap Word (bit1==1) */ if (!(smm_io_trap & SMM_IO_TRAP_VALID)) diff --git a/src/soc/intel/braswell/smihandler.c b/src/soc/intel/braswell/smihandler.c index d2588cf766..617ee10f58 100644 --- a/src/soc/intel/braswell/smihandler.c +++ b/src/soc/intel/braswell/smihandler.c @@ -176,6 +176,8 @@ static em64t100_smm_state_save_area_t *smi_apmc_find_state_save(uint8_t cmd) /* Check all nodes looking for the one that issued the IO */ for (node = 0; node < CONFIG_MAX_CPUS; node++) { state = smm_get_save_state(node); + if (!state) + continue; /* Check for Synchronous IO (bit0==1) */ if (!(state->io_misc_info & (1 << 0))) diff --git a/src/soc/intel/broadwell/pch/smihandler.c b/src/soc/intel/broadwell/pch/smihandler.c index 99906d944c..890167b45b 100644 --- a/src/soc/intel/broadwell/pch/smihandler.c +++ b/src/soc/intel/broadwell/pch/smihandler.c @@ -228,6 +228,8 @@ static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd) /* Check all nodes looking for the one that issued the IO */ for (node = 0; node < CONFIG_MAX_CPUS; node++) { state = smm_get_save_state(node); + if (!state) + continue; /* Check for Synchronous IO (bit0 == 1) */ if (!(state->io_misc_info & (1 << 0))) diff --git a/src/soc/intel/denverton_ns/smihandler.c b/src/soc/intel/denverton_ns/smihandler.c index 3bdc2a47ac..88d3e808bb 100644 --- a/src/soc/intel/denverton_ns/smihandler.c +++ b/src/soc/intel/denverton_ns/smihandler.c @@ -141,6 +141,8 @@ static em64t100_smm_state_save_area_t *smi_apmc_find_state_save(uint8_t cmd) /* Check all nodes looking for the one that issued the IO */ for (node = 0; node < CONFIG_MAX_CPUS; node++) { state = smm_get_save_state(node); + if (!state) + continue; /* Check for Synchronous IO (bit0==1) */ if (!(state->io_misc_info & (1 << 0))) diff --git a/src/southbridge/intel/common/smihandler.c b/src/southbridge/intel/common/smihandler.c index 798f2f1387..b1a6a6689d 100644 --- a/src/southbridge/intel/common/smihandler.c +++ b/src/southbridge/intel/common/smihandler.c @@ -205,6 +205,8 @@ static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd) /* Check all nodes looking for the one that issued the IO */ for (node = 0; node < CONFIG_MAX_CPUS; node++) { state = smm_get_save_state(node); + if (!state) + continue; /* Check for Synchronous IO (bit0 == 1) */ if (!(state->io_misc_info & (1 << 0))) diff --git a/src/southbridge/intel/lynxpoint/smihandler.c b/src/southbridge/intel/lynxpoint/smihandler.c index 8caafb716f..838b448db4 100644 --- a/src/southbridge/intel/lynxpoint/smihandler.c +++ b/src/southbridge/intel/lynxpoint/smihandler.c @@ -177,6 +177,8 @@ static em64t101_smm_state_save_area_t *smi_apmc_find_state_save(u8 cmd) /* Check all nodes looking for the one that issued the IO */ for (node = 0; node < CONFIG_MAX_CPUS; node++) { state = smm_get_save_state(node); + if (!state) + continue; /* Check for Synchronous IO (bit0 == 1) */ if (!(state->io_misc_info & (1 << 0)))