[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/14] mac_{old|new}world: Avoid else branch by setting default va
From: |
Mark Cave-Ayland |
Subject: |
[PULL 04/14] mac_{old|new}world: Avoid else branch by setting default value |
Date: |
Mon, 31 Oct 2022 20:14:25 +0000 |
From: BALATON Zoltan <balaton@eik.bme.hu>
Several variables are set in if-else branches where the else branch
can be removed by setting a default value at the variable declaration
which leads to simlpler code that is easier to follow.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id:
<8dac3515b29976a61dacda07752175d7531dca3c.1666957578.git.balaton@eik.bme.hu>
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
hw/ppc/mac_newworld.c | 19 ++++---------------
hw/ppc/mac_oldworld.c | 18 ++++--------------
2 files changed, 8 insertions(+), 29 deletions(-)
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index 6327694f85..6bc3bd19be 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -111,11 +111,11 @@ static void ppc_core99_init(MachineState *machine)
CPUPPCState *env = NULL;
char *filename;
IrqLines *openpic_irqs;
- int i, j, k, ppc_boot_device, machine_arch, bios_size;
+ int i, j, k, ppc_boot_device, machine_arch, bios_size = -1;
const char *bios_name = machine->firmware ?: PROM_FILENAME;
MemoryRegion *bios = g_new(MemoryRegion, 1);
- hwaddr kernel_base, initrd_base, cmdline_base = 0;
- long kernel_size, initrd_size;
+ hwaddr kernel_base = 0, initrd_base = 0, cmdline_base = 0;
+ long kernel_size = 0, initrd_size = 0;
UNINHostState *uninorth_pci;
PCIBus *pci_bus;
PCIDevice *macio;
@@ -165,8 +165,6 @@ static void ppc_core99_init(MachineState *machine)
bios_size = load_image_targphys(filename, PROM_BASE, PROM_SIZE);
}
g_free(filename);
- } else {
- bios_size = -1;
}
if (bios_size < 0 || bios_size > PROM_SIZE) {
error_report("could not load PowerPC bios '%s'", bios_name);
@@ -174,15 +172,12 @@ static void ppc_core99_init(MachineState *machine)
}
if (machine->kernel_filename) {
- int bswap_needed;
+ int bswap_needed = 0;
#ifdef BSWAP_NEEDED
bswap_needed = 1;
-#else
- bswap_needed = 0;
#endif
kernel_base = KERNEL_LOAD_ADDR;
-
kernel_size = load_elf(machine->kernel_filename, NULL,
translate_kernel_address, NULL, NULL, NULL,
NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
@@ -212,16 +207,10 @@ static void ppc_core99_init(MachineState *machine)
}
cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
} else {
- initrd_base = 0;
- initrd_size = 0;
cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size +
KERNEL_GAP);
}
ppc_boot_device = 'm';
} else {
- kernel_base = 0;
- kernel_size = 0;
- initrd_base = 0;
- initrd_size = 0;
ppc_boot_device = '\0';
/* We consider that NewWorld PowerMac never have any floppy drive
* For now, OHW cannot boot from the network.
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 5cabc410e7..cb67e44081 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -84,11 +84,11 @@ static void ppc_heathrow_init(MachineState *machine)
PowerPCCPU *cpu = NULL;
CPUPPCState *env = NULL;
char *filename;
- int i, bios_size;
+ int i, bios_size = -1;
MemoryRegion *bios = g_new(MemoryRegion, 1);
uint64_t bios_addr;
- uint32_t kernel_base, initrd_base, cmdline_base = 0;
- int32_t kernel_size, initrd_size;
+ uint32_t kernel_base = 0, initrd_base = 0, cmdline_base = 0;
+ int32_t kernel_size = 0, initrd_size = 0;
PCIBus *pci_bus;
PCIDevice *macio;
MACIOIDEState *macio_ide;
@@ -139,8 +139,6 @@ static void ppc_heathrow_init(MachineState *machine)
bios_addr = PROM_BASE;
}
g_free(filename);
- } else {
- bios_size = -1;
}
if (bios_size < 0 || bios_addr - PROM_BASE + bios_size > PROM_SIZE) {
error_report("could not load PowerPC bios '%s'", bios_name);
@@ -148,12 +146,10 @@ static void ppc_heathrow_init(MachineState *machine)
}
if (machine->kernel_filename) {
- int bswap_needed;
+ int bswap_needed = 0;
#ifdef BSWAP_NEEDED
bswap_needed = 1;
-#else
- bswap_needed = 0;
#endif
kernel_base = KERNEL_LOAD_ADDR;
kernel_size = load_elf(machine->kernel_filename, NULL,
@@ -186,16 +182,10 @@ static void ppc_heathrow_init(MachineState *machine)
}
cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
} else {
- initrd_base = 0;
- initrd_size = 0;
cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size +
KERNEL_GAP);
}
ppc_boot_device = 'm';
} else {
- kernel_base = 0;
- kernel_size = 0;
- initrd_base = 0;
- initrd_size = 0;
ppc_boot_device = '\0';
for (i = 0; machine->boot_config.order[i] != '\0'; i++) {
/*
--
2.30.2
- [PULL 00/14] qemu-macppc queue 20221031, Mark Cave-Ayland, 2022/10/31
- [PULL 01/14] mac_newworld: Drop some variables, Mark Cave-Ayland, 2022/10/31
- [PULL 02/14] mac_oldworld: Drop some more variables, Mark Cave-Ayland, 2022/10/31
- [PULL 04/14] mac_{old|new}world: Avoid else branch by setting default value,
Mark Cave-Ayland <=
- [PULL 05/14] mac_newworld: Clean up creation of Uninorth devices, Mark Cave-Ayland, 2022/10/31
- [PULL 03/14] mac_{old|new}world: Set tbfreq at declaration, Mark Cave-Ayland, 2022/10/31
- [PULL 06/14] mac_{old|new}world: Reduce number of QOM casts, Mark Cave-Ayland, 2022/10/31
- [PULL 07/14] hw/ppc/mac.h: Move newworld specific parts out from shared header, Mark Cave-Ayland, 2022/10/31
- [PULL 08/14] hw/ppc/mac.h: Move macio specific parts out from shared header, Mark Cave-Ayland, 2022/10/31
- [PULL 09/14] hw/ppc/mac.h: Move grackle-pcihost type declaration out to a header, Mark Cave-Ayland, 2022/10/31
- [PULL 10/14] hw/ppc/mac.h: Move PROM and KERNEL defines to board code, Mark Cave-Ayland, 2022/10/31
- [PULL 12/14] mac_nvram: Use NVRAM_SIZE constant, Mark Cave-Ayland, 2022/10/31
- [PULL 11/14] hw/ppc/mac.h: Rename to include/hw/nvram/mac_nvram.h, Mark Cave-Ayland, 2022/10/31
- [PULL 13/14] mac_{old|new}world: Code style fix adding missing braces to if-s, Mark Cave-Ayland, 2022/10/31