From patchwork Fri Jan 8 14:25:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 42508 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 6E07AB7C06 for ; Sat, 9 Jan 2010 01:35:40 +1100 (EST) Received: from localhost ([127.0.0.1]:54468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NTFw8-0008J1-PK for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2010 09:35:36 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NTFmm-0003Hx-Nu for qemu-devel@nongnu.org; Fri, 08 Jan 2010 09:25:57 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NTFmg-0003DV-S6 for qemu-devel@nongnu.org; Fri, 08 Jan 2010 09:25:55 -0500 Received: from [199.232.76.173] (port=43425 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NTFmg-0003DP-JC for qemu-devel@nongnu.org; Fri, 08 Jan 2010 09:25:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20415) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NTFmg-0006KZ-5T for qemu-devel@nongnu.org; Fri, 08 Jan 2010 09:25:50 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o08EPnAd030160 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 8 Jan 2010 09:25:49 -0500 Received: from zweiblum.home.kraxel.org (vpn2-11-198.ams2.redhat.com [10.36.11.198]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o08EPmBR006271; Fri, 8 Jan 2010 09:25:48 -0500 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 79B7E70FCA; Fri, 8 Jan 2010 15:25:42 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 8 Jan 2010 15:25:39 +0100 Message-Id: <1262960742-18267-4-git-send-email-kraxel@redhat.com> In-Reply-To: <1262960742-18267-1-git-send-email-kraxel@redhat.com> References: <1262960742-18267-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 3/6] fw_cfg: rom loader tweaks. 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 Changes: - make dir argument mandatory, we allways have one anyway (vgaroms or genroms). - check for duplicates, skip loading if found. Signed-off-by: Gerd Hoffmann --- hw/fw_cfg.c | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c index fe9c527..ea120ba 100644 --- a/hw/fw_cfg.c +++ b/hw/fw_cfg.c @@ -278,7 +278,7 @@ int fw_cfg_add_file(FWCfgState *s, const char *dir, const char *filename, uint8_t *data, uint32_t len) { const char *basename; - int index; + int i, index; if (!s->files) { int dsize = sizeof(uint32_t) + sizeof(FWCfgFile) * FW_CFG_FILE_SLOTS; @@ -300,13 +300,17 @@ int fw_cfg_add_file(FWCfgState *s, const char *dir, const char *filename, } else { basename = filename; } - if (dir) { - snprintf(s->files->f[index].name, sizeof(s->files->f[index].name), - "%s/%s", dir, basename); - } else { - snprintf(s->files->f[index].name, sizeof(s->files->f[index].name), - "%s", basename); + + snprintf(s->files->f[index].name, sizeof(s->files->f[index].name), + "%s/%s", dir, basename); + for (i = 0; i < index; i++) { + if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) { + FW_CFG_DPRINTF("%s: skip duplicate: %s\n", __FUNCTION__, + s->files->f[index].name); + return 1; + } } + s->files->f[index].size = cpu_to_be32(len); s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index); FW_CFG_DPRINTF("%s: #%d: %s (%d bytes)\n", __FUNCTION__,