diff mbox

[for-2.1,2/2] qdev: Fix crash when using non-device class name on -global

Message ID 1404416735-22371-3-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost July 3, 2014, 7:45 p.m. UTC
This fixes the following crash:

    $ qemu-system-x86_64 -global container.xxx=y
    hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
    Aborted (core dumped)

New behavior will be to just warn, just like when non-existing clas
names are used:

    $ qemu-system-x86_64 -global container.xxx=y
    qemu-system-x86_64: Warning: "-global container.xxx=y" not used

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/qdev-properties-system.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Eric Blake July 3, 2014, 8:25 p.m. UTC | #1
On 07/03/2014 01:45 PM, Eduardo Habkost wrote:
> This fixes the following crash:
> 
>     $ qemu-system-x86_64 -global container.xxx=y
>     hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
>     Aborted (core dumped)
> 
> New behavior will be to just warn, just like when non-existing clas

s/clas/class/

> names are used:
> 
>     $ qemu-system-x86_64 -global container.xxx=y
>     qemu-system-x86_64: Warning: "-global container.xxx=y" not used
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/qdev-properties-system.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
> index 8e140af..ae0900f 100644
> --- a/hw/core/qdev-properties-system.c
> +++ b/hw/core/qdev-properties-system.c
> @@ -394,7 +394,8 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
>      g->driver   = qemu_opt_get(opts, "driver");
>      g->property = qemu_opt_get(opts, "property");
>      g->value    = qemu_opt_get(opts, "value");
> -    oc = object_class_by_name(g->driver);
> +    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
> +                                   TYPE_DEVICE);
>      if (oc) {
>          DeviceClass *dc = DEVICE_CLASS(oc);

I'm not an expert on the type system, but this one looks simple enough
that I don't mind:

Reviewed-by: Eric Blake <eblake@redhat.com>
Don Slutz July 3, 2014, 9:42 p.m. UTC | #2
On 07/03/14 16:25, Eric Blake wrote:
> On 07/03/2014 01:45 PM, Eduardo Habkost wrote:
>> This fixes the following crash:
>>
>>      $ qemu-system-x86_64 -global container.xxx=y
>>      hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
>>      Aborted (core dumped)
>>
>> New behavior will be to just warn, just like when non-existing clas
> s/clas/class/
>
>> names are used:
>>
>>      $ qemu-system-x86_64 -global container.xxx=y
>>      qemu-system-x86_64: Warning: "-global container.xxx=y" not used
>>
>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> ---
>>   hw/core/qdev-properties-system.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
>> index 8e140af..ae0900f 100644
>> --- a/hw/core/qdev-properties-system.c
>> +++ b/hw/core/qdev-properties-system.c
>> @@ -394,7 +394,8 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
>>       g->driver   = qemu_opt_get(opts, "driver");
>>       g->property = qemu_opt_get(opts, "property");
>>       g->value    = qemu_opt_get(opts, "value");
>> -    oc = object_class_by_name(g->driver);
>> +    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
>> +                                   TYPE_DEVICE);
>>       if (oc) {
>>           DeviceClass *dc = DEVICE_CLASS(oc);
> I'm not an expert on the type system, but this one looks simple enough
> that I don't mind:
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
>

Looks good to me also, and it passes my quick tests.

Tested-by: Don Slutz <dslutz@verizon.com>

    -Don Slutz
Igor Mammedov July 7, 2014, 6:41 a.m. UTC | #3
On Thu,  3 Jul 2014 16:45:35 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> This fixes the following crash:
> 
>     $ qemu-system-x86_64 -global container.xxx=y
>     hw/core/qdev-properties-system.c:399:qdev_add_one_global: Object 0x7f7eff234100 is not an instance of type device
>     Aborted (core dumped)
> 
> New behavior will be to just warn, just like when non-existing clas
> names are used:
> 
>     $ qemu-system-x86_64 -global container.xxx=y
>     qemu-system-x86_64: Warning: "-global container.xxx=y" not used
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/core/qdev-properties-system.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
> index 8e140af..ae0900f 100644
> --- a/hw/core/qdev-properties-system.c
> +++ b/hw/core/qdev-properties-system.c
> @@ -394,7 +394,8 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque)
>      g->driver   = qemu_opt_get(opts, "driver");
>      g->property = qemu_opt_get(opts, "property");
>      g->value    = qemu_opt_get(opts, "value");
> -    oc = object_class_by_name(g->driver);
> +    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
> +                                   TYPE_DEVICE);
>      if (oc) {
>          DeviceClass *dc = DEVICE_CLASS(oc);
>  

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
diff mbox

Patch

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 8e140af..ae0900f 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -394,7 +394,8 @@  static int qdev_add_one_global(QemuOpts *opts, void *opaque)
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    oc = object_class_by_name(g->driver);
+    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
+                                   TYPE_DEVICE);
     if (oc) {
         DeviceClass *dc = DEVICE_CLASS(oc);