Hello Felix Singer,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/46297
to review the following change.
Change subject: device/pci: Add NULL check for PCI driver's .ops ......................................................................
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.
Change-Id: I5dcc05ebb092fb9c4be929c81ea2b05a10b1311b Signed-off-by: Nico Huber nico.huber@secunet.com --- M src/device/pci_device.c 1 file changed, 7 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/97/46297/1
diff --git a/src/device/pci_device.c b/src/device/pci_device.c index 80dad7e..62c4535 100644 --- a/src/device/pci_device.c +++ b/src/device/pci_device.c @@ -955,13 +955,16 @@ 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:
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/46297 )
Change subject: device/pci: Add NULL check for PCI driver's .ops ......................................................................
Patch Set 1: Code-Review+1
(1 comment)
https://review.coreboot.org/c/coreboot/+/46297/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/46297/1//COMMIT_MSG@10 PS1, Line 10: if `.ops` was set by a driver. Maybe add:
This avoids a NULL pointer dereference in case a driver with NULL .ops would match.
Hello Felix Singer, build bot (Jenkins), Angel Pons,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/46297
to look at the new patch set (#2).
Change subject: device/pci: Add NULL check for PCI driver's .ops ......................................................................
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 nico.huber@secunet.com --- M src/device/pci_device.c 1 file changed, 7 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/97/46297/2
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/46297 )
Change subject: device/pci: Add NULL check for PCI driver's .ops ......................................................................
Patch Set 2: Code-Review+2
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/46297 )
Change subject: device/pci: Add NULL check for PCI driver's .ops ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/46297/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/46297/1//COMMIT_MSG@10 PS1, Line 10: if `.ops` was set by a driver.
Maybe add: […]
Done
Stefan Reinauer has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/46297 )
Change subject: device/pci: Add NULL check for PCI driver's .ops ......................................................................
Patch Set 2: Code-Review+2
Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/46297 )
Change subject: device/pci: Add NULL check for PCI driver's .ops ......................................................................
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 nico.huber@secunet.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/46297 Reviewed-by: Angel Pons th3fanbus@gmail.com Reviewed-by: Stefan Reinauer stefan.reinauer@coreboot.org Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M src/device/pci_device.c 1 file changed, 7 insertions(+), 4 deletions(-)
Approvals: build bot (Jenkins): Verified Stefan Reinauer: Looks good to me, approved Angel Pons: Looks good to me, approved
diff --git a/src/device/pci_device.c b/src/device/pci_device.c index c3f3564..a008977 100644 --- a/src/device/pci_device.c +++ b/src/device/pci_device.c @@ -954,13 +954,16 @@ 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: