All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/2] register queue
@ 2020-09-27 13:46 Alistair Francis
  2020-09-27 13:46 ` [PULL 1/2] load_elf: Remove unused address variables from callers Alistair Francis
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Alistair Francis @ 2020-09-27 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: alistair23, Alistair Francis

The following changes since commit 8d16e72f2d4df2c9e631393adf1669a1da7efe8a:

  Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20200925a' into staging (2020-09-25 14:46:18 +0100)

are available in the Git repository at:

  git@github.com:alistair23/qemu.git tags/pull-register-20200927

for you to fetch changes up to e8a612b7e3cdbdface1e34a27300ca2f8521dee0:

  core/register: Specify instance_size in the TypeInfo (2020-09-25 16:52:24 -0700)

----------------------------------------------------------------
Two small patches. One with a fix for the register API instance_size
and one for removing unused address variables from load_elf.

----------------------------------------------------------------
Alistair Francis (1):
      core/register: Specify instance_size in the TypeInfo

BALATON Zoltan (1):
      load_elf: Remove unused address variables from callers

 hw/alpha/dp264.c       |  8 ++++----
 hw/arm/armv7m.c        |  4 +---
 hw/core/register.c     | 31 +++++++++++++------------------
 hw/cris/boot.c         |  4 ++--
 hw/microblaze/boot.c   |  4 ++--
 hw/mips/fuloong2e.c    |  8 ++++----
 hw/moxie/moxiesim.c    |  4 ++--
 hw/nios2/boot.c        |  4 ++--
 hw/ppc/mac_newworld.c  |  6 ++----
 hw/ppc/mac_oldworld.c  |  6 ++----
 hw/ppc/ppc440_bamboo.c |  9 +++------
 hw/ppc/sam460ex.c      | 12 +++++-------
 hw/ppc/spapr.c         | 11 ++++-------
 hw/ppc/virtex_ml507.c  |  4 ++--
 hw/riscv/boot.c        |  8 ++++----
 hw/xtensa/sim.c        |  3 +--
 hw/xtensa/xtfpga.c     |  3 +--
 17 files changed, 54 insertions(+), 75 deletions(-)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PULL 1/2] load_elf: Remove unused address variables from callers
  2020-09-27 13:46 [PULL 0/2] register queue Alistair Francis
@ 2020-09-27 13:46 ` Alistair Francis
  2020-09-27 13:46 ` [PULL 2/2] core/register: Specify instance_size in the TypeInfo Alistair Francis
  2020-09-28 18:31 ` [PULL 0/2] register queue Peter Maydell
  2 siblings, 0 replies; 9+ messages in thread
From: Alistair Francis @ 2020-09-27 13:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Max Filippov, alistair23, David Gibson, Alistair Francis

From: BALATON Zoltan <balaton@eik.bme.hu>

Several callers of load_elf() pass pointers for lowaddr and highaddr
parameters which are then not used for anything. This may stem from a
misunderstanding that load_elf need a value here but in fact it can
take NULL to ignore these values. Remove such unused variables and
pass NULL instead from callers that don't need these.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Message-Id: <20200705174020.BDD0174633F@zero.eik.bme.hu>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 hw/alpha/dp264.c       |  8 ++++----
 hw/arm/armv7m.c        |  4 +---
 hw/cris/boot.c         |  4 ++--
 hw/microblaze/boot.c   |  4 ++--
 hw/mips/fuloong2e.c    |  8 ++++----
 hw/moxie/moxiesim.c    |  4 ++--
 hw/nios2/boot.c        |  4 ++--
 hw/ppc/mac_newworld.c  |  6 ++----
 hw/ppc/mac_oldworld.c  |  6 ++----
 hw/ppc/ppc440_bamboo.c |  9 +++------
 hw/ppc/sam460ex.c      | 12 +++++-------
 hw/ppc/spapr.c         | 11 ++++-------
 hw/ppc/virtex_ml507.c  |  4 ++--
 hw/riscv/boot.c        |  8 ++++----
 hw/xtensa/sim.c        |  3 +--
 hw/xtensa/xtfpga.c     |  3 +--
 16 files changed, 41 insertions(+), 57 deletions(-)

diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index f7751b18f6..4d24518d1d 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -62,8 +62,8 @@ static void clipper_init(MachineState *machine)
     qemu_irq rtc_irq;
     long size, i;
     char *palcode_filename;
-    uint64_t palcode_entry, palcode_low, palcode_high;
-    uint64_t kernel_entry, kernel_low, kernel_high;
+    uint64_t palcode_entry;
+    uint64_t kernel_entry, kernel_low;
     unsigned int smp_cpus = machine->smp.cpus;
 
     /* Create up to 4 cpus.  */
