Patchwork qdev: Free opts on failed do_device_add

login
register
mail settings
Submitter Kevin Wolf
Date Feb. 16, 2010, 12:12 p.m.
Message ID <1266322358-7075-1-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/45463/
State New
Headers show

Comments

Kevin Wolf - Feb. 16, 2010, 12:12 p.m.
If the device can't be created, don't leak the QemuOpts and release the id of
the device that should have been added by the failed device_add.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 hw/qdev.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
Gerd Hoffmann - Feb. 16, 2010, 3:08 p.m.
On 02/16/10 13:12, Kevin Wolf wrote:
> If the device can't be created, don't leak the QemuOpts and release the id of
> the device that should have been added by the failed device_add.

Acked-by: Gerd Hoffmann <kraxel@redhat.com>

cheers,
   Gerd
Anthony Liguori - Feb. 19, 2010, 10:01 p.m.
On 02/16/2010 06:12 AM, Kevin Wolf wrote:
> If the device can't be created, don't leak the QemuOpts and release the id of
> the device that should have been added by the failed device_add.
>
> Signed-off-by: Kevin Wolf<kwolf@redhat.com>
>    

Applied.  Thanks.

Regards,

Anthony Liguori
> ---
>   hw/qdev.c |    7 +++++--
>   1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 539b5a2..d0052d4 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -749,8 +749,11 @@ void do_device_add(Monitor *mon, const QDict *qdict)
>
>       opts = qemu_opts_parse(&qemu_device_opts,
>                              qdict_get_str(qdict, "config"), "driver");
> -    if (opts&&  !qdev_device_help(opts))
> -        qdev_device_add(opts);
> +    if (opts) {
> +        if (qdev_device_help(opts) || qdev_device_add(opts) == NULL) {
> +            qemu_opts_del(opts);
> +        }
> +    }
>   }
>
>   void do_device_del(Monitor *mon, const QDict *qdict)
>

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 539b5a2..d0052d4 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -749,8 +749,11 @@  void do_device_add(Monitor *mon, const QDict *qdict)
 
     opts = qemu_opts_parse(&qemu_device_opts,
                            qdict_get_str(qdict, "config"), "driver");
-    if (opts && !qdev_device_help(opts))
-        qdev_device_add(opts);
+    if (opts) {
+        if (qdev_device_help(opts) || qdev_device_add(opts) == NULL) {
+            qemu_opts_del(opts);
+        }
+    }
 }
 
 void do_device_del(Monitor *mon, const QDict *qdict)