src/drivers/intel: Avoid NULL pointer dereference

Coverity detects dereferencing pointers that might be "NULL" when
calling acpigen_write_scope and acpigen_write_device. Add sanity
check for both of scope and name to prevent NULL pointer dereference.

Found-by: Coverity CID 1429979, 1429982
TEST=Built and boot up to kernel.

Signed-off-by: John Zhao <john.zhao@intel.com>
Change-Id: If17d12861f562dc0d6c98a5c91a9d3c0360ca2c9
Reviewed-on: https://review.coreboot.org/c/coreboot/+/42835
Reviewed-by: Wonkyu Kim <wonkyu.kim@intel.com>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
John Zhao 2020-06-26 08:53:54 -07:00 committed by Patrick Georgi
parent bda27cd336
commit ff4ead052b
2 changed files with 17 additions and 4 deletions

View File

@ -29,13 +29,20 @@ static void con_fill_ssdt(const struct device *dev)
{
struct drivers_intel_pmc_mux_con_config *config = dev->chip_info;
struct acpi_dp *dsd;
const char *scope;
const char *name;
if (!dev->enabled)
return;
/* Reference the existing scope and write CONx device */
acpigen_write_scope(acpi_device_scope(dev));
acpigen_write_device(acpi_device_name(dev));
scope = acpi_device_scope(dev);
name = acpi_device_name(dev);
if (!scope || !name)
return;
acpigen_write_scope(scope);
acpigen_write_device(name);
acpigen_write_name_integer("_ADR", dev->path.generic.id);

View File

@ -13,8 +13,14 @@ static const char *mux_acpi_name(const struct device *dev)
static void mux_fill_ssdt(const struct device *dev)
{
acpigen_write_scope(acpi_device_scope(dev));
acpigen_write_device(acpi_device_name(dev));
const char *scope = acpi_device_scope(dev);
const char *name = acpi_device_name(dev);
if (!scope || !name)
return;
acpigen_write_scope(scope);
acpigen_write_device(name);
acpigen_write_name_string("_HID", TGL_PMC_MUX_HID);
acpigen_write_name_string("_DDN", dev->chip_ops->name);