drivers/usb: 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 1430454
TEST=Built and boot up to kernel on Volteer.

Signed-off-by: John Zhao <john.zhao@intel.com>
Change-Id: I8ece3831bbd2641ceafbd71b9dc3db7e04a8eae4
Reviewed-on: https://review.coreboot.org/c/coreboot/+/43449
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
John Zhao 2020-07-14 09:07:48 -07:00 committed by Patrick Georgi
parent f09b4b6bee
commit acdf5fd66e
1 changed files with 7 additions and 2 deletions

View File

@ -187,11 +187,16 @@ static void xhci_add_devices(const struct device *dev)
static void xhci_fill_ssdt(const struct device *dev) static void xhci_fill_ssdt(const struct device *dev)
{ {
int gpe; int gpe;
const char *scope = acpi_device_scope(dev);
const char *name = acpi_device_name(dev);
if (!scope || !name)
return;
printk(BIOS_DEBUG, "xHCI SSDT generation\n"); printk(BIOS_DEBUG, "xHCI SSDT generation\n");
acpigen_write_scope(acpi_device_scope(dev)); acpigen_write_scope(scope);
acpigen_write_device(acpi_device_name(dev)); acpigen_write_device(name);
acpigen_write_ADR_pci_device(dev); acpigen_write_ADR_pci_device(dev);
acpigen_write_name_string("_DDN", "xHC - Extensible Host Controller"); acpigen_write_name_string("_DDN", "xHC - Extensible Host Controller");