All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: zhanghailiang <zhang.zhanghailiang@huawei.com>
Cc: luonengjun@huawei.com, qemu-devel@nongnu.org,
	lcapitulino@redhat.com, qiaonuohan@cn.fujitsu.com,
	peter.huangpeng@huawei.com, lersek@redhat.com
Subject: Re: [Qemu-devel] [PATCH v5 2/2] dump: Don't return error code when return an Error object
Date: Tue, 16 Sep 2014 18:24:44 +0200	[thread overview]
Message-ID: <87ppeva5yr.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <1410852659-13856-3-git-send-email-zhang.zhanghailiang@huawei.com> (zhanghailiang's message of "Tue, 16 Sep 2014 15:30:59 +0800")

zhanghailiang <zhang.zhanghailiang@huawei.com> writes:

> Functions shouldn't return an error code and an Error object at the same time.
> Turn all these functions that returning Error object to void.
> We also judge if a function success or fail by reference to the *errp.
>
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>  dump.c | 244 +++++++++++++++++++++++++----------------------------------------
>  1 file changed, 94 insertions(+), 150 deletions(-)
>
> diff --git a/dump.c b/dump.c
> index 07d2300..b2ed846 100644
> --- a/dump.c
> +++ b/dump.c
[...]
>  /* write the memroy to vmcore. 1 page per I/O. */
> -static int write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
> +static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
>                          int64_t size, Error **errp)
>  {
>      int64_t i;
> -    int ret;
>  
>      for (i = 0; i < size / TARGET_PAGE_SIZE; i++) {
> -        ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
> +        write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
>                           TARGET_PAGE_SIZE, errp);

Please fix up indentation of arguments.

> -        if (ret < 0) {
> -            return ret;
> +        if (*errp) {
> +            return;

This breaks when a caller choses to ignore errors by passing a null
argument for errp.

For static functions that may be okay.  But in general, we support null
arguments by coding like this:

    Error *local_err = NULL;
    int64_t i;

    for (i = 0; i < size / TARGET_PAGE_SIZE; i++) {
        write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
                   TARGET_PAGE_SIZE, &local_err);
        if (local_err) {
            error_propagate(errp, local_err);
            return;
        }
    }

I feel it's better to stick to this convention.

More of the same elsewhere.

>          }
>      }
[...]

  reply	other threads:[~2014-09-16 16:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-16  7:30 [Qemu-devel] [PATCH v5 0/2] Fix dump_error to return error message zhanghailiang
2014-09-16  7:30 ` [Qemu-devel] [PATCH v5 1/2] dump: let dump_error return error info to caller zhanghailiang
2014-09-16  7:30 ` [Qemu-devel] [PATCH v5 2/2] dump: Don't return error code when return an Error object zhanghailiang
2014-09-16 16:24   ` Markus Armbruster [this message]
2014-09-19  0:51     ` zhanghailiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ppeva5yr.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=lersek@redhat.com \
    --cc=luonengjun@huawei.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qiaonuohan@cn.fujitsu.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.