Commit 740a1931 authored by Philippe Mathieu-Daudé's avatar Philippe Mathieu-Daudé Committed by David Gibson
Browse files

spapr_pci: Fix potential NULL pointer dereference in spapr_dt_pci_bus()



Commit 14e71490 refactored the call to spapr_dt_drc(),
introducing a potential NULL pointer dereference while
accessing bus->parent_dev.
A trivial audit show 'bus' is not null in the two places
the static function spapr_dt_drc() is called.

Since the 'bus' parameter is not NULL in both callers, remove
remove the test on if (bus), and add an assert() to silent
static analyzers.

This fixes:

  /hw/ppc/spapr_pci.c: 1367 in spapr_dt_pci_bus()
  >>>     CID 1401933:  Null pointer dereferences  (FORWARD_NULL)
  >>>     Dereferencing null pointer "bus".
  1367         ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
  1368                            SPAPR_DR_CONNECTOR_TYPE_PCI);

Fixes: 14e71490
Reported-by: Coverity (CID 1401933)
Suggested-by: default avatarGreg Kurz <groug@kaod.org>
Suggested-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20190613213406.22053-1-philmd@redhat.com>
Signed-off-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
parent c29a0b0f
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -1356,13 +1356,12 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
    _FDT(fdt_setprop_cell(fdt, offset, "#size-cells",
                          RESOURCE_CELLS_SIZE));

    if (bus) {
    assert(bus);
    pci_for_each_device_reverse(bus, pci_bus_num(bus),
                                spapr_dt_pci_device_cb, &cbinfo);
    if (cbinfo.err) {
        return cbinfo.err;
    }
    }

    ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
                       SPAPR_DR_CONNECTOR_TYPE_PCI);