qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen.5i5j@gmail.com>
To: Michael Tokarev <mjt@tls.msk.ru>
Cc: mst@redhat.com, QEMU Trivial <qemu-trivial@nongnu.org>,
	quintela@redhat.com, QEMU Developers <qemu-devel@nongnu.org>,
	owasserm@redhat.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] arch_init: Simplify code for load_xbzrle()
Date: Sun, 18 May 2014 18:53:22 +0800	[thread overview]
Message-ID: <53789122.7080904@gmail.com> (raw)
In-Reply-To: <537715BF.90005@msgid.tls.msk.ru>

On 05/17/2014 03:54 PM, Michael Tokarev wrote:
> 10.05.2014 16:51, Chen Gang wrote:
>> For xbzrle_decode_buffer(), when decoding contents will exceed writing
>> buffer, it will return -1, so need not check the return value whether
>> large than writing buffer.
>>
>> And when failure occurs within load_xbzrle(), it always return -1
>> without any resources which need release.
>>
>> So can remove the related checking statements, and also can remove 'rc'
>> and 'ret' local variables,
> 
> Just one comment below.
> 
>> @@ -933,18 +932,13 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
>>      qemu_get_buffer(f, xbzrle_decoded_buf, xh_len);
>>  
>>      /* decode RLE */
>> -    ret = xbzrle_decode_buffer(xbzrle_decoded_buf, xh_len, host,
>> -                               TARGET_PAGE_SIZE);
>> -    if (ret == -1) {
>> +    if (xbzrle_decode_buffer(xbzrle_decoded_buf, xh_len, host,
>> +                             TARGET_PAGE_SIZE) == -1) {
> 
> Can we compare like '< 0' here, not like '== -1' ?

That's fine to me.

> Are there any other possible return values from xbzrle_decode_buffer()
> which are less than zero but non-error?
> 

Although, at present, when it fails, it will only return -1.


> To me, anything less than zero is always error (unless it is one of the
> possible non-error values, like offset for example which can be negative).
> 

That sounds reasonable to me, too.

> Especially having in mind that in the future, some function may extend
> its error return to include the actual error code (like -errno), in which
> case code which compares with -1 will not work anymore.
> 

Yeah, in the future, it may do.

> Is it okay to me to apply this with s/== -1/< 0/ ?
> 

At least, it is OK to me.


BTW: the related test code for xbzrle_decode_buffer() may also need
improved (although, after read through, I still don't known what it
really want to do).

diff --git a/tests/test-xbzrle.c b/tests/test-xbzrle.c
index db93b0a..c8b4e58 100644
--- a/tests/test-xbzrle.c
+++ b/tests/test-xbzrle.c
@@ -162,7 +162,7 @@ static void encode_decode_range(void)
                                 PAGE_SIZE);
 
     rc = xbzrle_decode_buffer(compressed, dlen, test, PAGE_SIZE);
-    g_assert(rc < PAGE_SIZE);
+    g_assert(rc < PAGE_SIZE && rc >= 0);
     g_assert(memcmp(test, buffer, PAGE_SIZE) == 0);
 
     g_free(buffer);

Please help check when you have time. If necessary, I shall send related
patch for it. (this fix may be still incorrect, if so, please help send
related patch for it, and welcome to mark me as Reported-by for it).


Thanks.
-- 
Chen Gang

Open, share and attitude like air, water and life which God blessed

  reply	other threads:[~2014-05-18 10:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-10 12:51 [Qemu-devel] [PATCH] arch_init: Simplify code for load_xbzrle() Chen Gang
2014-05-12 10:27 ` Juan Quintela
2014-05-17  7:54 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2014-05-18 10:53   ` Chen Gang [this message]
2014-05-19  7:46     ` Michael Tokarev

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=53789122.7080904@gmail.com \
    --to=gang.chen.5i5j@gmail.com \
    --cc=mjt@tls.msk.ru \
    --cc=mst@redhat.com \
    --cc=owasserm@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=quintela@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).