hw/arm/raspi4b: replace fprintf with error_report
PATCH 1/1 hw/arm/raspi4b: replace fprintf with error_report
Replace direct fprintf(stderr, …) with QEMU's error_report() API, which ensures consistent formatting and integrates with QEMU's logging infrastructure.
--- hw/arm/raspi4b.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/raspi4b.c +1 -1
@@ -47,7 +47,7 @@ static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) 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" ); +error_report ("dtb file invalid (#address-cells or #size-cells 0)" ); ret =-1 ; }else {qemu_fdt_add_subnode (fdt, nodename);
Signature · 1 line
2.43.0
References: <[email protected]>
User-Agent: mu4e 1.12.12; emacs 30.1
Quoted 2 lines · Osama Abdelkader
Replace direct
fprintf(stderr, .%80.)with QEMU'serror_report()API,
Not sure what happened with the encoding there, it seems to be non-utf-8.
Quoted 13 lines
which ensures consistent formatting and integrates with QEMU's logging infrastructure.
Signed-off-by Osama Abdelkader <[email protected]>--- hw/arm/raspi4b.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/raspi4b.c +0
-0
hw/arm/raspi4b.c static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) · line 50
Quoted 5 lines
hw/arm/raspi4b.c +1
-1@@ -47,7 +47,7 @@ static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) 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" ); +error_report ("dtb file invalid (#address-cells or #size-cells 0)" );
This change is fine as far as it goes but I wonder if it is an error_report or a warn_report. The reason being:
hw/arm/raspi4b.c static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) · line 51
Quoted 1 line
hw/arm/raspi4b.c +0
-0ret =-1 ;
we set -1 to ret here but it is ignored by the call:
if (info->ram_size > UPPER_RAM_BASE) {
raspi_add_memory_node(fdt, UPPER_RAM_BASE, ram_size - UPPER_RAM_BASE);
}which implies this isn't a fatal error, but the user should certainly be warned they won't get all the memory they were expecting.
While these single line patches are a good way to get comfortable with the review and submission process I would also encourage you to look at the call chain.
In this case we get here from arm_load_dtb:
if (binfo->modify_dtb) {
binfo->modify_dtb(binfo, fdt);
}And you can see further up that function we do the same test:
acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells",
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");
goto fail;
}which fails and ultimately causes QEMU to exit as it can't continue. In that case I don't think we could ever hit this condition. As it would be a programming failure I think we could replace the whole if leg with:
/* validated by arm_load_dtb */ g_assert(acells && scells);
and maybe remove the ignored (and redundant) return value from raspi_add_memory_node().
Quoted 2 lines
hw/arm/raspi4b.c +0
-0}else {qemu_fdt_add_subnode (fdt, nodename);
Signature · 3 lines
Alex Bennée Virtualisation Tech Lead @ Linaro Date: Tue, 02 Sep 2025 10:20:42 +0100
Quoted 67 lines · Alex Bennée
References: <[email protected]>
User-Agent: mu4e 1.12.12; emacs 30.1Quoted 2 lines · Osama Abdelkader
Replace direct
fprintf(stderr, .%80.)with QEMU'serror_report()API,Not sure what happened with the encoding there, it seems to be non-utf-8.
Quoted 13 lines
which ensures consistent formatting and integrates with QEMU's logging infrastructure.
Signed-off-by Osama Abdelkader <[email protected]>--- hw/arm/raspi4b.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/arm/raspi4b.c +0
-0hw/arm/raspi4b.c static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) · line 50
Quoted 5 lines
hw/arm/raspi4b.c +1
-1@@ -47,7 +47,7 @@ static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) 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" ); +error_report ("dtb file invalid (#address-cells or #size-cells 0)" );This change is fine as far as it goes but I wonder if it is an
error_reportor awarn_report. The reason being:hw/arm/raspi4b.c static int raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len) · line 51
Quoted 1 line
hw/arm/raspi4b.c +0
-0ret =-1 ;we set -1 to ret here but it is ignored by the call:
if (info->ram_size > UPPER_RAM_BASE) { raspi_add_memory_node(fdt, UPPER_RAM_BASE, ram_size - UPPER_RAM_BASE); }which implies this isn't a fatal error, but the user should certainly be warned they won't get all the memory they were expecting.
While these single line patches are a good way to get comfortable with the review and submission process I would also encourage you to look at the call chain.
In this case we get here from
arm_load_dtb:if (binfo->modify_dtb) { binfo->modify_dtb(binfo, fdt); }And you can see further up that function we do the same test:
acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells", 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"); goto fail; }which fails and ultimately causes QEMU to exit as it can't continue. In that case I don't think we could ever hit this condition. As it would be a programming failure I think we could replace the whole if leg with:
Quoted 13 lines
/* validated by arm_load_dtb */ g_assert(acells && scells);and maybe remove the ignored (and redundant) return value from
raspi_add_memory_node().Quoted 2 lines
hw/arm/raspi4b.c +0
-0}else {qemu_fdt_add_subnode (fdt, nodename);Signature · 3 lines
Alex Bennée Virtualisation Tech Lead @ Linaro Date: Tue, 02 Sep 2025 10:20:42 +0100
Thanks Alex, exactly. I just checked that and sent another patch since it's not only fprintf replace anymore.
Thank you,
Osama