Patchwork [v3,10/10] qdev: Do not let the user try to device_add when it cannot work

login
register
mail settings
Submitter Markus Armbruster
Date Oct. 30, 2013, 4:28 p.m.
Message ID <1383150524-16250-11-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/287283/
State New
Headers show

Comments

Markus Armbruster - Oct. 30, 2013, 4:28 p.m.
From: Markus Armbruster <armbru@redhat.com>

Such devices have always been unavailable and omitted from the list of
available devices shown by device_add help.  Until commit 18b6dad
silently broke the former, setting up nasty traps for unwary users,
like this one:

    $ qemu-system-x86_64 -nodefaults -monitor stdio -display none
    QEMU 1.6.50 monitor - type 'help' for more information
    (qemu) device_add apic
    Segmentation fault (core dumped)

I call that a regression.  Fix it.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qdev-monitor.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Marcel Apfelbaum - Oct. 31, 2013, 12:41 p.m.
On Wed, 2013-10-30 at 17:28 +0100, armbru@redhat.com wrote:
> From: Markus Armbruster <armbru@redhat.com>
> 
> Such devices have always been unavailable and omitted from the list of
> available devices shown by device_add help.  Until commit 18b6dad
> silently broke the former, setting up nasty traps for unwary users,
> like this one:
> 
>     $ qemu-system-x86_64 -nodefaults -monitor stdio -display none
>     QEMU 1.6.50 monitor - type 'help' for more information
>     (qemu) device_add apic
>     Segmentation fault (core dumped)
> 
> I call that a regression.  Fix it.

Seems OK to me.
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>

> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  qdev-monitor.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index 36f6f09..d3d87a3 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -477,13 +477,13 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>          }
>      }
>  
> -    if (!obj) {
> +    k = DEVICE_CLASS(obj);
> +
> +    if (!k || k->cannot_instantiate_with_device_add_yet) {
>          qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
>          return NULL;
>      }
>  
> -    k = DEVICE_CLASS(obj);
> -
>      /* find bus */
>      path = qemu_opt_get(opts, "bus");
>      if (path != NULL) {

Patch

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 36f6f09..d3d87a3 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -477,13 +477,13 @@  DeviceState *qdev_device_add(QemuOpts *opts)
         }
     }
 
-    if (!obj) {
+    k = DEVICE_CLASS(obj);
+
+    if (!k || k->cannot_instantiate_with_device_add_yet) {
         qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
         return NULL;
     }
 
-    k = DEVICE_CLASS(obj);
-
     /* find bus */
     path = qemu_opt_get(opts, "bus");
     if (path != NULL) {