From 7e3e1ea43f6de16b3369e9bca8374bc956dfb0bf Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Mon, 12 Oct 2020 16:25:40 +0200 Subject: [PATCH] device/pci: Add NULL check for PCI driver's .ops Add a NULL check and only skip setting the default operations if `.ops` was set by a driver. It's fairly unlikely that some- body adds a driver and forgets the `.ops` pointer. So this is mostly to increase readability: Nobody should have to wonder if we're missing a NULL-check. The condition is moved out of the loop to reduce indentation levels. Alternatively, we could jusk skip drivers that don't have `.ops` set (i.e. continue the loop). Change-Id: I5dcc05ebb092fb9c4be929c81ea2b05a10b1311b Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/coreboot/+/46297 Reviewed-by: Angel Pons Reviewed-by: Stefan Reinauer Tested-by: build bot (Jenkins) --- src/device/pci_device.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/device/pci_device.c b/src/device/pci_device.c index c3f356413f..a00897736a 100644 --- a/src/device/pci_device.c +++ b/src/device/pci_device.c @@ -954,13 +954,16 @@ static void set_pci_ops(struct device *dev) if ((driver->vendor == dev->vendor) && device_id_match(driver, dev->device)) { dev->ops = (struct device_operations *)driver->ops; - printk(BIOS_SPEW, "%s [%04x/%04x] %sops\n", - dev_path(dev), driver->vendor, driver->device, - (driver->ops->scan_bus ? "bus " : "")); - return; + break; } } + if (dev->ops) { + printk(BIOS_SPEW, "%s [%04x/%04x] %sops\n", dev_path(dev), + driver->vendor, driver->device, (driver->ops->scan_bus ? "bus " : "")); + return; + } + /* If I don't have a specific driver use the default operations. */ switch (dev->hdr_type & 0x7f) { /* Header type */ case PCI_HEADER_TYPE_NORMAL: