qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] qdev: unparent device when fails to set propert


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH] qdev: unparent device when fails to set properties
Date: Tue, 31 Dec 2013 17:06:44 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130923 Thunderbird/17.0.9

Il 31/12/2013 09:06, Amos Kong ha scritto:
> When it fails to set properties, qdev's parent is already set

Do not confuse the QOM parent (which is /machine/peripheral, of which
the new device is a child) with the qdev parent bus (which has a link to
the new device)!

In general, you should add the device to the QOM tree before using it to
set a link.  So I believe that object_property_add_child should be
called before qdev_set_parent_bus.  This is the root cause of the bug;
the fix then could be one of the following:

1) move qdev_set_parent_bus later;

2) move object_property_add_child before the setting of properties.


I slightly prefer the first, so that initialization happens in this order:

1) create object

2) set properties -- if it fails, you can just unref the object

3) add child -- if it fails due to duplicate ID, you can again just
unref the object

4) set parent bus (cannot fail)

5) realize -- if it fails, you need to unparent the object and unref the
object

6) drop the reference now that the object is kept solidly alive by
QOM/qdev, and return.

This matches a bit more closely what happens with object-add, too.

Paolo



reply via email to

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