From patchwork Fri Nov 30 15:17:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 152562 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3787008ljp; Fri, 30 Nov 2018 07:24:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/W5IdIHSHuRAbFKKJXAQRlJkn7wG19fpIKFhToE/db93Wv8n1LSnhP92rUzQGwUtOu1e9B0 X-Received: by 2002:a1c:88c7:: with SMTP id k190mr5523925wmd.97.1543591452253; Fri, 30 Nov 2018 07:24:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543591452; cv=none; d=google.com; s=arc-20160816; b=zEChUCVPfUhztPL7LAM17O0E50FkrqCQi2742KPV1/tYhgfc1AgbmmPOAS6rZfO536 akzbVFo4BhtBKQZP/emTTNXmOdWHrfAPPKJjX1ftEQ0SmULk/HQIaTA1shAiA3lwtoee oUrHQRuNAU6c27wBj7GrSA2BRNo+6ICRZyJydIcQ/fuDWScq2zmUqX9JdGR+m9UwShS0 U9bkVnzjST4UQ7FscY8AnLdeq3KiOfy8JhxnSeF32q7Cjm8dfNrwiGIrGduMdYNq/5xG QeH6akZEr9kwnNZX5qUN4rzcthS9baDfVWv78fkPX9k9M9AgmkEb9d1el8kg0d9P2LYv csNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=XkBbkLiwentOsJk1bho8mj47IzLUpNrMrfQelrLtJRo=; b=mKvXqhLkLBJp87qRJf3Eve8SrzZL7jFiQh6bats/NfaNgAY1UrG4HA9+yYGNccga5x EtPeIV0KJrXXSDxjW054y6qNbtC7u4r1bxT7aVCyrrDGeCqLn1FoMriY0FeOUVJ2vqhF kuajF3BOm42D8HviWVRBLKFnjc0N0reJHSEPul9kq0Wv915WFq5uvZq1L9gumQZWq+QH kQZbrEvqFACnvH4bCKJMd0m4OgP7ZyFIjyK83MyXr1MSYPpRdzM5v9eOfigdqsTdqWSL MmRc7AwJ6/3jwFC2rIXWKcx5vxPR3IfjyEHsQEvDJgVZ/EOtf4JOJGLwxWl4sphtIZBV V8Rg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id j27si4680235wre.73.2018.11.30.07.24.12 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Nov 2018 07:24:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 Cc: patches@linaro.org, Stefan Hajnoczi , Eric Blake , "Daniel P . Berrange" , Li Zhijian , Philip Li , Peter Crosthwaite , Alexander Graf , Kevin Wolf , Max Reitz , "Michael S. Tsirkin" , Marcel Apfelbaum , David Gibson , Igor Mammedov , qemu-block@nongnu.org, qemu-ppc@nongnu.org Subject: [PATCH 05/10] hw/i386/pc.c: Don't use load_image() 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 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 --- hw/i386/pc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) -- 2.19.1 Reviewed-by: Eric Blake 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 = 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, 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);