Hi Marek, On Sat, Sep 22, 2018 at 7:00 AM Marek Vasut <marek.va...@gmail.com> wrote: > > 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. >
Though adding the NULL pointer check makes the codes more robust, I would like to know with what calling sequence current codes are broken? I did a grep and looks every PCI controller driver registers a non-NULL dm_pci_ops so the ops can't be NULL, which means adding the check seems unnecessary. > Signed-off-by: Marek Vasut <marek.vasut+rene...@gmail.com> > Cc: Simon Glass <s...@chromium.org> > Cc: Tom Rini <tr...@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, > -- Regards, Bin _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot