[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/6] memory: Introduce address_space_create()
From: |
Peter Maydell |
Subject: |
Re: [PATCH 2/6] memory: Introduce address_space_create() |
Date: |
Thu, 19 Aug 2021 15:24:57 +0100 |
On Thu, 19 Aug 2021 at 15:20, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> Introduce address_space_create(). In is similar to
> address_space_init() but returns a pointer to a heap
> allocated AddressSpace.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> include/exec/memory.h | 14 ++++++++++++++
> softmmu/memory.c | 10 ++++++++++
> 2 files changed, 24 insertions(+)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index c3d417d317f..b353a48c25f 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -2418,6 +2418,20 @@ MemTxResult memory_region_dispatch_write(MemoryRegion
> *mr,
> */
> void address_space_init(AddressSpace *as, MemoryRegion *root, const char
> *name);
>
> +/**
> + * address_space_create: Create and initializes an address space
> + *
> + * @root: a #MemoryRegion that routes addresses for the address space
> + * @name: an address space name. The name is only used for debugging
> + * output.
> + *
> + * Returns pointer to initialized #AddressSpace.
> + *
> + * The caller is responsible for releasing the pointer returned
> + * with address_space_destroy() after use.
> + */
> +AddressSpace *address_space_create(MemoryRegion *root, const char *name);
> +
I'm not really a fan of this as an API -- almost always I think
devices would do better to have an AddressSpace foo field in
their device struct and call address_space_init() on that.
Hiding the heap allocation inside this function makes it harder
to notice it during code review, I think.
thanks
-- PMM
[PATCH 5/6] hw/usb: Replace alloc() + address_space_init() by address_space_create(), Philippe Mathieu-Daudé, 2021/08/19
[RFC PATCH 6/6] memory: Have address_space_create() re-use global &address_space_memory, Philippe Mathieu-Daudé, 2021/08/19