From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Gerd Hoffmann 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> Subject: [Qemu-devel] [PATCH 3/6] fw_cfg: rom loader tweaks. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann 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__, -- 1.6.5.2