All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 11/22] hw/i386/pc.c: Don't use load_image()
Date: Fri, 14 Dec 2018 14:42:03 +0000	[thread overview]
Message-ID: <20181214144214.1260-12-peter.maydell@linaro.org> (raw)
In-Reply-To: <20181214144214.1260-1-peter.maydell@linaro.org>

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 <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20181130151712.2312-6-peter.maydell@linaro.org
---
 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 4cd2fbca4d5..115bc2825ce 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 = 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 = 0;
     FILE *f;
     char *vmode;
@@ -965,27 +964,30 @@ static void load_linux(PCMachineState *pcms,
 
     /* load initrd */
     if (initrd_filename) {
+        gsize initrd_size;
+        gchar *initrd_data;
+        GError *gerr = NULL;
+
         if (protocol < 0x200) {
             fprintf(stderr, "qemu: linux kernel too old to load a ram disk\n");
             exit(1);
         }
 
-        initrd_size = 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 >= initrd_max) {
+        }
+        if (initrd_size >= initrd_max) {
             fprintf(stderr, "qemu: initrd is too large, cannot support."
-                    "(max: %"PRIu32", need %"PRId64")\n", initrd_max, initrd_size);
+                    "(max: %"PRIu32", need %"PRId64")\n",
+                    initrd_max, (uint64_t)initrd_size);
             exit(1);
         }
 
         initrd_addr = (initrd_max-initrd_size) & ~4095;
 
-        initrd_data = 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_size);
-- 
2.19.2

  parent reply	other threads:[~2018-12-14 14:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-14 14:41 [Qemu-devel] [PULL 00/22] misc queue Peter Maydell
2018-12-14 14:41 ` [Qemu-devel] [PULL 01/22] scripts/checkpatch.pl: Enforce multiline comment syntax Peter Maydell
2018-12-14 14:41 ` [Qemu-devel] [PULL 02/22] exec.c: Rename cpu_physical_memory_write_rom_internal() Peter Maydell
2018-12-14 14:41 ` [Qemu-devel] [PULL 03/22] Rename cpu_physical_memory_write_rom() to address_space_write_rom() Peter Maydell
2018-12-14 14:41 ` [Qemu-devel] [PULL 04/22] disas.c: Use address_space_read() to read memory Peter Maydell
2018-12-14 14:41 ` [Qemu-devel] [PULL 05/22] monitor: " Peter Maydell
2018-12-14 14:41 ` [Qemu-devel] [PULL 06/22] elf_ops.h: Use address_space_write() to write memory Peter Maydell
2018-12-14 14:41 ` [Qemu-devel] [PULL 07/22] hw/ppc/mac_newworld, mac_oldworld: Don't use load_image() Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 08/22] hw/ppc/ppc405_boards: " Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 09/22] hw/smbios/smbios.c: " Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 10/22] hw/pci/pci.c: " Peter Maydell
2018-12-14 14:42 ` Peter Maydell [this message]
2018-12-14 14:42 ` [Qemu-devel] [PULL 12/22] hw/i386/multiboot.c: " Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 13/22] hw/block/tc58128.c: " Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 14/22] device_tree.c: " Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 15/22] hw/core/loader.c: Remove load_image() Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 16/22] include/hw/loader.h: Document load_image_size() Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 17/22] target/arm: Free name string in ARMCPRegInfo hashtable entries Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 18/22] hw/arm/mps2-tz.c: Free mscname string in make_dma() Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 19/22] hw/sd/sdhci: Don't leak memory region in sdhci_sysbus_realize() Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 20/22] tests/test-arm-mptimer: Don't leak string memory Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 21/22] target/arm: Create timers in realize, not init Peter Maydell
2018-12-14 14:42 ` [Qemu-devel] [PULL 22/22] virt: Fix broken indentation Peter Maydell
2018-12-16 21:48 ` [Qemu-devel] [PULL 00/22] misc queue Peter Maydell
2018-12-16 21:49 ` Peter Maydell
2018-12-23  7:58 ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181214144214.1260-12-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.