From nobody Sun Sep 28 16:30:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1756731223; cv=none; d=zohomail.com; s=zohoarc; b=ex+6K1uqvsROrduBkyX2rTJeu+8iD4WgAak1ur/x2pNcOMLFTEAgF/O8SffwXeSqnw2UpY+bc+czFzqeCWqvhNEoUczG0S7017UXIXon1s+o8Upv2uUqc/Ow2nPpWaGB0FDU3+S+aEGqMM50SkkyfxuZ5MXb2cz+F8/DsJmExk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756731223; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BW+pcAYJr7rs8sK+GJ83FOVoqQy2R24okxpayuOukDM=; b=DanDEb5XUbfKAev7q9izsBFy3Ipl8TVC+Jytl/V55Qmu/eAy9jUpA+3RjtfclvitF+2pAyIhzhf5+IAuAS3HYysLibQKeCUa/jdauXzQNHbpG7xPA4u/CbW/XMagQ+J0euDf2xWQXF4cSdvy/6feFZ9AhkvUNfqvnNd65srSBfk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756731223248135.36117253938892; Mon, 1 Sep 2025 05:53:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ut429-0002TK-EN; Mon, 01 Sep 2025 08:53:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ut426-0002Qn-5p for qemu-devel@nongnu.org; Mon, 01 Sep 2025 08:53:14 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ut421-0004Ik-AG for qemu-devel@nongnu.org; Mon, 01 Sep 2025 08:53:13 -0400 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-61cbfa1d820so8394861a12.3 for ; Mon, 01 Sep 2025 05:53:08 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b04093c9161sm515809666b.54.2025.09.01.05.53.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Sep 2025 05:53:05 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 2D8395F8D7; Mon, 01 Sep 2025 13:53:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756731187; x=1757335987; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BW+pcAYJr7rs8sK+GJ83FOVoqQy2R24okxpayuOukDM=; b=uXz3ueEH8grKmRvzf8oB819OxF6JhLXEoZfAiufDSxA7hkTnei6eoDGyjTxnO6DXbA 8+A1JWoLEOb4rjsd5COE1XGw3SHVJEm2xWKzbVBAurEiHgl8tXSwYgprSp35p78nklQZ zVXt5Vein1OUK/i/TG/yReplqNlBcjDBhd+OMsA1k/eKD5PbgugixYlMKDVQSRoSf2fT DQ9iVlMUqtIynpMq+k3yXJasYN6WBwOcnCWr91/Gj/woFXJbEB1o4mMoWZy22upLIKmK /VQLJBsdVHwu3lt9ueE4fYyaAijT78+o+tE9EIjtaF0hpveTqcmiLbALeKof5l5E5EBY UrUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756731187; x=1757335987; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BW+pcAYJr7rs8sK+GJ83FOVoqQy2R24okxpayuOukDM=; b=CDLntT9MuuHUq+K3PbSWYGSTqzBP3DlQDqXA3/s+aeec+3wkxnmSF8VS93nGVmrapV 5PzeVgaOGj3Ju1rvzSWqhI7B68t/nPzvwq3+pxMZ/XXWP5lNwGF/QeeZLM9HCpOLFLCS pW1jm6rxtzMxH2nk2riQxAnPO4LmXC9k58wMM0ofo1hIzoGCosACv09xm5+HLKpNE47i 6spPRVlEDD/2G9Ezt00EBICjonY6T7efRhsKUL4mwTktUUWVzjC+6rbS2TXznKYNViJE iNZXnEFSQMJr1rlveL81+6FL9eKvi55yIm+DU9dELS90+RoH1rejOr0MbbG10dAyaoKC E3GA== X-Gm-Message-State: AOJu0Yx+AwnzoJUnHVyeQt2EFof80jVRk+FWjRziBD1aW8TipgbbrqI4 jOcPVpN5mkocusq+wRb7JzHRkLsMn34MMHUZDJ5oBpDQpuCCDJi/+HaQ5VvsyrGPM50= X-Gm-Gg: ASbGncvr/KIrQiQ/KhE8XyerrVPOVnDoEBahnAJVLx3RY2ESRCBzy8oguzukGxkBgM3 r8qZkU43z1ouGsS6giAS32uHJO+CcUApd6ds5cn6tfCP9jA30jMby+73SSz3oli7ROGlO5kdeG8 3WZDdkDp1aeiQgbXJ6LTEbuCvnewh+4SHcym8GpPMWYhXT4feSg0oJsR6aGOkL0Ri3bkDVzokTh +rAj8kTxfmaKmGkjpo+YpDv965q/TsjDkBcDHtIeP1baJ1Q3jhstyegoigEIr7vFv5fMbRsMi7s 0Y95DtW9HNW0jU1952w1ECIXrm8FtcQjwm8/V/RoYuN7Pr+JE9AJj8IIBLlBWVqw70aoPDiTiFv 071h2Zpgk/wLkGxmqnhlDrOg8SSAY/YYEcw== X-Google-Smtp-Source: AGHT+IErB9p5Z0ZCWdNwbhoKUaI0nbChocKjfcOqjuNfXkeiherqMi5oWD33sD8hEdJgDaOZVNuPhQ== X-Received: by 2002:a17:907:3c85:b0:af9:5e9a:b6a with SMTP id a640c23a62f3a-b01d9743b83mr685530566b.42.1756731186643; Mon, 01 Sep 2025 05:53:06 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH 2/4] hw/arm: use g_autofree for fdt in arm_load_dtb Date: Mon, 1 Sep 2025 13:53:02 +0100 Message-ID: <20250901125304.1047624-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250901125304.1047624-1-alex.bennee@linaro.org> References: <20250901125304.1047624-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1756731236497124100 With the fdt being protected by g_autofree we can skip the goto fail and bail out straight away. The only thing we must take care of is stealing the pointer in the one case when we do need it to survive. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Manos Pitsidianakis --- hw/arm/boot.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 56fd13b9f7c..749f2d08341 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -519,7 +519,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, hwaddr addr_limit, AddressSpace *as, MachineState *ms, ARMCPU *cpu) { - void *fdt =3D NULL; + g_autofree void *fdt =3D NULL; int size, rc, n =3D 0; uint32_t acells, scells; unsigned int i; @@ -538,13 +538,13 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_i= nfo *binfo, fdt =3D load_device_tree(filename, &size); if (!fdt) { fprintf(stderr, "Couldn't open dtb file %s\n", filename); - goto fail; + return -1; } } else { fdt =3D binfo->get_dtb(binfo, &size); if (!fdt) { fprintf(stderr, "Board was unable to create a dtb blob\n"); - goto fail; + return -1; } } =20 @@ -553,7 +553,6 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, * Whether this constitutes failure is up to the caller to decide, * so just return 0 as size, i.e., no error. */ - g_free(fdt); return 0; } =20 @@ -563,7 +562,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, NULL, &error_fatal); if (acells =3D=3D 0 || scells =3D=3D 0) { fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0= )\n"); - goto fail; + return -1; } =20 if (scells < 2 && binfo->ram_size >=3D 4 * GiB) { @@ -572,14 +571,14 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_i= nfo *binfo, */ fprintf(stderr, "qemu: dtb file not compatible with " "RAM size > 4GB\n"); - goto fail; + return -1; } =20 /* nop all root nodes matching /memory or /memory@unit-address */ node_path =3D qemu_fdt_node_unit_path(fdt, "memory", &err); if (err) { error_report_err(err); - goto fail; + return -1; } while (node_path[n]) { if (g_str_has_prefix(node_path[n], "/memory")) { @@ -611,7 +610,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, if (rc < 0) { fprintf(stderr, "couldn't add /memory@%"PRIx64" node\n", mem_base); - goto fail; + return -1; } =20 mem_base +=3D mem_len; @@ -622,7 +621,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, if (rc < 0) { fprintf(stderr, "couldn't add /memory@%"PRIx64" node\n", binfo->loader_start); - goto fail; + return -1; } } =20 @@ -636,7 +635,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, ms->kernel_cmdline); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/bootargs\n"); - goto fail; + return -1; } } =20 @@ -645,7 +644,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, acells, binfo->initrd_start); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); - goto fail; + return -1; } =20 rc =3D qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-= end", @@ -654,7 +653,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, binfo->initrd_size); if (rc < 0) { fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); - goto fail; + return -1; } } =20 @@ -673,14 +672,10 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_i= nfo *binfo, =20 if (fdt !=3D ms->fdt) { g_free(ms->fdt); - ms->fdt =3D fdt; + ms->fdt =3D g_steal_pointer(&fdt); } =20 return size; - -fail: - g_free(fdt); - return -1; } =20 static void do_cpu_reset(void *opaque) --=20 2.47.2