qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: peter.maydell@linaro.org, aliguori@us.ibm.com,
	qemu-devel@nongnu.org, Liu Ping Fan <qemulist@gmail.com>
Subject: Re: [Qemu-devel] [PATCH 1.3 4/5] qdev: simplify (de)allocation of buses
Date: Fri, 23 Nov 2012 18:07:45 +0100	[thread overview]
Message-ID: <50AFAD61.4040907@suse.de> (raw)
In-Reply-To: <1353660436-8897-5-git-send-email-pbonzini@redhat.com>

Am 23.11.2012 09:47, schrieb Paolo Bonzini:
> All conditional deallocation can now be done with object_delete.
> Remove the @qom_allocated and @glib_allocated fields; replace the latter
> with a direct assignment of the @free function pointer.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

I am grateful for your suggestion to clean up this mess! However...

> ---
>  hw/pci.c       |  2 +-
>  hw/qdev-core.h |  5 -----
>  hw/qdev.c      | 10 +---------
>  hw/sysbus.c    |  2 +-
>  4 files changed, 3 insertions(+), 16 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index 9841e39..97a0cd7 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -301,9 +301,9 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name,
>      PCIBus *bus;
>  
>      bus = g_malloc0(sizeof(*bus));
> -    bus->qbus.glib_allocated = true;
>      pci_bus_new_inplace(bus, parent, name, address_space_mem,
>                          address_space_io, devfn_min);
> +    OBJECT(bus)->free = g_free;

Anthony asked not to use the macros like this, but in this case to have
Object *obj; to assign it after g_malloc0() and use obj->free = g_free;
here.

>      return bus;
>  }
>  
> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
> index fce9e22..fff7f0f 100644
> --- a/hw/qdev-core.h
> +++ b/hw/qdev-core.h
> @@ -106,17 +106,12 @@ typedef struct BusChild {
>  
>  /**
>   * BusState:
> - * @qom_allocated: Indicates whether the object was allocated by QOM.
> - * @glib_allocated: Indicates whether the object was initialized in-place
> - * yet is expected to be freed with g_free().
>   */
>  struct BusState {
>      Object obj;
>      DeviceState *parent;
>      const char *name;
>      int allow_hotplug;
> -    bool qom_allocated;
> -    bool glib_allocated;
>      int max_index;
>      QTAILQ_HEAD(ChildrenHead, BusChild) children;
>      QLIST_ENTRY(BusState) sibling;
> diff --git a/hw/qdev.c b/hw/qdev.c
> index f43717b..788b4da 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -454,7 +454,6 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam
>      BusState *bus;
>  
>      bus = BUS(object_new(typename));
> -    bus->qom_allocated = true;
>  
>      bus->parent = parent;
>      bus->name = name ? g_strdup(name) : NULL;
> @@ -465,14 +464,7 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam
>  
>  void qbus_free(BusState *bus)
>  {
> -    if (bus->qom_allocated) {
> -        object_delete(OBJECT(bus));
> -    } else {
> -        object_finalize(OBJECT(bus));
> -        if (bus->glib_allocated) {
> -            g_free(bus);
> -        }
> -    }
> +    object_delete(OBJECT(bus));

In this case ("free") I have no objection to using "delete" for
simplification. ;)

>  }
>  
>  static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev)
> diff --git a/hw/sysbus.c b/hw/sysbus.c
> index 4969f06..ef8ffb6 100644
> --- a/hw/sysbus.c
> +++ b/hw/sysbus.c
> @@ -274,7 +274,7 @@ static void main_system_bus_create(void)
>      main_system_bus = g_malloc0(system_bus_info.instance_size);
>      qbus_create_inplace(main_system_bus, TYPE_SYSTEM_BUS, NULL,
>                          "main-system-bus");
> -    main_system_bus->glib_allocated = true;
> +    OBJECT(main_system_bus)->free = g_free;

Same here.

>      object_property_add_child(container_get(qdev_get_machine(),
>                                              "/unattached"),
>                                "sysbus", OBJECT(main_system_bus), NULL);
> 

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  reply	other threads:[~2012-11-23 17:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-23  8:47 [Qemu-devel] [PATCH 1.3 0/5] QOM/qdev lifetime fixes Paolo Bonzini
2012-11-23  8:47 ` [Qemu-devel] [PATCH 1.3 1/5] qom: fix refcount of non-heap-allocated objects Paolo Bonzini
2012-11-23 16:49   ` Andreas Färber
2012-11-26 15:49   ` Anthony Liguori
2012-11-26 16:08     ` Paolo Bonzini
2012-11-23  8:47 ` [Qemu-devel] [PATCH 1.3 2/5] qdev: move bus removal to object_unparent Paolo Bonzini
2012-11-23 16:52   ` Andreas Färber
2012-11-27  1:02   ` Andreas Färber
2012-11-23  8:47 ` [Qemu-devel] [PATCH 1.3 3/5] qom: make object_delete usable for statically-allocated objects Paolo Bonzini
2012-11-23 17:02   ` Andreas Färber
2012-11-23 17:10     ` Paolo Bonzini
2012-11-23  8:47 ` [Qemu-devel] [PATCH 1.3 4/5] qdev: simplify (de)allocation of buses Paolo Bonzini
2012-11-23 17:07   ` Andreas Färber [this message]
2012-11-23 17:16     ` Paolo Bonzini
2012-11-23  8:47 ` [Qemu-devel] [PATCH 1.3 5/5] qom: make object_finalize static Paolo Bonzini
2012-11-23 17:12   ` Andreas Färber
2012-11-23 17:32     ` Paolo Bonzini
2012-11-26 21:47 ` [Qemu-devel] [PATCH 1.3 0/5] QOM/qdev lifetime fixes Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50AFAD61.4040907@suse.de \
    --to=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemulist@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).