linux/drivers/misc/cxl
Daniel Axtens 2925c2fdf1 cxl: Fix unbalanced pci_dev_get in cxl_probe
Currently the first thing we do in cxl_probe is to grab a reference
on the pci device. Later on, we call device_register on our adapter.
In our remove path, we call device_unregister, but we never call
pci_dev_put. We therefore leak the device every time we do a
reflash.

device_register/unregister is sufficient to hold the reference.
Therefore, drop the call to pci_dev_get.

Here's why this is safe.
The proposed cxl_probe(pdev) calls cxl_adapter_init:
    a) init calls cxl_adapter_alloc, which creates a struct cxl,
       conventionally called adapter. This struct contains a
       device entry, adapter->dev.

    b) init calls cxl_configure_adapter, where we set
       adapter->dev.parent = &dev->dev (here dev is the pci dev)

So at this point, the cxl adapter's device's parent is the PCI
device that I want to be refcounted properly.

    c) init calls cxl_register_adapter
       *) cxl_register_adapter calls device_register(&adapter->dev)

So now we're in device_register, where dev is the adapter device, and
we want to know if the PCI device is safe after we return.

device_register(&adapter->dev) calls device_initialize() and then
device_add().

device_add() does a get_device(). device_add() also explicitly grabs
the device's parent, and calls get_device() on it:

         parent = get_device(dev->parent);

So therefore, device_register() takes a lock on the parent PCI dev,
which is what pci_dev_get() was guarding. pci_dev_get() can therefore
be safely removed.

Fixes: f204e0b8ce ("cxl: Driver code for powernv PCIe based cards for userspace access")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Axtens <dja@axtens.net>
Acked-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2015-09-15 19:33:38 +10:00
..
api.c cxl: Fix force unmapping mmaps of contexts allocated through the kernel api 2015-08-30 18:47:26 +10:00
base.c cxl: Move include file cxl.h -> cxl-base.h 2015-06-03 13:27:19 +10:00
context.c cxl: Fix force unmapping mmaps of contexts allocated through the kernel api 2015-08-30 18:47:26 +10:00
cxl.h cxl: Set up and enable PSL Timebase 2015-08-30 18:56:34 +10:00
debugfs.c cxl: sparse: Silence iomem warning in debugfs file creation 2015-08-12 14:49:29 +10:00
fault.c cxl: Only check pid for userspace contexts 2015-06-03 13:27:18 +10:00
file.c cxl: Add alternate MMIO error handling 2015-08-18 19:34:43 +10:00
irq.c cxl: Release irqs if memory allocation fails 2015-08-27 13:51:18 +10:00
Kconfig cxl: Add CONFIG_CXL_EEH symbol 2015-08-17 13:56:29 +10:00
main.c cxl: Destroy cxl_adapter_idr on module_exit 2015-07-16 14:14:55 +10:00
Makefile cxl: Compile with -Werror 2015-08-11 07:43:40 +10:00
native.c cxl: Allocate and release the SPA with the AFU 2015-08-14 21:32:04 +10:00
pci.c cxl: Fix unbalanced pci_dev_get in cxl_probe 2015-09-15 19:33:38 +10:00
sysfs.c powerpc updates for 4.3 2015-09-03 16:41:38 -07:00
trace.c cxl: Add tracepoints 2015-01-22 17:31:51 +11:00
trace.h cxl: use more common format specifier 2015-07-13 10:10:54 +10:00
vphb.c cxl: abort cxl_pci_enable_device_hook() if PCI channel is offline 2015-09-07 20:14:24 +10:00