[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/6] hw/usb: Replace alloc() + address_space_init() by address_sp
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 5/6] hw/usb: Replace alloc() + address_space_init() by address_space_create() |
Date: |
Thu, 19 Aug 2021 16:20:38 +0200 |
Replace g_malloc0() + address_space_init() by address_space_create().
Release the resource in DeviceUnrealize().
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
hw/usb/hcd-xhci-sysbus.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/hw/usb/hcd-xhci-sysbus.c b/hw/usb/hcd-xhci-sysbus.c
index a14e4381960..04ac485e8b3 100644
--- a/hw/usb/hcd-xhci-sysbus.c
+++ b/hw/usb/hcd-xhci-sysbus.c
@@ -43,16 +43,19 @@ static void xhci_sysbus_realize(DeviceState *dev, Error
**errp)
s->irq = g_new0(qemu_irq, s->xhci.numintrs);
qdev_init_gpio_out_named(dev, s->irq, SYSBUS_DEVICE_GPIO_IRQ,
s->xhci.numintrs);
- if (s->xhci.dma_mr) {
- s->xhci.as = g_malloc0(sizeof(AddressSpace));
- address_space_init(s->xhci.as, s->xhci.dma_mr, NULL);
- } else {
- s->xhci.as = &address_space_memory;
- }
+ s->xhci.as = address_space_create(s->xhci.dma_mr ?: get_system_memory(),
+ NULL);
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->xhci.mem);
}
+static void xhci_sysbus_unrealize(DeviceState *dev)
+{
+ XHCISysbusState *s = XHCI_SYSBUS(dev);
+
+ address_space_destroy(s->xhci.as);
+}
+
static void xhci_sysbus_instance_init(Object *obj)
{
XHCISysbusState *s = XHCI_SYSBUS(obj);
@@ -103,6 +106,7 @@ static void xhci_sysbus_class_init(ObjectClass *klass, void
*data)
dc->reset = xhci_sysbus_reset;
dc->realize = xhci_sysbus_realize;
+ dc->unrealize = xhci_sysbus_unrealize;
dc->vmsd = &vmstate_xhci_sysbus;
device_class_set_props(dc, xhci_sysbus_props);
}
--
2.31.1
- Re: [PATCH 1/6] memory: Do not increase refcount on global system_memory region, (continued)
[PATCH 5/6] hw/usb: Replace alloc() + address_space_init() by address_space_create(),
Philippe Mathieu-Daudé <=
[RFC PATCH 6/6] memory: Have address_space_create() re-use global &address_space_memory, Philippe Mathieu-Daudé, 2021/08/19