From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTvYu-0003ld-KX for qemu-devel@nongnu.org; Tue, 16 Sep 2014 12:25:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTvYp-0007gb-RW for qemu-devel@nongnu.org; Tue, 16 Sep 2014 12:25:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18262) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTvYp-0007fo-IF for qemu-devel@nongnu.org; Tue, 16 Sep 2014 12:24:59 -0400 From: Markus Armbruster References: <1410852659-13856-1-git-send-email-zhang.zhanghailiang@huawei.com> <1410852659-13856-3-git-send-email-zhang.zhanghailiang@huawei.com> Date: Tue, 16 Sep 2014 18:24:44 +0200 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") Message-ID: <87ppeva5yr.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v5 2/2] dump: Don't return error code when return an Error object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: zhanghailiang Cc: luonengjun@huawei.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, qiaonuohan@cn.fujitsu.com, peter.huangpeng@huawei.com, lersek@redhat.com zhanghailiang 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 > --- > 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. > } > } [...]