qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/2] vl.c: reduce exit on error code duplication


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 2/2] vl.c: reduce exit on error code duplication
Date: Wed, 15 Oct 2014 08:35:53 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1

On 10/15/2014 05:03 AM, Igor Mammedov wrote:
> use exit_if_error() helper instead of a bunch of
>     if (local_err) {
>         error_report(foo);
>         error_free(local_err);
>         exit(1);
>     }
> code blocks
> 
> Signed-off-by: Igor Mammedov <address@hidden>
> ---
>  vl.c | 58 ++++++++++++++++++++++++++++++----------------------------
>  1 file changed, 30 insertions(+), 28 deletions(-)

Not much net change, but I like the refactoring.


>  static int default_driver_check(QemuOpts *opts, void *opaque)
>  {
>      const char *driver = qemu_opt_get(opts, "driver");
> @@ -2380,11 +2404,7 @@ static int chardev_init_func(QemuOpts *opts, void 
> *opaque)
>      Error *local_err = NULL;
>  
>      qemu_chr_new_from_opts(opts, NULL, &local_err);
> -    if (local_err) {
> -        error_report("%s", error_get_pretty(local_err));
> -        error_free(local_err);
> -        return -1;
> -    }
> +    exit_if_error(local_err, NULL);
>      return 0;
>  }

Idea for followup patch: this function now always returns 0 (if it
returns at all); therefore, change its signature to void and simplify
further.

>  
> @@ -2790,12 +2810,7 @@ static int machine_set_property(const char *name, 
> const char *value,
>      string_input_visitor_cleanup(siv);
>      g_free(qom_name);
>  
> -    if (local_err) {
> -        qerror_report_err(local_err);
> -        error_free(local_err);
> -        return -1;
> -    }
> -
> +    exit_if_error(local_err, NULL);
>      return 0;
>  }

Same idea for simplification.

But as that should be a separate patch, this one is:
Reviewed-by: Eric Blake <address@hidden>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]