From: Bjorn Helgaas <bhelgaas@google.com>
To: Jiang Liu <liuj97@gmail.com>
Cc: Jiang Liu <jiang.liu@huawei.com>,
Yijing Wang <wangyijing@huawei.com>,
linux-pci@vger.kernel.org
Subject: Re: [PATCH 1/2] PCI: fix a double free issue in pci_create_root_bus() error recovery path
Date: Fri, 7 Jun 2013 19:42:51 -0600 [thread overview]
Message-ID: <20130608014251.GA5874@google.com> (raw)
In-Reply-To: <1370538609-28903-1-git-send-email-jiang.liu@huawei.com>
On Fri, Jun 07, 2013 at 01:10:08AM +0800, Jiang Liu wrote:
> On pci_create_root_bus() error recovery path, device_unregister(&bridge->dev)
> should have freed memory used by bridge, so we shouldn't call kfree(bridge)
> again, it's a double free.
>
> On the other hand, we should not use kfree() to free memory used by
> device object once we have invoked device_register() because it's
> reference-counted.
>
> Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
> Cc: stable@vger.kernel.org
> ---
> Hi Bjorn,
> This is the patch to fix the kfree() issue, it may be a material
> for stable trees.
> Thanks!
> Gerry
> ---
> drivers/pci/probe.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 8882b5d..2f81a0a 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -1729,12 +1729,16 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
> bridge->dev.release = pci_release_bus_bridge_dev;
> dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus);
> error = pcibios_root_bridge_prepare(bridge);
> - if (error)
> - goto bridge_dev_reg_err;
> + if (error) {
> + kfree(bridge);
> + goto err_out;
> + }
>
> error = device_register(&bridge->dev);
> - if (error)
> - goto bridge_dev_reg_err;
> + if (error) {
> + kfree(bridge);
Per device_register() comment, this should be a put_device().
I added this patch with that change to my pci/jiang-bus-lock-v3 branch.
I know a subsequent patch removes this anyway. I might be a little
obsessive.
> + goto err_out;
> + }
> b->bridge = get_device(&bridge->dev);
> device_enable_async_suspend(b->bridge);
> pci_set_bus_of_node(b);
> @@ -1790,8 +1794,6 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
> class_dev_reg_err:
> put_device(&bridge->dev);
> device_unregister(&bridge->dev);
> -bridge_dev_reg_err:
> - kfree(bridge);
> err_out:
> kfree(b);
> return NULL;
> --
> 1.8.1.2
>
next prev parent reply other threads:[~2013-06-08 1:42 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-25 13:48 [PATCH v3, part1 00/10] Prepare for introducing PCI bus lock interfaces Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 01/10] PCI: introduce pci_bus_{get|put}() to manage PCI bus reference count Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 02/10] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev() Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 03/10] PCI: Convert alloc_pci_dev(void) to pci_alloc_dev(bus) instead Jiang Liu
2013-06-05 20:07 ` Bjorn Helgaas
2013-06-06 16:16 ` Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 04/10] PCI: mark pci_scan_bus_parented() as __deprecated Jiang Liu
2013-05-31 20:12 ` Chris Metcalf
2013-06-05 20:04 ` Bjorn Helgaas
2013-06-06 16:32 ` Jiang Liu
2013-06-07 14:37 ` Konrad Rzeszutek Wilk
2013-06-07 15:11 ` Jiang Liu
2013-06-07 15:30 ` Jiang Liu
2013-06-07 20:37 ` Bjorn Helgaas
2013-05-25 13:48 ` [PATCH v3, part1 05/10] PCI, IA64: minor code clean up Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 06/10] PCI: make PCI host bridge/bus creating and destroying logic symmetric Jiang Liu
2013-06-05 20:14 ` Bjorn Helgaas
2013-06-06 17:10 ` [PATCH 1/2] PCI: fix a double free issue in pci_create_root_bus() error recovery path Jiang Liu
2013-06-08 1:42 ` Bjorn Helgaas [this message]
2013-06-06 17:10 ` [PATCH 2/2] PCI: make PCI host bridge/bus creating and destroying logic symmetric Jiang Liu
2013-06-06 20:01 ` Yinghai Lu
2013-06-08 1:51 ` Bjorn Helgaas
2013-06-08 7:01 ` Yinghai Lu
2013-06-14 23:53 ` Bjorn Helgaas
2013-06-15 1:46 ` Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 07/10] PCI, unicore, m68k: remove redundant call of pci_bus_add_devices() Jiang Liu
2013-06-05 21:31 ` Bjorn Helgaas
2013-06-06 6:54 ` Greg Ungerer
2013-05-25 13:48 ` [PATCH v3, part1 08/10] PCI, IOV: don't touch bus->is_added flag Jiang Liu
2013-05-25 13:48 ` [PATCH v3, part1 09/10] PCI, IOV: simplify IOV implementation Jiang Liu
2013-05-28 2:00 ` Yinghai Lu
2013-05-28 14:48 ` Liu Jiang
2013-05-30 4:31 ` [PATCH] PCI, IOV: fix a resource leakage on error recovery path Jiang Liu
2013-05-30 18:24 ` Bjorn Helgaas
2013-05-25 13:48 ` [PATCH v3, part1 10/10] PCI, IOV: hide remove and rescan sysfs interfaces for SR-IOV virtual functions Jiang Liu
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=20130608014251.GA5874@google.com \
--to=bhelgaas@google.com \
--cc=jiang.liu@huawei.com \
--cc=linux-pci@vger.kernel.org \
--cc=liuj97@gmail.com \
--cc=wangyijing@huawei.com \
/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).