soc/amd/picasso: Avoid NULL pointer dereference

Coverity detects dereferencing a pointer that might be "NULL" when
calling acpigen_write_scope. Add sanity check for scope to prevent
NULL pointer dereference.

Found-by: Coverity CID 1429980
TEST=None

Signed-off-by: John Zhao <john.zhao@intel.com>
Change-Id: I6214fb83bccb19fe4edad65ce6b862815b8dcec6
Reviewed-on: https://review.coreboot.org/c/coreboot/+/42837
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
John Zhao 2020-06-26 10:00:02 -07:00 committed by Aaron Durbin
parent 7b1cb0d603
commit f6f1f734ee
1 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <acpi/acpigen.h>
#include <assert.h>
#include <cbmem.h>
#include <console/console.h>
#include <cpu/amd/msr.h>
@ -134,14 +135,13 @@ static void read_resources(struct device *dev)
static void root_complex_fill_ssdt(const struct device *device)
{
msr_t msr;
const char *scope;
if (!device) {
printk(BIOS_ERR, "%s: device is NULL! ACPI SSDT will be incomplete.\n",
__func__);
return;
}
assert(device);
acpigen_write_scope(acpi_device_scope(device));
scope = acpi_device_scope(device);
assert(scope);
acpigen_write_scope(scope);
msr = rdmsr(TOP_MEM);
acpigen_write_name_dword("TOM1", msr.lo);