[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/13] ohci: fix resource cleanup leak
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PULL 12/13] ohci: fix resource cleanup leak |
Date: |
Wed, 18 Mar 2015 14:07:54 +0100 |
From: Gonglei <address@hidden>
When hot-unplugging the usb controllers (ehci/uhci),
we have to clean all resouce of these devices,
involved registered reset handler. Otherwise, it
may cause NULL pointer access and/or segmentation fault
if we reboot the guest os after hot-unplugging.
Let's hook up reset via DeviceClass->reset() and drop
the qemu_register_reset() call. Then Qemu will register
and unregister the reset handler automatically.
Ohci does't support hotplugging/hotunplugging yet, but
existing resource cleanup leak logic likes ehci/uhci.
Cc: qemu-stable <address@hidden>
Signed-off-by: Gonglei <address@hidden>
---
hw/usb/hcd-ohci.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index e180a17..1a22c9c 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -1883,7 +1883,6 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState
*dev,
usb_packet_init(&ohci->usb_packet);
ohci->async_td = 0;
- qemu_register_reset(ohci_reset, ohci);
}
#define TYPE_PCI_OHCI "pci-ohci"
@@ -1955,6 +1954,15 @@ static void usb_ohci_exit(PCIDevice *dev)
}
}
+static void usb_ohci_reset_pci(DeviceState *d)
+{
+ PCIDevice *dev = PCI_DEVICE(d);
+ OHCIPCIState *ohci = PCI_OHCI(dev);
+ OHCIState *s = &ohci->state;
+
+ ohci_reset(s);
+}
+
#define TYPE_SYSBUS_OHCI "sysbus-ohci"
#define SYSBUS_OHCI(obj) OBJECT_CHECK(OHCISysBusState, (obj), TYPE_SYSBUS_OHCI)
@@ -1980,6 +1988,14 @@ static void ohci_realize_pxa(DeviceState *dev, Error
**errp)
sysbus_init_mmio(sbd, &s->ohci.mem);
}
+static void usb_ohci_reset_sysbus(DeviceState *dev)
+{
+ OHCISysBusState *s = SYSBUS_OHCI(dev);
+ OHCIState *ohci = &s->ohci;
+
+ ohci_reset(ohci);
+}
+
static Property ohci_pci_properties[] = {
DEFINE_PROP_STRING("masterbus", OHCIPCIState, masterbus),
DEFINE_PROP_UINT32("num-ports", OHCIPCIState, num_ports, 3),
@@ -2101,6 +2117,7 @@ static void ohci_pci_class_init(ObjectClass *klass, void
*data)
dc->props = ohci_pci_properties;
dc->hotpluggable = false;
dc->vmsd = &vmstate_ohci;
+ dc->reset = usb_ohci_reset_pci;
}
static const TypeInfo ohci_pci_info = {
@@ -2124,6 +2141,7 @@ static void ohci_sysbus_class_init(ObjectClass *klass,
void *data)
set_bit(DEVICE_CATEGORY_USB, dc->categories);
dc->desc = "OHCI USB Controller";
dc->props = ohci_sysbus_properties;
+ dc->reset = usb_ohci_reset_sysbus;
}
static const TypeInfo ohci_sysbus_info = {
--
1.8.3.1
- [Qemu-devel] [PULL for-2.3 00/13] usb patch queue., Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 02/13] usb: Improve companion configuration error messages, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 13/13] ehci: fix segfault when hot-unplugging ehci controller, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 11/13] uhci: fix segfault when hot-unplugging uhci controller, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 12/13] ohci: fix resource cleanup leak,
Gerd Hoffmann <=
- [Qemu-devel] [PULL 03/13] ohci: Complete conversion to realize, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 08/13] usb/dev-storage: Fix QMP device_add missing encryption key failure, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 04/13] uhci: Convert to realize, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 06/13] monitor: Plug memory leak in monitor_read_bdrv_key_start(), Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 07/13] monitor usb: Inline monitor_read_bdrv_key_start()'s first part, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 05/13] monitor: Drop dead QMP check from monitor_read_password(), Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 10/13] hw/usb: Include USB files only if necessary, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 09/13] usb/dev-storage: Avoid qerror_report_err() outside QMP handlers, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 01/13] usb: Propagate errors through usb_register_companion(), Gerd Hoffmann, 2015/03/18
- Re: [Qemu-devel] [PULL for-2.3 00/13] usb patch queue., Peter Maydell, 2015/03/19