s390/pci: reset zdev->zbus on registration failure
authorNiklas Schnelle <schnelle@linux.ibm.com>
Fri, 6 Aug 2021 10:12:11 +0000 (12:12 +0200)
committerHeiko Carstens <hca@linux.ibm.com>
Wed, 25 Aug 2021 09:03:32 +0000 (11:03 +0200)
On failure to register a struct zpci_dev with a struct zpci_bus we left
a dangling pointer in zdev->zbus. As zpci_create_device() bails if
zpci_bus_device_register() fails this is of no consequence but still bad
practice.

Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/pci/pci_bus.c

index 9629f97..3c9ad51 100644 (file)
@@ -343,11 +343,11 @@ static int zpci_bus_add_device(struct zpci_bus *zbus, struct zpci_dev *zdev)
 {
        int rc = -EINVAL;
 
-       zdev->zbus = zbus;
        if (zbus->function[zdev->devfn]) {
                pr_err("devfn %04x is already assigned\n", zdev->devfn);
                return rc;
        }
+       zdev->zbus = zbus;
        zbus->function[zdev->devfn] = zdev;
        zpci_nb_devices++;
 
@@ -367,6 +367,7 @@ static int zpci_bus_add_device(struct zpci_bus *zbus, struct zpci_dev *zdev)
 
 error:
        zbus->function[zdev->devfn] = NULL;
+       zdev->zbus = NULL;
        zpci_nb_devices--;
        return rc;
 }