qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2] qdev: add the device to the QOM tree before


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH v2] qdev: add the device to the QOM tree before using it to set a link
Date: Mon, 20 Jan 2014 13:47:55 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130923 Thunderbird/17.0.9

Il 02/01/2014 02:02, Amos Kong ha scritto:
> Test steps:
>   (qemu) device_add e1000,addr=adsf
>   Property 'e1000.addr' doesn't take value 'adsf'
>   (qemu) info qtree
> Then qemu crashed.
> 
> Currently we set a link to the new device for qdev parent bus, but the
> device hasn't been added to QOM tree. When it fails to set properties,
> object_unparent() can't cleanup the device.
> 
> This patch moves qdev_set_parent_bus() back to object_property_add_child(),
> we only needs to unref the object if setting properties fails.
> 
> Signed-off-by: Amos Kong <address@hidden>
> ---
> V2: fix bz by adjust the initialization order (Paolo)
> ---
>  qdev-monitor.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index dc37a43..4070b0a 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -518,16 +518,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>      /* create device, set properties */
>      dev = DEVICE(object_new(driver));
>  
> -    if (bus) {
> -        qdev_set_parent_bus(dev, bus);
> -    }
> -
>      id = qemu_opts_id(opts);
>      if (id) {
>          dev->id = id;
>      }
>      if (qemu_opt_foreach(opts, set_property, dev, 1) != 0) {
> -        object_unparent(OBJECT(dev));
>          object_unref(OBJECT(dev));
>          return NULL;
>      }
> @@ -541,6 +536,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>                                    OBJECT(dev), NULL);
>          g_free(name);
>      }
> +
> +    if (bus) {
> +        qdev_set_parent_bus(dev, bus);
> +    }
> +
>      object_property_set_bool(OBJECT(dev), true, "realized", &err);
>      if (err != NULL) {
>          qerror_report_err(err);
> 

Reviewed-by: Paolo Bonzini <address@hidden>



reply via email to

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