@@ -113,7 +113,7 @@ static void clipper_init(MachineState *machine)
         exit(1);
     }
     size = load_elf(palcode_filename, NULL, cpu_alpha_superpage_to_phys,
-                    NULL, &palcode_entry, &palcode_low, &palcode_high, NULL,
+                    NULL, &palcode_entry, NULL, NULL, NULL,
                     0, EM_ALPHA, 0, 0);
     if (size < 0) {
         error_report("could not load palcode '%s'", palcode_filename);
@@ -132,7 +132,7 @@ static void clipper_init(MachineState *machine)
         uint64_t param_offset;
 
         size = load_elf(kernel_filename, NULL, cpu_alpha_superpage_to_phys,
-                        NULL, &kernel_entry, &kernel_low, &kernel_high, NULL,
+                        NULL, &kernel_entry, &kernel_low, NULL, NULL,
                         0, EM_ALPHA, 0, 0);
         if (size < 0) {
             error_report("could not load kernel '%s'", kernel_filename);
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
index 0e5997d333..8113b29f1f 100644
--- a/hw/arm/armv7m.c
+++ b/hw/arm/armv7m.c
@@ -292,7 +292,6 @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
 {
     int image_size;
     uint64_t entry;
-    uint64_t lowaddr;
     int big_endian;
     AddressSpace *as;
     int asidx;
@@ -313,12 +312,11 @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
 
     if (kernel_filename) {
         image_size = load_elf_as(kernel_filename, NULL, NULL, NULL,
-                                 &entry, &lowaddr, NULL,
+                                 &entry, NULL, NULL,
                                  NULL, big_endian, EM_ARM, 1, 0, as);
         if (image_size < 0) {
             image_size = load_image_targphys_as(kernel_filename, 0,
                                                 mem_size, as);
-            lowaddr = 0;
         }
         if (image_size < 0) {
             error_report("Could not load kernel '%s'", kernel_filename);
diff --git a/hw/cris/boot.c b/hw/cris/boot.c
index b8947bc660..aa8d2756d6 100644
--- a/hw/cris/boot.c
+++ b/hw/cris/boot.c
@@ -67,7 +67,7 @@ static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
 void cris_load_image(CRISCPU *cpu, struct cris_load_info *li)
 {
     CPUCRISState *env = &cpu->env;
-    uint64_t entry, high;
+    uint64_t entry;
     int kcmdline_len;
     int image_size;
 
@@ -76,7 +76,7 @@ void cris_load_image(CRISCPU *cpu, struct cris_load_info *li)
        devboard SDK.  */
     image_size = load_elf(li->image_filename, NULL,
                           translate_kernel_address, NULL,
-                          &entry, NULL, &high, NULL, 0, EM_CRIS, 0, 0);
+                          &entry, NULL, NULL, NULL, 0, EM_CRIS, 0, 0);
     li->entry = entry;
     if (image_size < 0) {
         /* Takes a kimage from the axis devboard SDK.  */
diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c
index 925e3f7c9d..8ad3c27f2c 100644
--- a/hw/microblaze/boot.c
+++ b/hw/microblaze/boot.c
@@ -135,7 +135,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,
 
     if (kernel_filename) {
         int kernel_size;
-        uint64_t entry, low, high;
+        uint64_t entry, high;
         uint32_t base32;
         int big_endian = 0;
 
@@ -145,7 +145,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,
 
         /* Boots a kernel elf binary.  */
         kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
-                               &entry, &low, &high, NULL,
+                               &entry, NULL, &high, NULL,
                                big_endian, EM_MICROBLAZE, 0, 0);
         base32 = entry;
         if (base32 == 0xc0000000) {
diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
index f28609976b..b000ed1d7f 100644
--- a/hw/mips/fuloong2e.c
+++ b/hw/mips/fuloong2e.c
@@ -107,7 +107,7 @@ static void GCC_FMT_ATTR(3, 4) prom_set(uint32_t *prom_buf, int index,
 
 static int64_t load_kernel(CPUMIPSState *env)
 {
-    int64_t kernel_entry, kernel_low, kernel_high, initrd_size;
+    int64_t kernel_entry, kernel_high, initrd_size;
     int index = 0;
     long kernel_size;
     ram_addr_t initrd_offset;
@@ -116,9 +116,9 @@ static int64_t load_kernel(CPUMIPSState *env)
 
     kernel_size = load_elf(loaderparams.kernel_filename, NULL,
                            cpu_mips_kseg0_to_phys, NULL,
-                           (uint64_t *)&kernel_entry,
-                           (uint64_t *)&kernel_low, (uint64_t *)&kernel_high,
-                           NULL, 0, EM_MIPS, 1, 0);
+                           (uint64_t *)&kernel_entry, NULL,
+                           (uint64_t *)&kernel_high, NULL,
+                           0, EM_MIPS, 1, 0);
     if (kernel_size < 0) {
         error_report("could not load kernel '%s': %s",
                      loaderparams.kernel_filename,
diff --git a/hw/moxie/moxiesim.c b/hw/moxie/moxiesim.c
index 51a98287b5..a765e9f6be 100644
--- a/hw/moxie/moxiesim.c
+++ b/hw/moxie/moxiesim.c
@@ -52,13 +52,13 @@ typedef struct {
 
 static void load_kernel(MoxieCPU *cpu, LoaderParams *loader_params)
 {
-    uint64_t entry, kernel_low, kernel_high;
+    uint64_t entry, kernel_high;
     int64_t initrd_size;
     long kernel_size;
     ram_addr_t initrd_offset;
 
     kernel_size = load_elf(loader_params->kernel_filename,  NULL, NULL, NULL,
-                           &entry, &kernel_low, &kernel_high, NULL, 1, EM_MOXIE,
+                           &entry, NULL, &kernel_high, NULL, 1, EM_MOXIE,
                            0, 0);
 
     if (kernel_size <= 0) {
diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c
index 88224aa84c..1df3b66c29 100644
--- a/hw/nios2/boot.c
+++ b/hw/nios2/boot.c
@@ -139,7 +139,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
 
     if (kernel_filename) {
         int kernel_size, fdt_size;
-        uint64_t entry, low, high;
+        uint64_t entry, high;
         int big_endian = 0;
 
 #ifdef TARGET_WORDS_BIGENDIAN
@@ -148,7 +148,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
 
         /* Boots a kernel elf binary. */
         kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
-                               &entry, &low, &high, NULL,
+                               &entry, NULL, &high, NULL,
                                big_endian, EM_ALTERA_NIOS2, 0, 0);
         if ((uint32_t)entry == 0xc0000000) {
             /*
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index e42bd7a626..4dfbeec0ca 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -177,7 +177,6 @@ static void ppc_core99_init(MachineState *machine)
     }
 
     if (linux_boot) {
-        uint64_t lowaddr = 0;
         int bswap_needed;
 
 #ifdef BSWAP_NEEDED
@@ -188,9 +187,8 @@ static void ppc_core99_init(MachineState *machine)
         kernel_base = KERNEL_LOAD_ADDR;
 
         kernel_size = load_elf(kernel_filename, NULL,
-                               translate_kernel_address, NULL,
-                               NULL, &lowaddr, NULL, NULL, 1, PPC_ELF_MACHINE,
-                               0, 0);
+                               translate_kernel_address, NULL, NULL, NULL,
+                               NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
         if (kernel_size < 0)
             kernel_size = load_aout(kernel_filename, kernel_base,
                                     ram_size - kernel_base, bswap_needed,
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 7aba040f1b..f8173934a2 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -150,7 +150,6 @@ static void ppc_heathrow_init(MachineState *machine)
     }
 
     if (linux_boot) {
-        uint64_t lowaddr = 0;
         int bswap_needed;
 
 #ifdef BSWAP_NEEDED
@@ -160,9 +159,8 @@ static void ppc_heathrow_init(MachineState *machine)
 #endif
         kernel_base = KERNEL_LOAD_ADDR;
         kernel_size = load_elf(kernel_filename, NULL,
-                               translate_kernel_address, NULL,
-                               NULL, &lowaddr, NULL, NULL, 1, PPC_ELF_MACHINE,
-                               0, 0);
+                               translate_kernel_address, NULL, NULL, NULL,
+                               NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
         if (kernel_size < 0)
             kernel_size = load_aout(kernel_filename, kernel_base,
                                     ram_size - kernel_base, bswap_needed,
diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c
index 4c5e9e4373..74028dc986 100644
--- a/hw/ppc/ppc440_bamboo.c
+++ b/hw/ppc/ppc440_bamboo.c
@@ -172,9 +172,6 @@ static void bamboo_init(MachineState *machine)
     PCIBus *pcibus;
     PowerPCCPU *cpu;
     CPUPPCState *env;
-    uint64_t elf_entry;
-    uint64_t elf_lowaddr;
-    hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID;
     target_long initrd_size = 0;
     DeviceState *dev;
     int success;
@@ -246,14 +243,14 @@ static void bamboo_init(MachineState *machine)
 
     /* Load kernel. */
     if (kernel_filename) {
+        hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID;
         success = load_uimage(kernel_filename, &entry, &loadaddr, NULL,
                               NULL, NULL);
         if (success < 0) {
+            uint64_t elf_entry;
             success = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
-                               &elf_lowaddr, NULL, NULL, 1, PPC_ELF_MACHINE,
-                               0, 0);
+                               NULL, NULL, NULL, 1, PPC_ELF_MACHINE, 0, 0);
             entry = elf_entry;
-            loadaddr = elf_lowaddr;
         }
         /* XXX try again as binary */
         if (success < 0) {
diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
index 1702344c46..7e59a91981 100644
--- a/hw/ppc/sam460ex.c
+++ b/hw/ppc/sam460ex.c
@@ -286,7 +286,6 @@ static void sam460ex_init(MachineState *machine)
     CPUPPCState *env;
     I2CBus *i2c;
     hwaddr entry = UBOOT_ENTRY;
-    hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID;
     target_long initrd_size = 0;
     DeviceState *dev;
     SysBusDevice *sbdev;
@@ -426,17 +425,16 @@ static void sam460ex_init(MachineState *machine)
 
     /* Load kernel. */
     if (machine->kernel_filename) {
+        hwaddr loadaddr = LOAD_UIMAGE_LOADADDR_INVALID;
         success = load_uimage(machine->kernel_filename, &entry, &loadaddr,
                               NULL, NULL, NULL);
         if (success < 0) {
-            uint64_t elf_entry, elf_lowaddr;
+            uint64_t elf_entry;
 
-            success = load_elf(machine->kernel_filename, NULL,
-                               NULL, NULL, &elf_entry,
-                               &elf_lowaddr, NULL, NULL, 1, PPC_ELF_MACHINE, 0,
-                               0);
+            success = load_elf(machine->kernel_filename, NULL, NULL, NULL,
+                               &elf_entry, NULL, NULL, NULL,
+                               1, PPC_ELF_MACHINE, 0, 0);
             entry = elf_entry;
-            loadaddr = elf_lowaddr;
         }
         /* XXX try again as binary */
         if (success < 0) {
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 9bce1892b5..cbcd93b406 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2919,18 +2919,15 @@ static void spapr_machine_init(MachineState *machine)
     }
 
     if (kernel_filename) {
-        uint64_t lowaddr = 0;
-
         spapr->kernel_size = load_elf(kernel_filename, NULL,
                                       translate_kernel_address, spapr,
-                                      NULL, &lowaddr, NULL, NULL, 1,
+                                      NULL, NULL, NULL, NULL, 1,
                                       PPC_ELF_MACHINE, 0, 0);
         if (spapr->kernel_size == ELF_LOAD_WRONG_ENDIAN) {
             spapr->kernel_size = load_elf(kernel_filename, NULL,
-                                          translate_kernel_address, spapr, NULL,
-                                          &lowaddr, NULL, NULL, 0,
-                                          PPC_ELF_MACHINE,
-                                          0, 0);
+                                          translate_kernel_address, spapr,
+                                          NULL, NULL, NULL, NULL, 0,
+                                          PPC_ELF_MACHINE, 0, 0);
             spapr->kernel_le = spapr->kernel_size > 0;
         }
         if (spapr->kernel_size < 0) {
diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index 78c4901be1..c790c1113f 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -250,12 +250,12 @@ static void virtex_init(MachineState *machine)
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[TIMER_IRQ]);
 
     if (kernel_filename) {
-        uint64_t entry, low, high;
+        uint64_t entry, high;
         hwaddr boot_offset;
 
         /* Boots a kernel elf binary.  */
         kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
-                               &entry, &low, &high, NULL, 1, PPC_ELF_MACHINE,
+                               &entry, NULL, &high, NULL, 1, PPC_ELF_MACHINE,
                                0, 0);
         boot_info.bootstrap_pc = entry & 0x00ffffff;
 
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 4c6c101ff1..21adaae56e 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -91,10 +91,10 @@ target_ulong riscv_load_firmware(const char *firmware_filename,
                                  hwaddr firmware_load_addr,
                                  symbol_fn_t sym_cb)
 {
-    uint64_t firmware_entry, firmware_start, firmware_end;
+    uint64_t firmware_entry;
 
     if (load_elf_ram_sym(firmware_filename, NULL, NULL, NULL,
-                         &firmware_entry, &firmware_start, &firmware_end, NULL,
+                         &firmware_entry, NULL, NULL, NULL,
                          0, EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) {
         return firmware_entry;
     }
@@ -110,10 +110,10 @@ target_ulong riscv_load_firmware(const char *firmware_filename,
 
 target_ulong riscv_load_kernel(const char *kernel_filename, symbol_fn_t sym_cb)
 {
-    uint64_t kernel_entry, kernel_high;
+    uint64_t kernel_entry;
 
     if (load_elf_ram_sym(kernel_filename, NULL, NULL, NULL,
-                         &kernel_entry, NULL, &kernel_high, NULL, 0,
+                         &kernel_entry, NULL, NULL, NULL, 0,
                          EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) {
         return kernel_entry;
     }
diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c
index aeb46d86f5..cbac50db2d 100644
--- a/hw/xtensa/sim.c
+++ b/hw/xtensa/sim.c
@@ -106,9 +106,8 @@ void xtensa_sim_load_kernel(XtensaCPU *cpu, MachineState *machine)
 
     if (kernel_filename) {
         uint64_t elf_entry;
-        uint64_t elf_lowaddr;
         int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
-                               &elf_entry, &elf_lowaddr, NULL, NULL, big_endian,
+                               &elf_entry, NULL, NULL, NULL, big_endian,
                                EM_XTENSA, 0, 0);
 
         if (success > 0) {
diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index 10de15855a..b1470b88e6 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -413,9 +413,8 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
         env->regs[2] = tagptr;
 
         uint64_t elf_entry;
-        uint64_t elf_lowaddr;
         int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
-                &elf_entry, &elf_lowaddr, NULL, NULL, be, EM_XTENSA, 0, 0);
+                &elf_entry, NULL, NULL, NULL, be, EM_XTENSA, 0, 0);
         if (success > 0) {
             entry_point = elf_entry;
         } else {
-- 
2.28.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 2/2] core/register: Specify instance_size in the TypeInfo
  2020-09-27 13:46 [PULL 0/2] register queue Alistair Francis
  2020-09-27 13:46 ` [PULL 1/2] load_elf: Remove unused address variables from callers Alistair Francis
@ 2020-09-27 13:46 ` Alistair Francis
  2020-09-29 12:55   ` Peter Maydell
  2020-09-28 18:31 ` [PULL 0/2] register queue Peter Maydell
  2 siblings, 1 reply; 9+ messages in thread
From: Alistair Francis @ 2020-09-27 13:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: alistair23, Alistair Francis, Eduardo Habkost,
	Philippe Mathieu-Daudé

Reported-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <4cf1beb7dafb9143c261d266557d3173bf160524.1598376594.git.alistair.francis@wdc.com>
---
 hw/core/register.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/hw/core/register.c b/hw/core/register.c
index ddf91eb445..31038bd7cc 100644
--- a/hw/core/register.c
+++ b/hw/core/register.c
@@ -176,17 +176,6 @@ void register_reset(RegisterInfo *reg)
     }
 }
 
-void register_init(RegisterInfo *reg)
-{
-    assert(reg);
-
-    if (!reg->data || !reg->access) {
-        return;
-    }
-
-    object_initialize((void *)reg, sizeof(*reg), TYPE_REGISTER);
-}
-
 void register_write_memory(void *opaque, hwaddr addr,
                            uint64_t value, unsigned size)
 {
@@ -269,13 +258,18 @@ static RegisterInfoArray *register_init_block(DeviceState *owner,
         int index = rae[i].addr / data_size;
         RegisterInfo *r = &ri[index];
 
-        *r = (RegisterInfo) {
-            .data = data + data_size * index,
-            .data_size = data_size,
-            .access = &rae[i],
-            .opaque = owner,
-        };
-        register_init(r);
+        if (data + data_size * index == 0 || !&rae[i]) {
+            continue;
+        }
+
+        /* Init the register, this will zero it. */
+        object_initialize((void *)r, sizeof(*r), TYPE_REGISTER);
+
+        /* Set the properties of the register */
+        r->data = data + data_size * index;
+        r->data_size = data_size;
+        r->access = &rae[i];
+        r->opaque = owner;
 
         r_array->r[i] = r;
     }
@@ -329,6 +323,7 @@ static const TypeInfo register_info = {
     .name  = TYPE_REGISTER,
     .parent = TYPE_DEVICE,
     .class_init = register_class_init,
+    .instance_size = sizeof(RegisterInfo),
 };
 
 static void register_register_types(void)
-- 
2.28.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PULL 0/2] register queue
  2020-09-27 13:46 [PULL 0/2] register queue Alistair Francis
  2020-09-27 13:46 ` [PULL 1/2] load_elf: Remove unused address variables from callers Alistair Francis
  2020-09-27 13:46 ` [PULL 2/2] core/register: Specify instance_size in the TypeInfo Alistair Francis
@ 2020-09-28 18:31 ` Peter Maydell
  2 siblings, 0 replies; 9+ messages in thread
From: Peter Maydell @ 2020-09-28 18:31 UTC (permalink / raw)
  To: Alistair Francis; +Cc: Alistair Francis, QEMU Developers

On Sun, 27 Sep 2020 at 14:58, Alistair Francis <alistair.francis@wdc.com> wrote:
>
> The following changes since commit 8d16e72f2d4df2c9e631393adf1669a1da7efe8a:
>
>   Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20200925a' into staging (2020-09-25 14:46:18 +0100)
>
> are available in the Git repository at:
>
>   git@github.com:alistair23/qemu.git tags/pull-register-20200927
>
> for you to fetch changes up to e8a612b7e3cdbdface1e34a27300ca2f8521dee0:
>
>   core/register: Specify instance_size in the TypeInfo (2020-09-25 16:52:24 -0700)
>
> ----------------------------------------------------------------
> Two small patches. One with a fix for the register API instance_size
> and one for removing unused address variables from load_elf.
>
> ----------------------------------------------------------------


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.2
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PULL 2/2] core/register: Specify instance_size in the TypeInfo
  2020-09-27 13:46 ` [PULL 2/2] core/register: Specify instance_size in the TypeInfo Alistair Francis
@ 2020-09-29 12:55   ` Peter Maydell
  2020-09-29 13:22     ` Eduardo Habkost
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2020-09-29 12:55 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Alistair Francis, Philippe Mathieu-Daudé,
	QEMU Developers, Eduardo Habkost

On Sun, 27 Sep 2020 at 15:00, Alistair Francis <alistair.francis@wdc.com> wrote:
>
> Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Message-Id: <4cf1beb7dafb9143c261d266557d3173bf160524.1598376594.git.alistair.francis@wdc.com>
> ---
> @@ -269,13 +258,18 @@ static RegisterInfoArray *register_init_block(DeviceState *owner,
>          int index = rae[i].addr / data_size;
>          RegisterInfo *r = &ri[index];
>
> -        *r = (RegisterInfo) {
> -            .data = data + data_size * index,
> -            .data_size = data_size,
> -            .access = &rae[i],
> -            .opaque = owner,
> -        };
> -        register_init(r);
> +        if (data + data_size * index == 0 || !&rae[i]) {
> +            continue;

Coverity thinks (CID 1432800) that this is dead code, because
"data + data_size * index" can never be NULL[*]. What was this
intending to test for ? (maybe data == NULL? Missing dereference
operator ?)

[*] The C spec is quite strict about what valid pointer arithmetic
is; in particular adding to a NULL pointer is undefined behaviour,
and pointer arithmetic that overflows and wraps around is
undefined behaviour, so there's no way to get a 0 result from
"ptr + offset" without the expression being UB.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PULL 2/2] core/register: Specify instance_size in the TypeInfo
  2020-09-29 12:55   ` Peter Maydell
@ 2020-09-29 13:22     ` Eduardo Habkost
  2020-10-01 15:37       ` Alistair Francis
  0 siblings, 1 reply; 9+ messages in thread
From: Eduardo Habkost @ 2020-09-29 13:22 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Alistair Francis, Alistair Francis, QEMU Developers,
	Philippe Mathieu-Daudé

On Tue, Sep 29, 2020 at 01:55:35PM +0100, Peter Maydell wrote:
> On Sun, 27 Sep 2020 at 15:00, Alistair Francis <alistair.francis@wdc.com> wrote:
> >
> > Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > Message-Id: <4cf1beb7dafb9143c261d266557d3173bf160524.1598376594.git.alistair.francis@wdc.com>
> > ---
> > @@ -269,13 +258,18 @@ static RegisterInfoArray *register_init_block(DeviceState *owner,
> >          int index = rae[i].addr / data_size;
> >          RegisterInfo *r = &ri[index];
> >
> > -        *r = (RegisterInfo) {
> > -            .data = data + data_size * index,
> > -            .data_size = data_size,
> > -            .access = &rae[i],
> > -            .opaque = owner,
> > -        };
> > -        register_init(r);
> > +        if (data + data_size * index == 0 || !&rae[i]) {
> > +            continue;
> 
> Coverity thinks (CID 1432800) that this is dead code, because
> "data + data_size * index" can never be NULL[*]. What was this
> intending to test for ? (maybe data == NULL? Missing dereference
> operator ?)

I believe the original check in the old register_init() function
were just to make the function more flexible by allowing NULL
arguments, but it was always unnecessary.  We have 4 callers of
register_init_block*() and neither rae or data are NULL on those
calls.

> 
> [*] The C spec is quite strict about what valid pointer arithmetic
> is; in particular adding to a NULL pointer is undefined behaviour,
> and pointer arithmetic that overflows and wraps around is
> undefined behaviour, so there's no way to get a 0 result from
> "ptr + offset" without the expression being UB.
> 
> thanks
> -- PMM
> 

-- 
Eduardo



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PULL 2/2] core/register: Specify instance_size in the TypeInfo
  2020-09-29 13:22     ` Eduardo Habkost
@ 2020-10-01 15:37       ` Alistair Francis
  2020-10-01 16:04         ` Eduardo Habkost
  0 siblings, 1 reply; 9+ messages in thread
From: Alistair Francis @ 2020-10-01 15:37 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Peter Maydell, Alistair Francis, QEMU Developers,
	Philippe Mathieu-Daudé

On Tue, Sep 29, 2020 at 6:22 AM Eduardo Habkost <ehabkost@redhat.com> wrote:
>
> On Tue, Sep 29, 2020 at 01:55:35PM +0100, Peter Maydell wrote:
> > On Sun, 27 Sep 2020 at 15:00, Alistair Francis <alistair.francis@wdc.com> wrote:
> > >
> > > Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> > > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > > Message-Id: <4cf1beb7dafb9143c261d266557d3173bf160524.1598376594.git.alistair.francis@wdc.com>
> > > ---
> > > @@ -269,13 +258,18 @@ static RegisterInfoArray *register_init_block(DeviceState *owner,
> > >          int index = rae[i].addr / data_size;
> > >          RegisterInfo *r = &ri[index];
> > >
> > > -        *r = (RegisterInfo) {
> > > -            .data = data + data_size * index,
> > > -            .data_size = data_size,
> > > -            .access = &rae[i],
> > > -            .opaque = owner,
> > > -        };
> > > -        register_init(r);
> > > +        if (data + data_size * index == 0 || !&rae[i]) {
> > > +            continue;
> >
> > Coverity thinks (CID 1432800) that this is dead code, because
> > "data + data_size * index" can never be NULL[*]. What was this
> > intending to test for ? (maybe data == NULL? Missing dereference
> > operator ?)
>
> I believe the original check in the old register_init() function
> were just to make the function more flexible by allowing NULL
> arguments, but it was always unnecessary.  We have 4 callers of
> register_init_block*() and neither rae or data are NULL on those
> calls.

In this case *data is an array, I guess the idea was to try and catch
if somehow a point in the array was NULL?

I'll send a patch to remove the check.

Alistair

>
> >
> > [*] The C spec is quite strict about what valid pointer arithmetic
> > is; in particular adding to a NULL pointer is undefined behaviour,
> > and pointer arithmetic that overflows and wraps around is
> > undefined behaviour, so there's no way to get a 0 result from
> > "ptr + offset" without the expression being UB.
> >
> > thanks
> > -- PMM
> >
>
> --
> Eduardo
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PULL 2/2] core/register: Specify instance_size in the TypeInfo
  2020-10-01 15:37       ` Alistair Francis
@ 2020-10-01 16:04         ` Eduardo Habkost
  2020-10-01 16:48           ` Alistair Francis
  0 siblings, 1 reply; 9+ messages in thread
From: Eduardo Habkost @ 2020-10-01 16:04 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Peter Maydell, Alistair Francis, QEMU Developers,
	Philippe Mathieu-Daudé

On Thu, Oct 01, 2020 at 08:37:31AM -0700, Alistair Francis wrote:
> On Tue, Sep 29, 2020 at 6:22 AM Eduardo Habkost <ehabkost@redhat.com> wrote:
> >
> > On Tue, Sep 29, 2020 at 01:55:35PM +0100, Peter Maydell wrote:
> > > On Sun, 27 Sep 2020 at 15:00, Alistair Francis <alistair.francis@wdc.com> wrote:
> > > >
> > > > Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> > > > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > > > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > > > Message-Id: <4cf1beb7dafb9143c261d266557d3173bf160524.1598376594.git.alistair.francis@wdc.com>
> > > > ---
> > > > @@ -269,13 +258,18 @@ static RegisterInfoArray *register_init_block(DeviceState *owner,
> > > >          int index = rae[i].addr / data_size;
> > > >          RegisterInfo *r = &ri[index];
> > > >
> > > > -        *r = (RegisterInfo) {
> > > > -            .data = data + data_size * index,
> > > > -            .data_size = data_size,
> > > > -            .access = &rae[i],
> > > > -            .opaque = owner,
> > > > -        };
> > > > -        register_init(r);
> > > > +        if (data + data_size * index == 0 || !&rae[i]) {
> > > > +            continue;
> > >
> > > Coverity thinks (CID 1432800) that this is dead code, because
> > > "data + data_size * index" can never be NULL[*]. What was this
> > > intending to test for ? (maybe data == NULL? Missing dereference
> > > operator ?)
> >
> > I believe the original check in the old register_init() function
> > were just to make the function more flexible by allowing NULL
> > arguments, but it was always unnecessary.  We have 4 callers of
> > register_init_block*() and neither rae or data are NULL on those
> > calls.
> 
> In this case *data is an array, I guess the idea was to try and catch
> if somehow a point in the array was NULL?

I don't understand what you mean.  The area pointed by data
doesn't contain any pointers, just the register values.

> 
> I'll send a patch to remove the check.

Thanks!

-- 
Eduardo



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PULL 2/2] core/register: Specify instance_size in the TypeInfo
  2020-10-01 16:04         ` Eduardo Habkost
@ 2020-10-01 16:48           ` Alistair Francis
  0 siblings, 0 replies; 9+ messages in thread
From: Alistair Francis @ 2020-10-01 16:48 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Peter Maydell, Alistair Francis, QEMU Developers,
	Philippe Mathieu-Daudé

On Thu, Oct 1, 2020 at 9:05 AM Eduardo Habkost <ehabkost@redhat.com> wrote:
>
> On Thu, Oct 01, 2020 at 08:37:31AM -0700, Alistair Francis wrote:
> > On Tue, Sep 29, 2020 at 6:22 AM Eduardo Habkost <ehabkost@redhat.com> wrote:
> > >
> > > On Tue, Sep 29, 2020 at 01:55:35PM +0100, Peter Maydell wrote:
> > > > On Sun, 27 Sep 2020 at 15:00, Alistair Francis <alistair.francis@wdc.com> wrote:
> > > > >
> > > > > Reported-by: Eduardo Habkost <ehabkost@redhat.com>
> > > > > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > > > > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > > > > Message-Id: <4cf1beb7dafb9143c261d266557d3173bf160524.1598376594.git.alistair.francis@wdc.com>
> > > > > ---
> > > > > @@ -269,13 +258,18 @@ static RegisterInfoArray *register_init_block(DeviceState *owner,
> > > > >          int index = rae[i].addr / data_size;
> > > > >          RegisterInfo *r = &ri[index];
> > > > >
> > > > > -        *r = (RegisterInfo) {
> > > > > -            .data = data + data_size * index,
> > > > > -            .data_size = data_size,
> > > > > -            .access = &rae[i],
> > > > > -            .opaque = owner,
> > > > > -        };
> > > > > -        register_init(r);
> > > > > +        if (data + data_size * index == 0 || !&rae[i]) {
> > > > > +            continue;
> > > >
> > > > Coverity thinks (CID 1432800) that this is dead code, because
> > > > "data + data_size * index" can never be NULL[*]. What was this
> > > > intending to test for ? (maybe data == NULL? Missing dereference
> > > > operator ?)
> > >
> > > I believe the original check in the old register_init() function
> > > were just to make the function more flexible by allowing NULL
> > > arguments, but it was always unnecessary.  We have 4 callers of
> > > register_init_block*() and neither rae or data are NULL on those
> > > calls.
> >
> > In this case *data is an array, I guess the idea was to try and catch
> > if somehow a point in the array was NULL?
>
> I don't understand what you mean.  The area pointed by data
> doesn't contain any pointers, just the register values.

Yeah, I don't think this was ever right.

The idea I guess was to make sure that r.data was not NULL, but unless
data was NULL it couldn't be.

Alistair

>
> >
> > I'll send a patch to remove the check.
>
> Thanks!
>
> --
> Eduardo
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-10-01 17:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-27 13:46 [PULL 0/2] register queue Alistair Francis
2020-09-27 13:46 ` [PULL 1/2] load_elf: Remove unused address variables from callers Alistair Francis
2020-09-27 13:46 ` [PULL 2/2] core/register: Specify instance_size in the TypeInfo Alistair Francis
2020-09-29 12:55   ` Peter Maydell
2020-09-29 13:22     ` Eduardo Habkost
2020-10-01 15:37       ` Alistair Francis
2020-10-01 16:04         ` Eduardo Habkost
2020-10-01 16:48           ` Alistair Francis
2020-09-28 18:31 ` [PULL 0/2] register queue Peter Maydell

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.