From: Bjorn Helgaas <bhelgaas@google.com>
To: Levente Kurusa <levex@linux.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andrew Murray <amurray@embedded-bits.co.uk>,
Myron Stowe <myron.stowe@redhat.com>,
linux-pci@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Yinghai Lu <yinghai@kernel.org>
Subject: Re: [PATCH 32/38] pcie: add missing put_device call
Date: Thu, 19 Dec 2013 15:10:19 -0700 [thread overview]
Message-ID: <20131219221019.GB15201@google.com> (raw)
In-Reply-To: <1387465612-3673-33-git-send-email-levex@linux.com>
[+cc Greg, Yinghai]
On Thu, Dec 19, 2013 at 04:06:46PM +0100, Levente Kurusa wrote:
> This is required so that we give up the last reference to the device.
> Removed the kfree() as put_device will result in release_pcie_device being
> called and hence the container of the device will be kfree'd.
>
> Signed-off-by: Levente Kurusa <levex@linux.com>
Thanks, I applied a slightly modified version of this to my pci/deletion
branch for v3.14.
I think the get_device() after device_register() succeeds and the
put_device() before device_unregister() are superfluous, so I propose the
series included below. Any comments?
> ---
> drivers/pci/pcie/portdrv_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
> index 08d131f..80fb1f2 100644
> --- a/drivers/pci/pcie/portdrv_core.c
> +++ b/drivers/pci/pcie/portdrv_core.c
> @@ -345,7 +345,7 @@ static int pcie_device_init(struct pci_dev *pdev, int service, int irq)
>
> retval = device_register(device);
> if (retval)
> - kfree(pcie);
> + put_device(device);
> else
> get_device(device);
> return retval;
commit 8f3acca9acec1503f6b374faef2d1013cbf502af
Author: Bjorn Helgaas <bhelgaas@google.com>
Date: Thu Dec 19 14:20:09 2013 -0700
PCI/portdrv: Cleanup error paths
Make the straightline path the normal no-error path. Check for errors and
return them directly, instead of checking for success and putting the
normal path in an "if" body.
No functional change.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 0b6e76604068..fc86d323fecc 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -344,11 +344,13 @@ static int pcie_device_init(struct pci_dev *pdev, int service, int irq)
device_enable_async_suspend(device);
retval = device_register(device);
- if (retval)
+ if (retval) {
kfree(pcie);
- else
- get_device(device);
- return retval;
+ return retval;
+ }
+
+ get_device(device);
+ return 0;
}
/**
@@ -498,12 +500,12 @@ static int pcie_port_probe_service(struct device *dev)
pciedev = to_pcie_device(dev);
status = driver->probe(pciedev);
- if (!status) {
- dev_printk(KERN_DEBUG, dev, "service driver %s loaded\n",
- driver->name);
- get_device(dev);
- }
- return status;
+ if (status)
+ return status;
+
+ dev_printk(KERN_DEBUG, dev, "service driver %s loaded\n", driver->name);
+ get_device(dev);
+ return 0;
}
/**
commit f39862058e1f278e0495cd9ea57de571e74aa1fe
Author: Levente Kurusa <levex@linux.com>
Date: Thu Dec 19 14:22:35 2013 -0700
PCI/portdrv: Add put_device() after device_register() failure
This is required so that we give up the last reference to the device.
Removed the kfree() as put_device will result in release_pcie_device()
being called and hence the container of the device will be kfree'd.
[bhelgaas: fix conflict after my previous cleanup]
Signed-off-by: Levente Kurusa <levex@linux.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index fc86d323fecc..9811eea53511 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -345,7 +345,7 @@ static int pcie_device_init(struct pci_dev *pdev, int service, int irq)
retval = device_register(device);
if (retval) {
- kfree(pcie);
+ put_device(device);
return retval;
}
commit e75f34ce6633549486a044d64b2a79240d4113a8
Author: Bjorn Helgaas <bhelgaas@google.com>
Date: Thu Dec 19 14:24:13 2013 -0700
PCI/portdrv: Remove extra get_device()/put_device() for pcie_device
Previously pcie_device_init() called get_device() if device_register() for
the new pcie_device succeeded, and remove_iter() called put_device() when
removing before unregistering the device.
But device_register() already increments the reference count in
device_add(), so we don't need to do it again here.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 9811eea53511..6a6e54909335 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -349,7 +349,6 @@ static int pcie_device_init(struct pci_dev *pdev, int service, int irq)
return retval;
}
- get_device(device);
return 0;
}
@@ -456,10 +455,8 @@ int pcie_port_device_resume(struct device *dev)
static int remove_iter(struct device *dev, void *data)
{
- if (dev->bus == &pcie_port_bus_type) {
- put_device(dev);
+ if (dev->bus == &pcie_port_bus_type)
device_unregister(dev);
- }
return 0;
}
next prev parent reply other threads:[~2013-12-19 22:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-19 15:06 [PATCH 32/38] pcie: add missing put_device call Levente Kurusa
2013-12-19 15:06 ` [PATCH 33/38] scsi: transport: " Levente Kurusa
2013-12-19 15:19 ` James Bottomley
2013-12-19 15:06 ` [PATCH 34/38] infiniband: core: " Levente Kurusa
2013-12-19 15:06 ` [PATCH 35/38] media: bt8xx: " Levente Kurusa
2013-12-19 15:06 ` [PATCH 36/38] dio: " Levente Kurusa
2013-12-19 15:06 ` [PATCH 37/38] uwb: umc-dev: " Levente Kurusa
2013-12-19 15:06 ` [PATCH 38/38] bcma: " Levente Kurusa
2013-12-19 22:10 ` Bjorn Helgaas [this message]
2013-12-19 22:34 ` [PATCH 32/38] pcie: " Greg Kroah-Hartman
2013-12-20 6:15 ` Yinghai Lu
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=20131219221019.GB15201@google.com \
--to=bhelgaas@google.com \
--cc=amurray@embedded-bits.co.uk \
--cc=gregkh@linuxfoundation.org \
--cc=levex@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=myron.stowe@redhat.com \
--cc=yinghai@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.