From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF2fp-0007gT-B7 for qemu-devel@nongnu.org; Fri, 21 Sep 2012 08:49:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TF2fo-0002ny-3m for qemu-devel@nongnu.org; Fri, 21 Sep 2012 08:49:37 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:45429) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF2fn-0002no-Nd for qemu-devel@nongnu.org; Fri, 21 Sep 2012 08:49:36 -0400 Received: by pbbrp12 with SMTP id rp12so7613157pbb.4 for ; Fri, 21 Sep 2012 05:49:34 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <505C6259.7000702@redhat.com> Date: Fri, 21 Sep 2012 14:49:29 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1348217255-22441-1-git-send-email-quintela@redhat.com> <1348217255-22441-35-git-send-email-quintela@redhat.com> In-Reply-To: <1348217255-22441-35-git-send-email-quintela@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 34/41] savevm: Only qemu_fflush() can generate errors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: qemu-devel@nongnu.org Il 21/09/2012 10:47, Juan Quintela ha scritto: > Move the error check to the beggining of the callers. Once this is fixed > qemu_file_set_if_error() is not used anymore, so remove it. > > Signed-off-by: Juan Quintela > --- > savevm.c | 35 ++++++++++++++++++----------------- > 1 file changed, 18 insertions(+), 17 deletions(-) > > diff --git a/savevm.c b/savevm.c > index 4e4aa3c..59ec8bf 100644 > --- a/savevm.c > +++ b/savevm.c > @@ -445,18 +445,6 @@ void qemu_file_set_error(QEMUFile *f, int ret) > f->last_error = ret; > } > > -/** Sets last_error conditionally > - * > - * Sets last_error only if ret is negative _and_ no error > - * was set before. > - */ > -static void qemu_file_set_if_error(QEMUFile *f, int ret) > -{ > - if (ret < 0 && !f->last_error) { > - qemu_file_set_error(f, ret); > - } > -} > - > /** Flushes QEMUFile buffer > * > */ > @@ -544,13 +532,17 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) > { > int l; > > - if (!f->last_error && f->is_write == 0 && f->buf_index > 0) { > + if (f->last_error) { > + return; > + } > + > + if (f->is_write == 0 && f->buf_index > 0) { > fprintf(stderr, > "Attempted to write to buffer while read buffer is not empty\n"); > abort(); > } > > - while (!f->last_error && size > 0) { > + while (size > 0) { > l = IO_BUF_SIZE - f->buf_index; > if (l > size) > l = size; > @@ -561,14 +553,21 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) > size -= l; > if (f->buf_index >= IO_BUF_SIZE) { > int ret = qemu_fflush(f); > - qemu_file_set_if_error(f, ret); > + if (ret < 0) { > + qemu_file_set_error(f, ret); > + break; > + } > } > } > } > > void qemu_put_byte(QEMUFile *f, int v) > { > - if (!f->last_error && f->is_write == 0 && f->buf_index > 0) { > + if (f->last_error) { > + return; > + } > + > + if (f->is_write == 0 && f->buf_index > 0) { > fprintf(stderr, > "Attempted to write to buffer while read buffer is not empty\n"); > abort(); > @@ -578,7 +577,9 @@ void qemu_put_byte(QEMUFile *f, int v) > f->is_write = 1; > if (f->buf_index >= IO_BUF_SIZE) { > int ret = qemu_fflush(f); > - qemu_file_set_if_error(f, ret); > + if (ret < 0) { > + qemu_file_set_error(f, ret); > + } > } > } > Just a matter of taste, but I happen to agree. Reviewed-by: Paolo Bonzini