Skip to contentSkip to conversation

hw/arm/raspi4b: remove redundant check in raspi_add_memory_node

PATCH Applied Osama Abdelkader 3 participants 3 messages Sep 2, 2025 – Sep 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/arm/raspi4b: remove redundant check in raspi_add_memory_node

The if (acells == 0 || scells == 0) check is redundant in raspi_add_memory_node, since it is already checked in the call chain, arm_load_dtb. Also the return value of the function is not checked/used so it's removed.

---
 hw/arm/raspi4b.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
hw/arm/raspi4b.c +9 -13
index 20082d5266..4df951a0d8 100644
@@ -36,9 +36,8 @@ struct Raspi4bMachineState {
  * (see https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf
  * 1.2 Address Map)
  */
-static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len)
+static void raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len)
 {
-    int ret;
     uint32_t acells, scells;
     char *nodename = g_strdup_printf("/memory@%" PRIx64, mem_base);
 
@@ -46,19 +45,16 @@ static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len)
                                    NULL, &error_fatal);
     scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells",
                                    NULL, &error_fatal);
-    if (acells == 0 || scells == 0) {
-        fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");
-        ret = -1;
-    } else {
-        qemu_fdt_add_subnode(fdt, nodename);
-        qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory");
-        ret = qemu_fdt_setprop_sized_cells(fdt, nodename, "reg",
-                                           acells, mem_base,
-                                           scells, mem_len);
-    }
+    /* validated by arm_load_dtb */
+    g_assert(acells && scells);
+
+    qemu_fdt_add_subnode(fdt, nodename);
+    qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory");
+    qemu_fdt_setprop_sized_cells(fdt, nodename, "reg",
+                                        acells, mem_base,
+                                        scells, mem_len);
 
     g_free(nodename);
-    return ret;
 }
 
 static void raspi4_modify_dtb(const struct arm_boot_info *info, void *fdt)
Signature · 1 line
2.43.0
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Osama Abdelkader

The if (acells == 0 || scells == 0) check is redundant in raspi_add_memory_node, since it is already checked in the call chain, arm_load_dtb. Also the return value of the function is not checked/used so it's removed.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro