qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 05/12] qdev: add reference count to a device


From: Andreas Färber
Subject: Re: [Qemu-devel] [PATCH v3 05/12] qdev: add reference count to a device for the BusChild
Date: Fri, 25 Jan 2013 13:08:07 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2

Am 25.01.2013 12:46, schrieb Paolo Bonzini:
> Each device has a reference through the BusChild.  This reference
> was not accounted for, add it now.
> 
> Signed-off-by: Paolo Bonzini <address@hidden>

I don't understand the comments about ownership. As far as I understand,
there's one ref for the child list entry and one additional ref for the
property but no "transfer" of ownership.

Having said that, ref'ing and unref'ing

Reviewed-by: Andreas Färber <address@hidden>

Andreas

> ---
>  hw/qdev.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 59dce62..78eedf0 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -64,7 +64,10 @@ static void bus_remove_child(BusState *bus, DeviceState 
> *child)
>  
>              snprintf(name, sizeof(name), "child[%d]", kid->index);
>              QTAILQ_REMOVE(&bus->children, kid, sibling);
> +
> +            /* This gives back ownership of kid->child back to us.  */
>              object_property_del(OBJECT(bus), name, NULL);
> +            object_unref(OBJECT(kid->child));
>              g_free(kid);
>              return;
>          }
> @@ -82,9 +85,11 @@ static void bus_add_child(BusState *bus, DeviceState 
> *child)
>  
>      kid->index = bus->max_index++;
>      kid->child = child;
> +    object_ref(OBJECT(kid->child));
>  
>      QTAILQ_INSERT_HEAD(&bus->children, kid, sibling);
>  
> +    /* This transfers ownership of kid->child to the property.  */
>      snprintf(name, sizeof(name), "child[%d]", kid->index);
>      object_property_add_link(OBJECT(bus), name,
>                               object_get_typename(OBJECT(child)),
> 


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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]