From nobody Fri Dec 19 20:11:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543591914171776.9857470690093; Fri, 30 Nov 2018 07:31:54 -0800 (PST) Received: from localhost ([::1]:33327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSklg-0003bo-SY for importer@patchew.org; Fri, 30 Nov 2018 10:31:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSkXw-0004ih-Cd for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:17:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSkXv-0005Xo-CE for qemu-devel@nongnu.org; Fri, 30 Nov 2018 10:17:36 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:53050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSkXv-0005Wz-36; Fri, 30 Nov 2018 10:17:35 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gSkXb-0005Pq-Us; Fri, 30 Nov 2018 15:17:15 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2018 15:17:07 +0000 Message-Id: <20181130151712.2312-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130151712.2312-1-peter.maydell@linaro.org> References: <20181130151712.2312-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 05/10] hw/i386/pc.c: Don't use load_image() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-ppc@nongnu.org, Li Zhijian , patches@linaro.org, Peter Crosthwaite , Alexander Graf , Max Reitz , Philip Li , "Michael S. Tsirkin" , Stefan Hajnoczi , Igor Mammedov , qemu-block@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The load_image() function is deprecated, as it does not let the caller specify how large the buffer to read the file into is. Use the glib g_file_get_contents() function instead, which does the whole "allocate memory for the file and read it in" operation. Signed-off-by: Peter Maydell Reviewed-by: Eric Blake --- hw/i386/pc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f095725dbab..067d23a992a 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -839,10 +839,9 @@ static void load_linux(PCMachineState *pcms, { uint16_t protocol; int setup_size, kernel_size, cmdline_size; - int64_t initrd_size =3D 0; int dtb_size, setup_data_offset; uint32_t initrd_max; - uint8_t header[8192], *setup, *kernel, *initrd_data; + uint8_t header[8192], *setup, *kernel; hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr =3D 0; FILE *f; char *vmode; @@ -965,27 +964,30 @@ static void load_linux(PCMachineState *pcms, =20 /* load initrd */ if (initrd_filename) { + gsize initrd_size; + gchar *initrd_data; + GError *gerr =3D NULL; + if (protocol < 0x200) { fprintf(stderr, "qemu: linux kernel too old to load a ram disk= \n"); exit(1); } =20 - initrd_size =3D get_image_size(initrd_filename); - if (initrd_size < 0) { + if (!g_file_get_contents(initrd_filename, &initrd_data, + &initrd_size, &gerr)) { fprintf(stderr, "qemu: error reading initrd %s: %s\n", - initrd_filename, strerror(errno)); + initrd_filename, gerr->message); exit(1); - } else if (initrd_size >=3D initrd_max) { + } + if (initrd_size >=3D initrd_max) { fprintf(stderr, "qemu: initrd is too large, cannot support." - "(max: %"PRIu32", need %"PRId64")\n", initrd_max, init= rd_size); + "(max: %"PRIu32", need %"PRId64")\n", + initrd_max, initrd_size); exit(1); } =20 initrd_addr =3D (initrd_max-initrd_size) & ~4095; =20 - initrd_data =3D g_malloc(initrd_size); - load_image(initrd_filename, initrd_data); - fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_s= ize); --=20 2.19.1