[U-Boot] [PATCH 2/6] pci: Check ops before using them for config space access

Marek Vasut marek.vasut at gmail.com
Fri Sep 21 22:59:17 UTC 2018


The code fails to check if ops is non-NULL before using it's members.
Add the missing check and while at it, flip the condition to make it
more obvious what is actually happening.

Signed-off-by: Marek Vasut <marek.vasut+renesas at gmail.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Tom Rini <trini at konsulko.com>
---
 drivers/pci/pci-uclass.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index eb118f3496..de523a76ad 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -241,9 +241,9 @@ int pci_bus_write_config(struct udevice *bus, pci_dev_t bdf, int offset,
 	struct dm_pci_ops *ops;
 
 	ops = pci_get_ops(bus);
-	if (!ops->write_config)
-		return -ENOSYS;
-	return ops->write_config(bus, bdf, offset, value, size);
+	if (ops && ops->write_config)
+		return ops->write_config(bus, bdf, offset, value, size);
+	return -ENOSYS;
 }
 
 int pci_bus_clrset_config32(struct udevice *bus, pci_dev_t bdf, int offset,
@@ -321,9 +321,9 @@ int pci_bus_read_config(struct udevice *bus, pci_dev_t bdf, int offset,
 	struct dm_pci_ops *ops;
 
 	ops = pci_get_ops(bus);
-	if (!ops->read_config)
-		return -ENOSYS;
-	return ops->read_config(bus, bdf, offset, valuep, size);
+	if (ops && ops->read_config)
+		return ops->read_config(bus, bdf, offset, valuep, size);
+	return -ENOSYS;
 }
 
 int pci_read_config(pci_dev_t bdf, int offset, unsigned long *valuep,
-- 
2.18.0



More information about the U-Boot mailing list