qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] hw/arm: use g_autofree for filename in arm_load_dtb
       [not found] <20250904081220.1944461-1-alex.bennee@linaro.org>
@ 2025-09-04  8:12 ` Alex Bennée
  0 siblings, 0 replies; only message in thread
From: Alex Bennée @ 2025-09-04  8:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, qemu-arm, Alex Bennée, Richard Henderson,
	Manos Pitsidianakis

The function has quite a number of exit cases so lets try and clean
things up with g_autofree. As the fdt hasn't be allocated yet we can
return directly from the fail point.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 hw/arm/boot.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 1e57c4ab9ee..5d708255df6 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -553,20 +553,18 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
     Error *err = NULL;
 
     if (binfo->dtb_filename) {
-        char *filename;
-        filename = qemu_find_file(QEMU_FILE_TYPE_DTB, binfo->dtb_filename);
+        g_autofree char *filename = qemu_find_file(QEMU_FILE_TYPE_DTB,
+                                                   binfo->dtb_filename);
         if (!filename) {
             fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
-            goto fail;
+            return -1;
         }
 
         fdt = load_device_tree(filename, &size);
         if (!fdt) {
             fprintf(stderr, "Couldn't open dtb file %s\n", filename);
-            g_free(filename);
             goto fail;
         }
-        g_free(filename);
     } else {
         fdt = binfo->get_dtb(binfo, &size);
         if (!fdt) {
-- 
2.47.2



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-09-04  8:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250904081220.1944461-1-alex.bennee@linaro.org>
2025-09-04  8:12 ` [PATCH v2 1/4] hw/arm: use g_autofree for filename in arm_load_dtb Alex Bennée

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).