From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF83Y-0000na-L4 for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:43:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XF839-0005Qa-0t for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:43:32 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:35045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF838-0005QD-Nh for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:43:06 -0400 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Aug 2014 14:43:06 -0600 From: Michael Roth Date: Wed, 6 Aug 2014 15:39:20 -0500 Message-Id: <1407357598-21541-71-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1407357598-21541-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1407357598-21541-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 070/108] migration: remove duplicate code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org From: ChenLiang version_id is checked twice in the ram_load. Signed-off-by: ChenLiang Signed-off-by: Gonglei Signed-off-by: Juan Quintela (cherry picked from commit 21a246a43b606ee833f907d589d8dcbb54a2761e) Signed-off-by: Michael Roth --- arch_init.c | 68 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/arch_init.c b/arch_init.c index 60c975d..85c6d6e 100644 --- a/arch_init.c +++ b/arch_init.c @@ -997,7 +997,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) seq_iter++; - if (version_id < 4 || version_id > 4) { + if (version_id != 4) { return -EINVAL; } @@ -1008,44 +1008,42 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) addr &= TARGET_PAGE_MASK; if (flags & RAM_SAVE_FLAG_MEM_SIZE) { - if (version_id == 4) { - /* Synchronize RAM block list */ - char id[256]; - ram_addr_t length; - ram_addr_t total_ram_bytes = addr; - - while (total_ram_bytes) { - RAMBlock *block; - uint8_t len; - - len = qemu_get_byte(f); - qemu_get_buffer(f, (uint8_t *)id, len); - id[len] = 0; - length = qemu_get_be64(f); - - QTAILQ_FOREACH(block, &ram_list.blocks, next) { - if (!strncmp(id, block->idstr, sizeof(id))) { - if (block->length != length) { - fprintf(stderr, - "Length mismatch: %s: " RAM_ADDR_FMT - " in != " RAM_ADDR_FMT "\n", id, length, - block->length); - ret = -EINVAL; - goto done; - } - break; + /* Synchronize RAM block list */ + char id[256]; + ram_addr_t length; + ram_addr_t total_ram_bytes = addr; + + while (total_ram_bytes) { + RAMBlock *block; + uint8_t len; + + len = qemu_get_byte(f); + qemu_get_buffer(f, (uint8_t *)id, len); + id[len] = 0; + length = qemu_get_be64(f); + + QTAILQ_FOREACH(block, &ram_list.blocks, next) { + if (!strncmp(id, block->idstr, sizeof(id))) { + if (block->length != length) { + fprintf(stderr, + "Length mismatch: %s: " RAM_ADDR_FMT + " in != " RAM_ADDR_FMT "\n", id, length, + block->length); + ret = -EINVAL; + goto done; } + break; } + } - if (!block) { - fprintf(stderr, "Unknown ramblock \"%s\", cannot " - "accept migration\n", id); - ret = -EINVAL; - goto done; - } - - total_ram_bytes -= length; + if (!block) { + fprintf(stderr, "Unknown ramblock \"%s\", cannot " + "accept migration\n", id); + ret = -EINVAL; + goto done; } + + total_ram_bytes -= length; } } -- 1.9.1