From patchwork Mon May 31 14:19:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 54099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id ED6E4B7D57 for ; Tue, 1 Jun 2010 00:20:35 +1000 (EST) Received: from localhost ([127.0.0.1]:60263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJ5qy-00024e-Ds for incoming@patchwork.ozlabs.org; Mon, 31 May 2010 10:20:32 -0400 Received: from [140.186.70.92] (port=33293 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJ5qF-00021p-Uf for qemu-devel@nongnu.org; Mon, 31 May 2010 10:19:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJ5qF-0000Ym-0b for qemu-devel@nongnu.org; Mon, 31 May 2010 10:19:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15618) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJ5qE-0000Ye-PW for qemu-devel@nongnu.org; Mon, 31 May 2010 10:19:46 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4VEJjOO020104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 31 May 2010 10:19:46 -0400 Received: from blackfin.pond.sub.org (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4VEJiT1022709; Mon, 31 May 2010 10:19:45 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 8C8066E; Mon, 31 May 2010 16:19:43 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 31 May 2010 16:19:43 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: amit.shah@redhat.com Subject: [Qemu-devel] [PATCH] virtio-serial: Simplify virtio_serial_load() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For all i, ports_map[i] is used in and only in the i-th iteration. Replace the dynamic array by a scalar variable. Signed-off-by: Markus Armbruster Acked-by: Amit Shah --- hw/virtio-serial-bus.c | 12 +++--------- 1 files changed, 3 insertions(+), 9 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 3ce95e8..bcc6d5d 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -492,8 +492,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id) { VirtIOSerial *s = opaque; VirtIOSerialPort *port; - size_t ports_map_size; - uint32_t max_nr_ports, nr_active_ports, *ports_map; + uint32_t max_nr_ports, nr_active_ports, ports_map; unsigned int i; if (version_id > 2) { @@ -517,22 +516,17 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id) return -EINVAL; } - ports_map_size = sizeof(uint32_t) * (max_nr_ports + 31) / 32; - ports_map = qemu_malloc(ports_map_size); - for (i = 0; i < (max_nr_ports + 31) / 32; i++) { - qemu_get_be32s(f, &ports_map[i]); + qemu_get_be32s(f, &ports_map); - if (ports_map[i] != s->ports_map[i]) { + if (ports_map != s->ports_map[i]) { /* * Ports active on source and destination don't * match. Fail migration. */ - qemu_free(ports_map); return -EINVAL; } } - qemu_free(ports_map); qemu_get_be32s(f, &nr_active_ports);