From: Michael Ellerman <mpe@ellerman.id.au>
To: Daniel Axtens <dja@axtens.net>, linuxppc-dev@ozlabs.org
Cc: mikey@neuling.org, imunsie@au1.ibm.com,
andrew.donnellan@au1.ibm.com, Daniel Axtens <dja@axtens.net>
Subject: Re: [v2] cxl: Fix unbalanced pci_dev_get in cxl_probe
Date: Thu, 17 Sep 2015 15:13:28 +1000 (AEST) [thread overview]
Message-ID: <20150917051328.A67EA140291@ozlabs.org> (raw)
In-Reply-To: <1442293447-1843-1-git-send-email-dja@axtens.net>
On Tue, 2015-15-09 at 05:04:07 UTC, Daniel Axtens wrote:
> 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: f204e0b8cedd ("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>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/2925c2fdf1e0eb642482f5b3
cheers
prev parent reply other threads:[~2015-09-17 5:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-15 5:04 [PATCH v2] cxl: Fix unbalanced pci_dev_get in cxl_probe Daniel Axtens
2015-09-15 5:12 ` Ian Munsie
2015-09-17 5:13 ` Michael Ellerman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150917051328.A67EA140291@ozlabs.org \
--to=mpe@ellerman.id.au \
--cc=andrew.donnellan@au1.ibm.com \
--cc=dja@axtens.net \
--cc=imunsie@au1.ibm.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=mikey@neuling.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).