* [PATCH v2] pci: cleanly backout of pci_qdev_init()
@ 2010-05-11 10:44 ` Alex Williamson
0 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2010-05-11 10:44 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, kvm, alex.williamson
If the init function of a device fails, as might happen with device
assignment, we never undo the work done by do_pci_register_device().
This not only causes a bit of a memory leak, but also leaves a bogus
pointer in the bus devices array that can cause a segfault or
garbage data from 'info pci'.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
v2: Remove extraneous return from do_pci_unregister_device()(
hw/pci.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index f167436..3ca5f09 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -625,6 +625,13 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
return pci_dev;
}
+static void do_pci_unregister_device(PCIDevice *pci_dev)
+{
+ qemu_free_irqs(pci_dev->irq);
+ pci_dev->bus->devices[pci_dev->devfn] = NULL;
+ pci_config_free(pci_dev);
+}
+
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
int instance_size, int devfn,
PCIConfigReadFunc *config_read,
@@ -680,10 +687,7 @@ static int pci_unregister_device(DeviceState *dev)
return ret;
pci_unregister_io_regions(pci_dev);
-
- qemu_free_irqs(pci_dev->irq);
- pci_dev->bus->devices[pci_dev->devfn] = NULL;
- pci_config_free(pci_dev);
+ do_pci_unregister_device(pci_dev);
return 0;
}
@@ -1652,8 +1656,10 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
if (pci_dev == NULL)
return -1;
rc = info->init(pci_dev);
- if (rc != 0)
+ if (rc != 0) {
+ do_pci_unregister_device(pci_dev);
return rc;
+ }
/* rom loading */
if (pci_dev->romfile == NULL && info->romfile != NULL)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH v2] pci: cleanly backout of pci_qdev_init()
@ 2010-05-11 10:44 ` Alex Williamson
0 siblings, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2010-05-11 10:44 UTC (permalink / raw)
To: qemu-devel; +Cc: blauwirbel, alex.williamson, kvm
If the init function of a device fails, as might happen with device
assignment, we never undo the work done by do_pci_register_device().
This not only causes a bit of a memory leak, but also leaves a bogus
pointer in the bus devices array that can cause a segfault or
garbage data from 'info pci'.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
v2: Remove extraneous return from do_pci_unregister_device()(
hw/pci.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index f167436..3ca5f09 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -625,6 +625,13 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
return pci_dev;
}
+static void do_pci_unregister_device(PCIDevice *pci_dev)
+{
+ qemu_free_irqs(pci_dev->irq);
+ pci_dev->bus->devices[pci_dev->devfn] = NULL;
+ pci_config_free(pci_dev);
+}
+
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
int instance_size, int devfn,
PCIConfigReadFunc *config_read,
@@ -680,10 +687,7 @@ static int pci_unregister_device(DeviceState *dev)
return ret;
pci_unregister_io_regions(pci_dev);
-
- qemu_free_irqs(pci_dev->irq);
- pci_dev->bus->devices[pci_dev->devfn] = NULL;
- pci_config_free(pci_dev);
+ do_pci_unregister_device(pci_dev);
return 0;
}
@@ -1652,8 +1656,10 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
if (pci_dev == NULL)
return -1;
rc = info->init(pci_dev);
- if (rc != 0)
+ if (rc != 0) {
+ do_pci_unregister_device(pci_dev);
return rc;
+ }
/* rom loading */
if (pci_dev->romfile == NULL && info->romfile != NULL)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] pci: cleanly backout of pci_qdev_init()
2010-05-11 10:44 ` [Qemu-devel] " Alex Williamson
@ 2010-05-11 23:00 ` Michael S. Tsirkin
-1 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2010-05-11 23:00 UTC (permalink / raw)
To: Alex Williamson; +Cc: qemu-devel, blauwirbel, kvm
On Tue, May 11, 2010 at 06:44:21AM -0400, Alex Williamson wrote:
> If the init function of a device fails, as might happen with device
> assignment, we never undo the work done by do_pci_register_device().
> This not only causes a bit of a memory leak, but also leaves a bogus
> pointer in the bus devices array that can cause a segfault or
> garbage data from 'info pci'.
>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Thanks, applied.
> ---
>
> v2: Remove extraneous return from do_pci_unregister_device()(
>
> hw/pci.c | 16 +++++++++++-----
> 1 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index f167436..3ca5f09 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -625,6 +625,13 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
> return pci_dev;
> }
>
> +static void do_pci_unregister_device(PCIDevice *pci_dev)
> +{
> + qemu_free_irqs(pci_dev->irq);
> + pci_dev->bus->devices[pci_dev->devfn] = NULL;
> + pci_config_free(pci_dev);
> +}
> +
> PCIDevice *pci_register_device(PCIBus *bus, const char *name,
> int instance_size, int devfn,
> PCIConfigReadFunc *config_read,
> @@ -680,10 +687,7 @@ static int pci_unregister_device(DeviceState *dev)
> return ret;
>
> pci_unregister_io_regions(pci_dev);
> -
> - qemu_free_irqs(pci_dev->irq);
> - pci_dev->bus->devices[pci_dev->devfn] = NULL;
> - pci_config_free(pci_dev);
> + do_pci_unregister_device(pci_dev);
> return 0;
> }
>
> @@ -1652,8 +1656,10 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
> if (pci_dev == NULL)
> return -1;
> rc = info->init(pci_dev);
> - if (rc != 0)
> + if (rc != 0) {
> + do_pci_unregister_device(pci_dev);
> return rc;
> + }
>
> /* rom loading */
> if (pci_dev->romfile == NULL && info->romfile != NULL)
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [PATCH v2] pci: cleanly backout of pci_qdev_init()
@ 2010-05-11 23:00 ` Michael S. Tsirkin
0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2010-05-11 23:00 UTC (permalink / raw)
To: Alex Williamson; +Cc: blauwirbel, qemu-devel, kvm
On Tue, May 11, 2010 at 06:44:21AM -0400, Alex Williamson wrote:
> If the init function of a device fails, as might happen with device
> assignment, we never undo the work done by do_pci_register_device().
> This not only causes a bit of a memory leak, but also leaves a bogus
> pointer in the bus devices array that can cause a segfault or
> garbage data from 'info pci'.
>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Thanks, applied.
> ---
>
> v2: Remove extraneous return from do_pci_unregister_device()(
>
> hw/pci.c | 16 +++++++++++-----
> 1 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index f167436..3ca5f09 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -625,6 +625,13 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
> return pci_dev;
> }
>
> +static void do_pci_unregister_device(PCIDevice *pci_dev)
> +{
> + qemu_free_irqs(pci_dev->irq);
> + pci_dev->bus->devices[pci_dev->devfn] = NULL;
> + pci_config_free(pci_dev);
> +}
> +
> PCIDevice *pci_register_device(PCIBus *bus, const char *name,
> int instance_size, int devfn,
> PCIConfigReadFunc *config_read,
> @@ -680,10 +687,7 @@ static int pci_unregister_device(DeviceState *dev)
> return ret;
>
> pci_unregister_io_regions(pci_dev);
> -
> - qemu_free_irqs(pci_dev->irq);
> - pci_dev->bus->devices[pci_dev->devfn] = NULL;
> - pci_config_free(pci_dev);
> + do_pci_unregister_device(pci_dev);
> return 0;
> }
>
> @@ -1652,8 +1656,10 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
> if (pci_dev == NULL)
> return -1;
> rc = info->init(pci_dev);
> - if (rc != 0)
> + if (rc != 0) {
> + do_pci_unregister_device(pci_dev);
> return rc;
> + }
>
> /* rom loading */
> if (pci_dev->romfile == NULL && info->romfile != NULL)
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-11 23:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-11 10:44 [PATCH v2] pci: cleanly backout of pci_qdev_init() Alex Williamson
2010-05-11 10:44 ` [Qemu-devel] " Alex Williamson
2010-05-11 23:00 ` Michael S. Tsirkin
2010-05-11 23:00 ` [Qemu-devel] " Michael S. Tsirkin
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.