Patchwork QOM: Fail casts for unknown types

login
register
mail settings
Submitter Alexander Graf
Date April 30, 2013, 1:02 p.m.
Message ID <1367326936-28539-1-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/240615/
State New
Headers show

Comments

Alexander Graf - April 30, 2013, 1:02 p.m.
When we try to cast an object to an unknown type, fail the cast. Today
we would simply run into an assert().

This fixes a bug on qemu-system-s390x for me that gets triggered by the
audio code looking for PCI and ISA buses.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 qom/object.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Paolo Bonzini - April 30, 2013, 1:57 p.m.
Il 30/04/2013 15:02, Alexander Graf ha scritto:
> When we try to cast an object to an unknown type, fail the cast. Today
> we would simply run into an assert().
> 
> This fixes a bug on qemu-system-s390x for me that gets triggered by the
> audio code looking for PCI and ISA buses.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>

Seems a better solution than guarding the object_resolve_path_type with
an if.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

> ---
>  qom/object.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index dd53d24..75e6aac 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -453,6 +453,11 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
>      TypeImpl *type = class->type;
>      ObjectClass *ret = NULL;
>  
> +    if (!target_type) {
> +        /* target class type unknown, so fail the cast */
> +        return NULL;
> +    }
> +
>      if (type->class->interfaces &&
>              type_is_ancestor(target_type, type_interface)) {
>          int found = 0;
>
Andreas Färber - April 30, 2013, 2:58 p.m.
Am 30.04.2013 15:02, schrieb Alexander Graf:
> When we try to cast an object to an unknown type, fail the cast. Today
> we would simply run into an assert().
> 
> This fixes a bug on qemu-system-s390x for me that gets triggered by the
> audio code looking for PCI and ISA buses.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>

Reviewed-by: Andreas Färber <afaerber@suse.de>

but "qom: ..." please, for proportional (Web) fonts. :)

Andreas
Anthony Liguori - April 30, 2013, 6:58 p.m.
Applied.  Thanks.

Regards,

Anthony Liguori

Patch

diff --git a/qom/object.c b/qom/object.c
index dd53d24..75e6aac 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -453,6 +453,11 @@  ObjectClass *object_class_dynamic_cast(ObjectClass *class,
     TypeImpl *type = class->type;
     ObjectClass *ret = NULL;
 
+    if (!target_type) {
+        /* target class type unknown, so fail the cast */
+        return NULL;
+    }
+
     if (type->class->interfaces &&
             type_is_ancestor(target_type, type_interface)) {
         int found = 0;