qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Daniel Henrique Barboza <danielhb413@gmail.com>
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, clg@kaod.org
Subject: Re: [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init()
Date: Tue, 1 Mar 2022 13:24:19 +1100	[thread overview]
Message-ID: <Yh2D0wofGDJlxpHd@yekko> (raw)
In-Reply-To: <20220228175004.8862-3-danielhb413@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3035 bytes --]

On Mon, Feb 28, 2022 at 02:49:52PM -0300, Daniel Henrique Barboza wrote:
> The firmware check consists on a file search (qemu_find_file) and load
> it via load_imag_targphys(). This validation is not dependent on any
> other machine state but it currently being done at the end of
> spapr_machine_init(). This means that we can do a lot of stuff and end
> up failing at the end for something that we can verify right out of the
> gate.
> 
> Move this validation to the start of spapr_machine_init() to fail
> earlier.  While we're at it, use g_autofree in the 'filename' pointer.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  hw/ppc/spapr.c | 24 +++++++++++-------------
>  1 file changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index c74543ace3..4cc204f90d 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -2707,15 +2707,25 @@ static void spapr_machine_init(MachineState *machine)
>      MachineClass *mc = MACHINE_GET_CLASS(machine);
>      const char *bios_default = spapr->vof ? FW_FILE_NAME_VOF : FW_FILE_NAME;
>      const char *bios_name = machine->firmware ?: bios_default;
> +    g_autofree char *filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
>      const char *kernel_filename = machine->kernel_filename;
>      const char *initrd_filename = machine->initrd_filename;
>      PCIHostState *phb;
>      int i;
>      MemoryRegion *sysmem = get_system_memory();
>      long load_limit, fw_size;
> -    char *filename;
>      Error *resize_hpt_err = NULL;
>  
> +    if (!filename) {
> +        error_report("Could not find LPAR firmware '%s'", bios_name);
> +        exit(1);
> +    }
> +    fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE);
> +    if (fw_size <= 0) {
> +        error_report("Could not load LPAR firmware '%s'", filename);
> +        exit(1);
> +    }
> +
>      /*
>       * if Secure VM (PEF) support is configured, then initialize it
>       */
> @@ -2996,18 +3006,6 @@ static void spapr_machine_init(MachineState *machine)
>          }
>      }
>  
> -    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
> -    if (!filename) {
> -        error_report("Could not find LPAR firmware '%s'", bios_name);
> -        exit(1);
> -    }
> -    fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE);
> -    if (fw_size <= 0) {
> -        error_report("Could not load LPAR firmware '%s'", filename);
> -        exit(1);
> -    }
> -    g_free(filename);
> -
>      /* FIXME: Should register things through the MachineState's qdev
>       * interface, this is a legacy from the sPAPREnvironment structure
>       * which predated MachineState but had a similar function */

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2022-03-01  3:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-28 17:49 [PATCH 00/14] simple cleanups in spapr files Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 01/14] hw/ppc/spapr.c: use g_autofree in spapr_dt_chosen() Daniel Henrique Barboza
2022-03-01  0:58   ` David Gibson
2022-02-28 17:49 ` [PATCH 02/14] hw/ppc/spapr.c: fail early if no firmware found in machine_init() Daniel Henrique Barboza
2022-02-28 19:28   ` BALATON Zoltan
2022-03-01  2:24   ` David Gibson [this message]
2022-02-28 17:49 ` [PATCH 03/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_set_string() Daniel Henrique Barboza
2022-03-01  3:14   ` David Gibson
2022-02-28 17:49 ` [PATCH 04/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_cap_get_string() Daniel Henrique Barboza
2022-03-01  3:15   ` David Gibson
2022-02-28 17:49 ` [PATCH 05/14] hw/ppc/spapr_caps.c: use g_autofree in spapr_caps_add_properties() Daniel Henrique Barboza
2022-03-01  3:15   ` David Gibson
2022-02-28 17:49 ` [PATCH 06/14] hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc() Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 07/14] hw/ppc/spapr_drc.c: use g_autofree in drc_realize() Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 08/14] hw/ppc/spapr_drc.c: use g_autofree in drc_unrealize() Daniel Henrique Barboza
2022-02-28 17:49 ` [PATCH 09/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_dr_connector_new() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 10/14] hw/ppc/spapr_drc.c: use g_autofree in spapr_drc_by_index() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 11/14] hw/ppc/spapr_numa.c: simplify spapr_numa_write_assoc_lookup_arrays() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 12/14] spapr_pci_nvlink2.c: use g_autofree in spapr_phb_nvgpu_ram_populate_dt() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 13/14] hw/ppc/spapr_rtas.c: use g_autofree in rtas_ibm_get_system_parameter() Daniel Henrique Barboza
2022-02-28 17:50 ` [PATCH 14/14] hw/ppc/spapr_vio.c: use g_autofree in spapr_dt_vdevice() Daniel Henrique Barboza
2022-02-28 18:13 ` [PATCH 00/14] simple cleanups in spapr files Philippe Mathieu-Daudé

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=Yh2D0wofGDJlxpHd@yekko \
    --to=david@gibson.dropbear.id.au \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).