Patchwork [PULL,10/13] qom: catch errors in object_property_add_child

login
register
mail settings
Submitter Luiz Capitulino
Date Dec. 18, 2013, 5 p.m.
Message ID <1387386003-8949-11-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/302999/
State New
Headers show

Comments

Luiz Capitulino - Dec. 18, 2013, 5 p.m.
From: Paolo Bonzini <pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-By: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qom/object.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Andreas Färber - Dec. 18, 2013, 7:09 p.m.
Am 18.12.2013 18:00, schrieb Luiz Capitulino:
> From: Paolo Bonzini <pbonzini@redhat.com>
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-By: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  qom/object.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index fc19cf6..68fe07a 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -988,17 +988,22 @@ static void object_finalize_child_property(Object *obj, const char *name,
>  void object_property_add_child(Object *obj, const char *name,
>                                 Object *child, Error **errp)
>  {
> +    Error *local_err = NULL;
>      gchar *type;
>  
>      type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
>  
>      object_property_add(obj, name, type, object_get_child_property,
> -                        NULL, object_finalize_child_property, child, errp);
> -
> +                        NULL, object_finalize_child_property, child, &local_err);
> +    if (error_is_set(&local_err)) {

I've been told we shouldn't error_is_set() that way but instead write:
if (local_err) {

No need to respin, but giving me a chance to ack this QOM patch would've
been nice.

Andreas

> +        error_propagate(errp, local_err);
> +        goto out;
> +    }
>      object_ref(child);
>      g_assert(child->parent == NULL);
>      child->parent = obj;
>  
> +out:
>      g_free(type);
>  }
>  
>
Markus Armbruster - Dec. 18, 2013, 7:58 p.m.
Andreas Färber <afaerber@suse.de> writes:

> Am 18.12.2013 18:00, schrieb Luiz Capitulino:
>> From: Paolo Bonzini <pbonzini@redhat.com>
>> 
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> Reviewed-By: Igor Mammedov <imammedo@redhat.com>
>> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
>> ---
>>  qom/object.c | 9 +++++++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>> 
>> diff --git a/qom/object.c b/qom/object.c
>> index fc19cf6..68fe07a 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -988,17 +988,22 @@ static void object_finalize_child_property(Object *obj, const char *name,
>>  void object_property_add_child(Object *obj, const char *name,
>>                                 Object *child, Error **errp)
>>  {
>> +    Error *local_err = NULL;
>>      gchar *type;
>>  
>>      type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
>>  
>>      object_property_add(obj, name, type, object_get_child_property,
>> -                        NULL, object_finalize_child_property, child, errp);
>> -
>> +                        NULL, object_finalize_child_property, child, &local_err);
>> +    if (error_is_set(&local_err)) {
>
> I've been told we shouldn't error_is_set() that way but instead write:
> if (local_err) {

"if (local_err)" is immediately obvious.

"if (error_is_set(&local_err))" isn't.  But it's consistent with places
where you do "if (error_is_set(errp))", where errp may be null, for
whatever that's worth.

Obvious is preferable.  Anyway, hardly a NAK-worthy crime.

[...]
Luiz Capitulino - Dec. 18, 2013, 10:17 p.m.
On Wed, 18 Dec 2013 20:09:03 +0100
Andreas Färber <afaerber@suse.de> wrote:

> Am 18.12.2013 18:00, schrieb Luiz Capitulino:
> > From: Paolo Bonzini <pbonzini@redhat.com>
> > 
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > Reviewed-By: Igor Mammedov <imammedo@redhat.com>
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > ---
> >  qom/object.c | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/qom/object.c b/qom/object.c
> > index fc19cf6..68fe07a 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -988,17 +988,22 @@ static void object_finalize_child_property(Object *obj, const char *name,
> >  void object_property_add_child(Object *obj, const char *name,
> >                                 Object *child, Error **errp)
> >  {
> > +    Error *local_err = NULL;
> >      gchar *type;
> >  
> >      type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
> >  
> >      object_property_add(obj, name, type, object_get_child_property,
> > -                        NULL, object_finalize_child_property, child, errp);
> > -
> > +                        NULL, object_finalize_child_property, child, &local_err);
> > +    if (error_is_set(&local_err)) {
> 
> I've been told we shouldn't error_is_set() that way but instead write:
> if (local_err) {

We've talked about adopting an idiom, and the general consensus seems
to be checking the error pointer straight is better than calling
error_is_set(). I'm OK with both ways and didn't consider rejecting
a patch because of that.

> No need to respin, but giving me a chance to ack this QOM patch would've
> been nice.

Oh, sorry for that. As I was preparing a pull request and as this
series got two Reviewed-bys (mine and Igor's) I just included it.

> 
> Andreas
> 
> > +        error_propagate(errp, local_err);
> > +        goto out;
> > +    }
> >      object_ref(child);
> >      g_assert(child->parent == NULL);
> >      child->parent = obj;
> >  
> > +out:
> >      g_free(type);
> >  }
> >  
> > 
> 
>
Peter Crosthwaite - Dec. 20, 2013, 2:27 a.m.
On Thu, Dec 19, 2013 at 3:00 AM, Luiz Capitulino <lcapitulino@redhat.com> wrote:
> From: Paolo Bonzini <pbonzini@redhat.com>
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-By: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  qom/object.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/qom/object.c b/qom/object.c
> index fc19cf6..68fe07a 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -988,17 +988,22 @@ static void object_finalize_child_property(Object *obj, const char *name,
>  void object_property_add_child(Object *obj, const char *name,
>                                 Object *child, Error **errp)
>  {
> +    Error *local_err = NULL;
>      gchar *type;
>
>      type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
>
>      object_property_add(obj, name, type, object_get_child_property,
> -                        NULL, object_finalize_child_property, child, errp);
> -
> +                        NULL, object_finalize_child_property, child, &local_err);

This long line causes a checkpatch failure.

Regards,
Peter

> +    if (error_is_set(&local_err)) {
> +        error_propagate(errp, local_err);
> +        goto out;
> +    }
>      object_ref(child);
>      g_assert(child->parent == NULL);
>      child->parent = obj;
>
> +out:
>      g_free(type);
>  }
>
> --
> 1.8.1.4
>
>

Patch

diff --git a/qom/object.c b/qom/object.c
index fc19cf6..68fe07a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -988,17 +988,22 @@  static void object_finalize_child_property(Object *obj, const char *name,
 void object_property_add_child(Object *obj, const char *name,
                                Object *child, Error **errp)
 {
+    Error *local_err = NULL;
     gchar *type;
 
     type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
 
     object_property_add(obj, name, type, object_get_child_property,
-                        NULL, object_finalize_child_property, child, errp);
-
+                        NULL, object_finalize_child_property, child, &local_err);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
+        goto out;
+    }
     object_ref(child);
     g_assert(child->parent == NULL);
     child->parent = obj;
 
+out:
     g_free(type);
 }