Skip to content

Commit 2877068

Browse files
mcaylandbonzini
authored andcommitted
softmmu/ioport.c: QOMify MemoryRegionPortioList
The aim of QOMification is so that the lifetime of the MemoryRegionPortioList structure can be managed using QOM's in-built refcounting instead of having to handle this manually. Due to the use of an opaque pointer it isn't possible to model the new TYPE_MEMORY_REGION_PORTIO_LIST directly using QOM properties, however since use of the new object is restricted to the portio API we can simply set the opaque pointer (and the heap-allocated port list) internally. Signed-off-by: Mark Cave-Ayland <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent d2f07b7 commit 2877068

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

softmmu/ioport.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@
3232
#include "exec/address-spaces.h"
3333
#include "trace.h"
3434

35-
typedef struct MemoryRegionPortioList {
35+
struct MemoryRegionPortioList {
36+
Object obj;
37+
3638
MemoryRegion mr;
3739
void *portio_opaque;
3840
MemoryRegionPortio *ports;
39-
} MemoryRegionPortioList;
41+
};
42+
43+
#define TYPE_MEMORY_REGION_PORTIO_LIST "memory-region-portio-list"
44+
OBJECT_DECLARE_SIMPLE_TYPE(MemoryRegionPortioList, MEMORY_REGION_PORTIO_LIST)
4045

4146
static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size)
4247
{
@@ -147,8 +152,7 @@ void portio_list_destroy(PortioList *piolist)
147152
for (i = 0; i < piolist->nr; ++i) {
148153
mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
149154
object_unparent(OBJECT(&mrpio->mr));
150-
g_free(mrpio->ports);
151-
g_free(mrpio);
155+
object_unref(mrpio);
152156
}
153157
g_free(piolist->regions);
154158
}
@@ -228,7 +232,8 @@ static void portio_list_add_1(PortioList *piolist,
228232
unsigned i;
229233

230234
/* Copy the sub-list and null-terminate it. */
231-
mrpio = g_malloc0(sizeof(MemoryRegionPortioList));
235+
mrpio = MEMORY_REGION_PORTIO_LIST(
236+
object_new(TYPE_MEMORY_REGION_PORTIO_LIST));
232237
mrpio->portio_opaque = piolist->opaque;
233238
mrpio->ports = g_malloc0(sizeof(MemoryRegionPortio) * (count + 1));
234239
memcpy(mrpio->ports, pio_init, sizeof(MemoryRegionPortio) * count);
@@ -298,3 +303,24 @@ void portio_list_del(PortioList *piolist)
298303
memory_region_del_subregion(piolist->address_space, &mrpio->mr);
299304
}
300305
}
306+
307+
static void memory_region_portio_list_finalize(Object *obj)
308+
{
309+
MemoryRegionPortioList *mrpio = MEMORY_REGION_PORTIO_LIST(obj);
310+
311+
g_free(mrpio->ports);
312+
}
313+
314+
static const TypeInfo memory_region_portio_list_info = {
315+
.parent = TYPE_OBJECT,
316+
.name = TYPE_MEMORY_REGION_PORTIO_LIST,
317+
.instance_size = sizeof(MemoryRegionPortioList),
318+
.instance_finalize = memory_region_portio_list_finalize,
319+
};
320+
321+
static void ioport_register_types(void)
322+
{
323+
type_register_static(&memory_region_portio_list_info);
324+
}
325+
326+
type_init(ioport_register_types)

0 commit comments

Comments
 (0)