linux/drivers/pci/hotplug
Niklas Schnelle 0b13525c20 s390/pci: fix leak of PCI device structure
In commit 05bc1be6db ("s390/pci: create zPCI bus") we removed the
pci_dev_put() call matching the earlier pci_get_slot() done as part of
__zpci_event_availability(). This was based on the wrong understanding
that the device_put() done as part of pci_destroy_device() would counter
the pci_get_slot() when it only counters the initial reference. This
same understanding and existing bad example also lead to not doing
a pci_dev_put() in zpci_remove_device().

Since releasing the PCI devices, unlike releasing the PCI slot, does not
print any debug message for testing I added one in pci_release_dev().
This revealed that we are indeed leaking the PCI device on PCI
hotunplug. Further testing also revealed another missing pci_dev_put() in
disable_slot().

Fix this by adding the missing pci_dev_put() in disable_slot() and fix
zpci_remove_device() with the correct pci_dev_put() calls. Also instead
of calling pci_get_slot() in __zpci_event_availability() to determine if
a PCI device is registered and then doing the same again in
zpci_remove_device() do this once in zpci_remove_device() which makes
sure that the pdev in __zpci_event_availability() is only used for the
result of pci_scan_single_device() which does not need a reference count
decremnt as its ownership goes to the PCI bus.

Also move the check if zdev->zbus->bus is set into zpci_remove_device()
since it may be that we're removing a device with devfn != 0 which never
had a PCI bus. So we can still set the pdev->error_state to indicate
that the device is not usable anymore, add a flag to set the error state.

Fixes: 05bc1be6db ("s390/pci: create zPCI bus")
Cc: <stable@vger.kernel.org> # 5.8+: e1bff843cd s390/pci: remove superfluous zdev->zbus check
Cc: <stable@vger.kernel.org> # 5.8+: ba764dd703 s390/pci: refactor zpci_create_device()
Cc: <stable@vger.kernel.org> # 5.8+
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>
2021-03-15 19:10:56 +01:00
..
acpi_pcihp.c PCI: Fix kerneldoc warnings 2020-08-05 18:23:14 -05:00
acpiphp_core.c Merge branch 'xarray' of git://git.infradead.org/users/willy/linux-dax 2018-10-28 11:35:40 -07:00
acpiphp_glue.c PCI: hotplug: ACPI: Fix context refcounting in acpiphp_grab_context() 2020-06-26 19:42:34 +02:00
acpiphp_ibm.c PCI: hotplug: Embed hotplug_slot 2018-09-18 17:52:15 -05:00
acpiphp.h PCI: acpiphp: Remove unused acpiphp_callback typedef 2021-02-18 17:32:37 -06:00
cpci_hotplug_core.c PCI: Remove unnecessary returns 2019-08-30 14:00:34 -05:00
cpci_hotplug_pci.c PCI: hotplug: Embed hotplug_slot 2018-09-18 17:52:15 -05:00
cpci_hotplug.h PCI: hotplug: Embed hotplug_slot 2018-09-18 17:52:15 -05:00
cpcihp_generic.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpcihp_zt5550.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpcihp_zt5550.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpqphp_core.c PCI: Remove unnecessary returns 2019-08-30 14:00:34 -05:00
cpqphp_ctrl.c PCI: Remove unnecessary returns 2019-08-30 14:00:34 -05:00
cpqphp_nvram.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpqphp_nvram.h PCI: Remove unnecessary returns 2019-08-30 14:00:34 -05:00
cpqphp_pci.c Merge branch 'pci/spdx' into next 2018-02-01 11:40:07 -06:00
cpqphp_sysfs.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
cpqphp.h PCI: hotplug: Embed hotplug_slot 2018-09-18 17:52:15 -05:00
ibmphp_core.c PCI: ibmphp: Turn semaphores into completions or mutexes 2019-01-29 17:15:36 -06:00
ibmphp_ebda.c PCI: hotplug: Embed hotplug_slot 2018-09-18 17:52:15 -05:00
ibmphp_hpc.c PCI: ibmphp: Turn semaphores into completions or mutexes 2019-01-29 17:15:36 -06:00
ibmphp_pci.c PCI: ibmphp: Remove unneeded break 2020-11-20 11:17:55 -06:00
ibmphp_res.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
ibmphp.h PCI: ibmphp: Turn semaphores into completions or mutexes 2019-01-29 17:15:36 -06:00
Kconfig treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
Makefile PCI/hotplug: remove the sgi_hotplug driver 2019-08-16 11:33:56 -07:00
pci_hotplug_core.c PCI: hotplug: Drop hotplug_slot_info 2018-09-18 17:52:15 -05:00
pciehp_core.c PCI: Fix kerneldoc warnings 2020-08-05 18:23:14 -05:00
pciehp_ctrl.c pci-v5.10-changes 2020-10-22 12:41:00 -07:00
pciehp_hpc.c PCI: pciehp: Reduce noisiness on hot removal 2020-09-17 16:22:36 -05:00
pciehp_pci.c PCI: pciehp: Log messages with pci_dev, not pcie_device 2019-05-09 16:45:20 -05:00
pciehp.h PCI: pciehp: Remove unused EMI() and HP_SUPR_RM() macros 2020-04-23 13:45:35 -05:00
pnv_php.c pci/hotplug/pnv-php: Wrap warnings in macro 2020-01-23 21:31:17 +11:00
rpadlpar_core.c PCI: rpadlpar: Use for_each_child_of_node() and for_each_node_by_name() 2020-09-17 16:22:36 -05:00
rpadlpar_sysfs.c pci-v4.16-changes 2018-02-06 09:59:40 -08:00
rpadlpar.h PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
rpaphp_core.c PCI: Use of_node_name_eq() for node name comparisons 2020-04-24 18:02:17 -05:00
rpaphp_pci.c powerpc/eeh: Make early EEH init pseries specific 2020-03-25 12:09:39 +11:00
rpaphp_slot.c PCI: rpaphp: Get/put device node reference during slot alloc/dealloc 2019-04-10 16:07:12 -05:00
rpaphp.h PCI: hotplug: Embed hotplug_slot 2018-09-18 17:52:15 -05:00
s390_pci_hpc.c s390/pci: fix leak of PCI device structure 2021-03-15 19:10:56 +01:00
shpchp_core.c PCI: hotplug: Embed hotplug_slot 2018-09-18 17:52:15 -05:00
shpchp_ctrl.c pci-v5.10-changes 2020-10-22 12:41:00 -07:00
shpchp_hpc.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
shpchp_pci.c PCI: shpchp: Make shpchp_unconfigure_device() void 2020-05-21 15:23:20 -05:00
shpchp_sysfs.c PCI: Add SPDX GPL-2.0+ to replace GPL v2 or later boilerplate 2018-01-28 15:49:06 -06:00
shpchp.h PCI: shpchp: Make shpchp_unconfigure_device() void 2020-05-21 15:23:20 -05:00
TODO PCI: hotplug: Document TODOs 2018-09-18 17:52:15 -05:00