From nobody Tue Nov 26 17:24:36 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1705961839; cv=none; d=zohomail.com; s=zohoarc; b=AZFHawwvPGNMn+wvFZiOSbKDFrYunj7cUKc21lnlIQATmNy9Zf/DSgmaDYUNQ4xh/t/lDeDdfDLIc0CoDdJ3RtP3EkU+rTVR24Q382bKFds9elKsty1c5YkH3UGOqecZLmYi/5US1WpUwxXH5UYAWGTfwo8BKo7Y0O0eaounU9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705961839; h=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=0kWZUcyOcgTFo8e119jS9KvVJWH/ZmICoOps9eP3tTI=; b=lj8UXrivqErHAgjt1ohJZ0TUqM8RbVSblFjG2f5d1gHhiQBWKJVp4frQUYQj/Pd/VBVItUflVuhxHGfms/JZ4v03hV1LDZDiwlWhodfHljpPbhUlK438i9HhzL/LW6xfz44fwmW157OQenlflvVaxvvhzKOQP9lslEL56aPGHKM= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705961839570947.9746816995422; Mon, 22 Jan 2024 14:17:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rS2a2-0004nt-SB; Mon, 22 Jan 2024 17:15:46 -0500 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 1rS2Zx-0004mU-Ty for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:42 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rS2Zw-0005ty-Ee for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:41 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d76671e5a4so5286025ad.0 for ; Mon, 22 Jan 2024 14:15:40 -0800 (PST) Received: from grind.. ([152.234.127.94]) by smtp.gmail.com with ESMTPSA id kr8-20020a170903080800b001d7338977e6sm4029104plb.223.2024.01.22.14.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705961738; x=1706566538; 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=0kWZUcyOcgTFo8e119jS9KvVJWH/ZmICoOps9eP3tTI=; b=i+mk8dhIdz7aYXJuqVD6FYzC0Tdcq8lATL5Th9IOYTuVaxU8/ZyCS3uxFEuECa+7Z2 ZKG4eMwdHRs6OgZ9KboagzWX5iYPcv/HKXkYWKTPh9pw+h1MM1uJIOUvIzOpxPsetESF wh6ngIMLORMHE366BZGPPHy+nJwpjmGnUFADhKw2xzctrFoppuX3iu//j5LZhkeK9GWx 98WkTlUn0YLsnq92r+aXbDEGguDXAyuGnMCGiSV2Mj4WYZrLzD+rCX2a6XyuPio3rxs7 3mGwcGkB7N2/3uqMo1GxTARJle0Un2N0z5AjjsKl/xq8RteJiw7BRYb7ItMBBQp9WjVx 8AMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705961738; x=1706566538; 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=0kWZUcyOcgTFo8e119jS9KvVJWH/ZmICoOps9eP3tTI=; b=GLvnPd5d37sugtRKE6i2+a0VVaMawz10AW5PuSZnrB0KQQrYKF0NnN+XEeoWvHqcN4 2JrpR9bTsBHl1PQgMLFiFcrQ+SBtMKbb+0EdygFVFqKPiqoSUlQPZfx8y9XkbgwLqmLA DqT+CIDKt+9YuWn1+SiAKaF0i1oz24tWjUb4JC3ricTp1BMfxyo1qJ2osT8MVGN7J8W7 rkqWCbpYSA7bAzsrUq5vs5GwkE28M9xy+W6olEqmcuQ/BdQQNSazxUJQOCfZQNWUKkpI l5X0ucMi6pi08Yi29FcLhMEdwHplb0GHpNMqrBSt92+Td52o59SPzetyJCNJQfgyH+Cg +DyA== X-Gm-Message-State: AOJu0Yyx2/CLngWuvalq4FSi6Orz43b3mUDyhs9cPA9dnZQ78Ri5IvQn +OQ24vrIkFd2mGiderLFkd5ed6afwLLz3OYBGMWNlAiChVOCBzpsBtAWFmNFDMw9acrCFaJoLqv 9 X-Google-Smtp-Source: AGHT+IHYwwPdqLb0Z1C56XNnK3IvlAVjKnaIMHXXYZ9zehfY4ji7+ycXJUrgIqVTp5ZtbNpWOx/9Zw== X-Received: by 2002:a17:902:ec84:b0:1d7:5adc:3a03 with SMTP id x4-20020a170902ec8400b001d75adc3a03mr2054076plg.119.1705961738306; Mon, 22 Jan 2024 14:15:38 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH 1/7] hw/riscv/virt-acpi-build.c: fix leak in build_rhct() Date: Mon, 22 Jan 2024 19:15:23 -0300 Message-ID: <20240122221529.86562-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122221529.86562-1-dbarboza@ventanamicro.com> References: <20240122221529.86562-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::62c; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62c.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, T_SCC_BODY_TEXT_LINE=-0.01 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 @ventanamicro.com) X-ZM-MESSAGEID: 1705961840062100009 Content-Type: text/plain; charset="utf-8" The 'isa' char pointer isn't being freed after use. Issue detected by Valgrind: =3D=3D38752=3D=3D 128 bytes in 1 blocks are definitely lost in loss record = 3,190 of 3,884 =3D=3D38752=3D=3D at 0x484280F: malloc (vg_replace_malloc.c:442) =3D=3D38752=3D=3D by 0x5189619: g_malloc (gmem.c:130) =3D=3D38752=3D=3D by 0x51A5BF2: g_strconcat (gstrfuncs.c:628) =3D=3D38752=3D=3D by 0x6C1E3E: riscv_isa_string_ext (cpu.c:2321) =3D=3D38752=3D=3D by 0x6C1E3E: riscv_isa_string (cpu.c:2343) =3D=3D38752=3D=3D by 0x6BD2EA: build_rhct (virt-acpi-build.c:232) =3D=3D38752=3D=3D by 0x6BD2EA: virt_acpi_build (virt-acpi-build.c:556) =3D=3D38752=3D=3D by 0x6BDC86: virt_acpi_setup (virt-acpi-build.c:662) =3D=3D38752=3D=3D by 0x9C8DC6: notifier_list_notify (notify.c:39) =3D=3D38752=3D=3D by 0x4A595A: qdev_machine_creation_done (machine.c:158= 9) =3D=3D38752=3D=3D by 0x61E052: qemu_machine_creation_done (vl.c:2680) =3D=3D38752=3D=3D by 0x61E052: qmp_x_exit_preconfig.part.0 (vl.c:2709) =3D=3D38752=3D=3D by 0x6220C6: qmp_x_exit_preconfig (vl.c:2702) =3D=3D38752=3D=3D by 0x6220C6: qemu_init (vl.c:3758) =3D=3D38752=3D=3D by 0x425858: main (main.c:47) Fixes: ebfd392893 ("hw/riscv/virt: virt-acpi-build.c: Add RHCT Table") Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/riscv/virt-acpi-build.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c index 26c7e4482d..fb8baf64f6 100644 --- a/hw/riscv/virt-acpi-build.c +++ b/hw/riscv/virt-acpi-build.c @@ -196,7 +196,7 @@ static void build_rhct(GArray *table_data, RISCVCPU *cpu =3D &s->soc[0].harts[0]; uint32_t mmu_offset =3D 0; uint8_t satp_mode_max; - char *isa; + g_autofree char *isa =3D NULL; =20 AcpiTable table =3D { .sig =3D "RHCT", .rev =3D 1, .oem_id =3D s->oem_= id, .oem_table_id =3D s->oem_table_id }; --=20 2.43.0 From nobody Tue Nov 26 17:24:36 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1705961858; cv=none; d=zohomail.com; s=zohoarc; b=WQ8eoJwB04n+TLji7Ytd1n5beP7XpJqCDFua4GilQpdgF95j74tZ1D5WRLX34lMWGxNRJCVop7kUdGsVBnu+bMWoBzvMKWE1bMc8B1hhJm5QgjlIggBpguJ45LOdfw9Zf+Ld47buxoMx97mA2tO8KM4HxcN3lDHlRPuqIF/tNjE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705961858; h=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=NzHL8aJDpNvMBJ2WBWw1qBXQpPaYiy2l39AZTY8wyvQ=; b=M61FTQaOJTt0iqNeOQrd6PsRwm1qfqUZrAdvfCdzakpCJ7i2gwAeJqvVTlANQ670a7vkD+hI5L74LRCFTpOvQ/lTU+sOYbg0sQ+6g7i5qJOfecFOCVUfA2YpGvTH+JUby0sEQFtZOobXOavqeBfv3abfQownj+/a6NBGXVqM5oo= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705961858350515.2987540368579; Mon, 22 Jan 2024 14:17:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rS2aM-0004qx-MQ; Mon, 22 Jan 2024 17:16:08 -0500 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 1rS2a0-0004nD-Ki for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:44 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rS2Zz-0005uo-63 for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:44 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d7354ba334so17575515ad.1 for ; Mon, 22 Jan 2024 14:15:42 -0800 (PST) Received: from grind.. ([152.234.127.94]) by smtp.gmail.com with ESMTPSA id kr8-20020a170903080800b001d7338977e6sm4029104plb.223.2024.01.22.14.15.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:15:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705961741; x=1706566541; 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=NzHL8aJDpNvMBJ2WBWw1qBXQpPaYiy2l39AZTY8wyvQ=; b=iuKOMvdXhVRrMPHY1vS1xuCSkKWfzDw98+EhppFz+AKMyNcnodpVhefWAMXzKhn+RZ LlZu3CtLvrNe31qdC11aBlM4EEdF5GPZKg5WfVFgUFQ1j2RChEIv0RE4Qx01RTLTZFr4 BaqyNGM9iMZEZsKs1IMN9r+PjlcRbDyiTmtPeGVspr6TmSL5+sXp89EinOsxeAlX+xnm w6tO7buYiFneFgaR4CmVkxkzW7OXk1gkMez7Zs5gqcx8Llmcmrhf70bny0aQFmBIekca R986YN2BjMfaLBcKoFGEuQsAqXS+ilk+A8LrYdhGB6BkC6S924lTonqXLoHt/1iH7BM2 YBPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705961741; x=1706566541; 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=NzHL8aJDpNvMBJ2WBWw1qBXQpPaYiy2l39AZTY8wyvQ=; b=SI04tuuJHQjnT/eyh0a4Fq15RmEeW2b2wYibHTr6SgrV/7R3nWc2YsDBPc+d3uercO Xz1VDNEL8zGMZBvQ+PaaEsu9qyVgMNQHvHy/3OO/ehSLPCk2uCPeTwyJObawwUPm42u2 qrVyqesb1qxIbMDcz5BJSuAs+B9/XkYM9s0kSyWHMEVbItAygMa2a/yRiemc89SBSqqg sgvdWUQBK9IsKz5nBLBz+KBk9QGaxQsKXX5H0oymVpBNvYtzK1e4iLldtOxzAT9MJCMZ G002QBKCV57cYlzOvGSGkcFuxJgnw5rHHH4eF2Pj2pBSATfrvoT57rFen45wq5t8eJZ7 CA7w== X-Gm-Message-State: AOJu0YzF0oWLNgy6EQbA5dwoChP/d7oTqSPqVqx+lQh8XQArX3+E1ccx 6KXNMrHnxylFgNdEZopIwXrkx8HoolJHHcvNcrjcGyUg/RtWSpA4OA7Bers9Req5nZv3Ys9mL6R B X-Google-Smtp-Source: AGHT+IGzsf37BmxGv7KeuB1LO0dV+L3lL+X9Y8JQx+fmpMyYbXTJosc/Eamursw+m9Hv82BYymEMdg== X-Received: by 2002:a17:902:650e:b0:1d5:efcb:3cd1 with SMTP id b14-20020a170902650e00b001d5efcb3cd1mr4636841plk.81.1705961741183; Mon, 22 Jan 2024 14:15:41 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH 2/7] hw/riscv/numa.c: use g_autofree in socket_fdt_write_distance_matrix() Date: Mon, 22 Jan 2024 19:15:24 -0300 Message-ID: <20240122221529.86562-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122221529.86562-1-dbarboza@ventanamicro.com> References: <20240122221529.86562-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::62f; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62f.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, T_SCC_BODY_TEXT_LINE=-0.01 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 @ventanamicro.com) X-ZM-MESSAGEID: 1705961860138100001 Content-Type: text/plain; charset="utf-8" Use g_autofree in 'dist_matrix' to avoid the manual g_free(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/riscv/numa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/riscv/numa.c b/hw/riscv/numa.c index d319aefb45..cf686f4ff1 100644 --- a/hw/riscv/numa.c +++ b/hw/riscv/numa.c @@ -167,7 +167,8 @@ void riscv_socket_fdt_write_id(const MachineState *ms, = const char *node_name, void riscv_socket_fdt_write_distance_matrix(const MachineState *ms) { int i, j, idx; - uint32_t *dist_matrix, dist_matrix_size; + g_autofree uint32_t *dist_matrix =3D NULL; + uint32_t dist_matrix_size; =20 if (numa_enabled(ms) && ms->numa_state->have_numa_distance) { dist_matrix_size =3D riscv_socket_count(ms) * riscv_socket_count(m= s); @@ -189,7 +190,6 @@ void riscv_socket_fdt_write_distance_matrix(const Machi= neState *ms) "numa-distance-map-v1"); qemu_fdt_setprop(ms->fdt, "/distance-map", "distance-matrix", dist_matrix, dist_matrix_size); - g_free(dist_matrix); } } =20 --=20 2.43.0 From nobody Tue Nov 26 17:24:36 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1705961823; cv=none; d=zohomail.com; s=zohoarc; b=DuJ0wd/jTMc8/8gD03m00C9N2jxcFQSBfTx0qu6cZ/WIVwl9HwugBLHJihlYZEvg/383+u5qUGC6wf9q8DYgehqk1VMzjVWHcm1A2Q1KfjoFPMJQHLXd5FwSlVtAHmvlzWxezGN/8Au6aZ15g2Gfj38+TueBj+N3vE12xe2OZNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705961823; h=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=RXJkelt17p21iChlHdyIQJpyyWudaM9AOBguHLeeMgQ=; b=ivkhZDa0p+aA6+SplosQaoLUJzBDx1EgQBEt7N7u56tBjtTetEwUhtDYUhaD/Epea1uOYAC1nMAeIueIpUez+C3eE/L8hmvVnx9ncpfy38Fdsd5JZV3m0SZCUiwssQT6kOv0zgTebiybCYJLrgFTRFTtMgCjgz3Q79TDkV25fIk= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705961823729674.3100354103851; Mon, 22 Jan 2024 14:17:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rS2aD-0004px-O4; Mon, 22 Jan 2024 17:15:57 -0500 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 1rS2a5-0004oe-5q for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:51 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rS2a2-0005vF-68 for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:47 -0500 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d746856d85so8173745ad.0 for ; Mon, 22 Jan 2024 14:15:45 -0800 (PST) Received: from grind.. ([152.234.127.94]) by smtp.gmail.com with ESMTPSA id kr8-20020a170903080800b001d7338977e6sm4029104plb.223.2024.01.22.14.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:15:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705961744; x=1706566544; 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=RXJkelt17p21iChlHdyIQJpyyWudaM9AOBguHLeeMgQ=; b=lp7lBg0KgWu7fwwE4/vN/jAoWT+vfwdO+9Yiz+Jw6gjMNJIX80cBbp2d+ABEz6ZIMO g3SNvinrbjhXGgr1CNMlVL9oYUQ5G/qQK/Z4LjWEeDSt7Rf35JWAWgwDq/IfF6QvbNQa YkhkBWY5+dgWbeflRmMFouVIOzMJ0eb5EuAf7HFt0U82QLIFpgXfWd/U5klbuZdyQSBK ei49dqui62X1MQJwyPb2D1fRZi3qlRkz3IhGqTCP6AxcPOvcuimUN+2kuf2U+2dX3a74 FsXkG6Tkh5D/ZeEcPqNc9OWEIzKoHi2ZlDPZN0NBEAItBiT4NHZzJqIaQRejnu72y9Py ulFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705961744; x=1706566544; 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=RXJkelt17p21iChlHdyIQJpyyWudaM9AOBguHLeeMgQ=; b=jXXjACBjz3gvrzoRJPc3aHQMDtDZYUxgyDOQK2vpLIwdrPAQd8+PoLL6GGbth+4PRi QKBjZAuAquWZ5YDGMlCkd/qWHQnH/9h92FzvdneVaBVmWPK/G6EVNu9zKiYINUvGmHY+ IB+haNq0mjLoWnSiqpUww6j2CYbN/PZRSgZwcWZfegRJaGw0ST5jMz2zDNJzVICgXBUi fODpI5hYxMEeElE+K0YL/HPGJ7YJbAdNn0f6XD1F9QqhvAq2VLl0rZqWVvkW3FjBe5gK xu6i53mvanDj+hWB6nbinIL8+RgW4tOfF4DJWgr2U30r/5b7KTCGyY0VAdI35ZODEWUc ssFA== X-Gm-Message-State: AOJu0Yw1cDHwL1CxEv0+kd5iqJf/I3ey5hLoK8vSWsyvvQMbVXS1F3KW dBcKu/tk5Vx8cyK1naO3iYUw7t9qaPQflqMH2xg7DapbgL6BjBj1aTpSJW9tpJIo/xXK4/kcQCp U X-Google-Smtp-Source: AGHT+IHbmrRzoDHuMPAm+9RhG728+lpTXnTIbB5f/SqVjXPWWMy/EmeBdxl0eXAAmPSKdisro603Ag== X-Received: by 2002:a17:902:ea92:b0:1d6:ee5c:42c2 with SMTP id x18-20020a170902ea9200b001d6ee5c42c2mr2027491plb.115.1705961744093; Mon, 22 Jan 2024 14:15:44 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH 3/7] hw/riscv/virt.c: use g_autofree in create_fdt_socket_cpus() Date: Mon, 22 Jan 2024 19:15:25 -0300 Message-ID: <20240122221529.86562-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122221529.86562-1-dbarboza@ventanamicro.com> References: <20240122221529.86562-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::634; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x634.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, T_SCC_BODY_TEXT_LINE=-0.01 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 @ventanamicro.com) X-ZM-MESSAGEID: 1705961825967100006 Content-Type: text/plain; charset="utf-8" Move all char pointers to the loop. Use g_autofree in all of them to avoid the g_free() calls. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/riscv/virt.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index f9fd1341fc..373b1dd96b 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -215,12 +215,16 @@ static void create_fdt_socket_cpus(RISCVVirtState *s,= int socket, int cpu; uint32_t cpu_phandle; MachineState *ms =3D MACHINE(s); - char *name, *cpu_name, *core_name, *intc_name, *sv_name; bool is_32_bit =3D riscv_is_32bit(&s->soc[0]); uint8_t satp_mode_max; =20 for (cpu =3D s->soc[socket].num_harts - 1; cpu >=3D 0; cpu--) { RISCVCPU *cpu_ptr =3D &s->soc[socket].harts[cpu]; + g_autofree char *name =3D NULL; + g_autofree char *cpu_name =3D NULL; + g_autofree char *core_name =3D NULL; + g_autofree char *intc_name =3D NULL; + g_autofree char *sv_name =3D NULL; =20 cpu_phandle =3D (*phandle)++; =20 @@ -233,12 +237,10 @@ static void create_fdt_socket_cpus(RISCVVirtState *s,= int socket, sv_name =3D g_strdup_printf("riscv,%s", satp_mode_str(satp_mode_max, is_32_b= it)); qemu_fdt_setprop_string(ms->fdt, cpu_name, "mmu-type", sv_name= ); - g_free(sv_name); } =20 name =3D riscv_isa_string(cpu_ptr); qemu_fdt_setprop_string(ms->fdt, cpu_name, "riscv,isa", name); - g_free(name); =20 if (cpu_ptr->cfg.ext_zicbom) { qemu_fdt_setprop_cell(ms->fdt, cpu_name, "riscv,cbom-block-siz= e", @@ -277,10 +279,6 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, = int socket, core_name =3D g_strdup_printf("%s/core%d", clust_name, cpu); qemu_fdt_add_subnode(ms->fdt, core_name); qemu_fdt_setprop_cell(ms->fdt, core_name, "cpu", cpu_phandle); - - g_free(core_name); - g_free(intc_name); - g_free(cpu_name); } } =20 --=20 2.43.0 From nobody Tue Nov 26 17:24:36 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1705961823; cv=none; d=zohomail.com; s=zohoarc; b=b2Ffyg1CWZPYTBdZWvCZ3D8tLPGY/caVCTmibHJEC5gHPKwBuqve+2LHbcXFZlDFWGHIfPmvXp2rn2WdmWqUTtq9gfzJIVP/L+ImgPwW6GaUqVcAA9z2lyp3oym21BCdfY1mXAj2omLTMpZbdZkoCNNKMR3/nmbJpv9aoxfrrv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705961823; h=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=WX7OqCyKznH6Xg+YgqFqeDU+3oQq1TVExI/mQG8+wFY=; b=mMl/cwwSqTvbTfadj0MZqYX33PEfMh27BVYGHMxYFXBYafbeohl5GlXApf6kFMl5Rz99GOlBwzbwyTQmutAxL9vUjmx3SI2FvAx7faJI8e0qOsgmHh0HtWJaPGK+SHKHlbotkMKnaULhYYl7lpUtbzhe9eG/g+pi04R2TqkTuEA= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705961823820691.304981749626; Mon, 22 Jan 2024 14:17:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rS2aS-0004sm-Ra; Mon, 22 Jan 2024 17:16:12 -0500 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 1rS2a7-0004ow-RZ for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:53 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rS2a5-0005vh-55 for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:51 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1d71e24845aso19500145ad.0 for ; Mon, 22 Jan 2024 14:15:48 -0800 (PST) Received: from grind.. ([152.234.127.94]) by smtp.gmail.com with ESMTPSA id kr8-20020a170903080800b001d7338977e6sm4029104plb.223.2024.01.22.14.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:15:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705961747; x=1706566547; 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=WX7OqCyKznH6Xg+YgqFqeDU+3oQq1TVExI/mQG8+wFY=; b=dh0pyy1SBx1XhX3Rlh4NRfnJuwwnPYS9qZZF2NW28RSsWaAayE3tSLHlEp4i2QPSFn e9C08FTRJwGk1Mcva3LmSmmEcbbE1HO2QpPV4iaAJ1WuDIValvyu2y2YbDP8bDi6Dlkl drxKp8nDxCHEJSXRb9g4RkXmfZWmbm/4jpbbYd3rpgbqWmslqo6essqvpAjtT2l54UPR 9mkHUuxv+Vut9c2qA0DT4p5PIn2mM8v/d7NivD2m9h/snjEmC43pjuG7KA4/4UDsn3pC UixHf94Fa9L9bYs71qRW7cC+drdI/wOB4EtQb7wNj3WRv+v/7dgrm9YYgbQ/o1M3Cd7/ pNtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705961747; x=1706566547; 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=WX7OqCyKznH6Xg+YgqFqeDU+3oQq1TVExI/mQG8+wFY=; b=Hy8jokd2rwbZQ5WlZxygxC31PQyiLA6ZJkp7qxTjmeFWxHalioGQYPJDYKcuc97xyI xJCsktyY8ScpeiKTLvaCmicOpO+M3pr4XxlrSrEONPXmGIbI5IaX+LBXv9h62g2iIM3A A0VmWwbkjIcyTbD5pMcU7roIPfssgDrlu08gPvY85Z597BnvSTpX2LW1811nU34j5Vfv NxuN3NySgnAhQq/iQBdfxghtq7qkP3heKyDV/8EAaHpEPgJcVRk1tlLB4xVcrWmh/jP+ ltbMuBGHLEqs+Tl21k+trELJG4DYq1fIDnokEgy7KeSUOW8v8wblcRl6TtAYp4ErTU04 nccA== X-Gm-Message-State: AOJu0YykA/4FqB8p/O3+UPn1c8rqVQFeuRfFKmxnVW1fgrswqP6tb9wC fDz1vXuJEKrA3fDolDn5KfGRiinFN7efDasQmxEkg4qoWIbIZx5EdyZBEQyMH4Vglbqhaa690uB d X-Google-Smtp-Source: AGHT+IEUeRkhNeTWUoJFpnmdmj8HsTlZKD7bvdHdJHpp/3Cnr9klbj89tzwsW2Rk0d76hZHPblV3uQ== X-Received: by 2002:a17:903:2348:b0:1d7:600c:cc3b with SMTP id c8-20020a170903234800b001d7600ccc3bmr1352388plh.22.1705961746992; Mon, 22 Jan 2024 14:15:46 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH 4/7] hw/riscv/virt.c: use g_autofree in create_fdt_sockets() Date: Mon, 22 Jan 2024 19:15:26 -0300 Message-ID: <20240122221529.86562-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122221529.86562-1-dbarboza@ventanamicro.com> References: <20240122221529.86562-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::632; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x632.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, T_SCC_BODY_TEXT_LINE=-0.01 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 @ventanamicro.com) X-ZM-MESSAGEID: 1705961825967100005 Content-Type: text/plain; charset="utf-8" Move 'clust_name' inside the loop, and g_autofree, to avoid having to g_free() manually in each loop iteration. 'intc_phandles' is also g_autofreed to avoid another manual g_free(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 373b1dd96b..d0f402e0d5 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -721,11 +721,11 @@ static void create_fdt_sockets(RISCVVirtState *s, con= st MemMapEntry *memmap, uint32_t *irq_virtio_phandle, uint32_t *msi_pcie_phandle) { - char *clust_name; int socket, phandle_pos; MachineState *ms =3D MACHINE(s); uint32_t msi_m_phandle =3D 0, msi_s_phandle =3D 0; - uint32_t *intc_phandles, xplic_phandles[MAX_NODES]; + uint32_t xplic_phandles[MAX_NODES]; + g_autofree uint32_t *intc_phandles =3D NULL; int socket_count =3D riscv_socket_count(ms); =20 qemu_fdt_add_subnode(ms->fdt, "/cpus"); @@ -739,6 +739,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const= MemMapEntry *memmap, =20 phandle_pos =3D ms->smp.cpus; for (socket =3D (socket_count - 1); socket >=3D 0; socket--) { + g_autofree char *clust_name =3D NULL; phandle_pos -=3D s->soc[socket].num_harts; =20 clust_name =3D g_strdup_printf("/cpus/cpu-map/cluster%d", socket); @@ -749,8 +750,6 @@ static void create_fdt_sockets(RISCVVirtState *s, const= MemMapEntry *memmap, =20 create_fdt_socket_memory(s, memmap, socket); =20 - g_free(clust_name); - if (tcg_enabled()) { if (s->have_aclint) { create_fdt_socket_aclint(s, memmap, socket, @@ -793,8 +792,6 @@ static void create_fdt_sockets(RISCVVirtState *s, const= MemMapEntry *memmap, } } =20 - g_free(intc_phandles); - if (kvm_enabled() && virt_use_kvm_aia(s)) { *irq_mmio_phandle =3D xplic_phandles[0]; *irq_virtio_phandle =3D xplic_phandles[0]; --=20 2.43.0 From nobody Tue Nov 26 17:24:36 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1705961868; cv=none; d=zohomail.com; s=zohoarc; b=SVkvg6hedvSqPpgAuCqlB1jz9faqH3peRBjZwhMqJHjp3mzdQRioNvWZ7oLzWMhrtTntzEOf1K6oQC6NdO4VXaBI/+xksD8eMokYohne7RIEcVK+k7iwTh3eQd7bUG5aQItFMElZB1sdXu92ITpGB8+dgM/V+UyGzKahuuKvoFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705961868; h=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=Tl3iidZgjm5uEUrZPE7oR27Prvw+PS6Pb1oSe3v2DTM=; b=UIaDgOlMN/ryfrdKE4YSSy0g16iUzzmmxkJTNB7dM84bkHdxpae268OowAR7ksYZC3cXiCYCANbVIFZZV+QELRZoB/2/w2SZ1Lp3FoGSj76Cn9GJ8UEn9kmXOZJroZTIMHMFDlpYKEQPqqK5Xg+k1fBHDbUSnob98iGfksgn/Kg= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705961868901609.8143837737891; Mon, 22 Jan 2024 14:17:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rS2aV-0004uC-2W; Mon, 22 Jan 2024 17:16:15 -0500 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 1rS2a9-0004p6-7M for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:53 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rS2a7-0005w6-NV for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:52 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d427518d52so26158425ad.0 for ; Mon, 22 Jan 2024 14:15:51 -0800 (PST) Received: from grind.. ([152.234.127.94]) by smtp.gmail.com with ESMTPSA id kr8-20020a170903080800b001d7338977e6sm4029104plb.223.2024.01.22.14.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:15:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705961750; x=1706566550; 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=Tl3iidZgjm5uEUrZPE7oR27Prvw+PS6Pb1oSe3v2DTM=; b=fny2502EBEYBNIotWtX55pXsRk2Kj091R2tt8JW8jT5M4EI/tYVX80P8BLPzfw98YY YyKJdSE61Q0YW7WK0WfD/ja4TW6Ar8VoufNB5KcUKqT0b0/s7ZjWCbHrdipsSrOyG+CO T0IeDHRiv+Zbh3LyvIPoqMxMOUs++4R1HeRuyJgUyKtN8h4OQtbZ/Vhk0F4oQAxbyo0q OlCVTZWOJjySHOvjkE59BNMvvwvqpUm5JvnmYi5mPFZtvgsgiFhzAeYmnFrS1hCbaStL bSA2smNZ1rSsLtBAPFzE2Kr6A9r/wGt4CORXT51Es3g6mOm1qzG0EjzeCmurHfASvqj9 t3JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705961750; x=1706566550; 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=Tl3iidZgjm5uEUrZPE7oR27Prvw+PS6Pb1oSe3v2DTM=; b=JIHwHdS4U0deC8KUN1CIJxHf7lwoHywdHzib03Fwy9+TLJe0J83gaDsSOTBJvyFy3G XB6kEZ3bH6ubC4QNSAXGfEOK5ltDVviYRxIIzdBfZxi7SkxIiF+wnTm/0IRk3ZNSMdRm Pqnlb+rbq8IfabpsGd03WB8PwOcAgx8o6x9Mva0RSE59WAQ6btHVFG6BwgQaCaH7rqTz M42MxZ4OiTEv1Omf4GtGVC+Xj31K7dzQslawpo6RFQSAt4gIqGsWdUQxDzcTXIpUrZFy X6KH6trLyqovRyWg3uJqk5imdKBwngmGgomHU5QG1dWHW4mtFqmcPXh9NcuWAIZuwEoW L5dg== X-Gm-Message-State: AOJu0YyEzT7Fajfgpy4TGPupROXTpZzY6/UqEUGXYfq+Y3i0LIJZy649 218Ui5hWFUvRmGc++WKyeTqq6eep3CMMOKWeBDLUBTyWGnKxgp0OUg3tEYZR6LeSnVZJubUDUI3 c X-Google-Smtp-Source: AGHT+IFTubjT+ymld5oYADRNI6PHZvq3wRXwLJIkc9RKEpt/d8MF1EnLxtH8niY6OI2be6JsE8Q3oQ== X-Received: by 2002:a17:902:fe0c:b0:1d3:8bf1:9add with SMTP id g12-20020a170902fe0c00b001d38bf19addmr6561079plj.36.1705961749971; Mon, 22 Jan 2024 14:15:49 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH 5/7] hw/riscv/virt.c: use g_autofree in create_fdt_virtio() Date: Mon, 22 Jan 2024 19:15:27 -0300 Message-ID: <20240122221529.86562-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122221529.86562-1-dbarboza@ventanamicro.com> References: <20240122221529.86562-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::62d; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62d.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, T_SCC_BODY_TEXT_LINE=-0.01 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 @ventanamicro.com) X-ZM-MESSAGEID: 1705961870210100001 Content-Type: text/plain; charset="utf-8" Put 'name' declaration inside the loop, with g_autofree, to avoid manually doing g_free() in each iteration. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/riscv/virt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index d0f402e0d5..f8278df83f 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -820,12 +820,12 @@ static void create_fdt_virtio(RISCVVirtState *s, cons= t MemMapEntry *memmap, uint32_t irq_virtio_phandle) { int i; - char *name; MachineState *ms =3D MACHINE(s); =20 for (i =3D 0; i < VIRTIO_COUNT; i++) { - name =3D g_strdup_printf("/soc/virtio_mmio@%lx", + g_autofree char *name =3D g_strdup_printf("/soc/virtio_mmio@%lx", (long)(memmap[VIRT_VIRTIO].base + i * memmap[VIRT_VIRTIO].size= )); + qemu_fdt_add_subnode(ms->fdt, name); qemu_fdt_setprop_string(ms->fdt, name, "compatible", "virtio,mmio"= ); qemu_fdt_setprop_cells(ms->fdt, name, "reg", @@ -840,7 +840,6 @@ static void create_fdt_virtio(RISCVVirtState *s, const = MemMapEntry *memmap, qemu_fdt_setprop_cells(ms->fdt, name, "interrupts", VIRTIO_IRQ + i, 0x4); } - g_free(name); } } =20 --=20 2.43.0 From nobody Tue Nov 26 17:24:36 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1705961870; cv=none; d=zohomail.com; s=zohoarc; b=KBGL1rhzFGVLsjFuaWwlZWde1FEexG2iUFGAh7aXmkp5wncEAAPmv/s+xgKkajQgk+DYU2MWKtBNlV9P2FtjYLt/M4nwNX463ghuoTrdbO9fdkqJV3+fLDkfsgbwJVPjOrxenBK42SdZMyTTUmn2vhSZw6OQho4joCqEQ21VaOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705961870; h=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=O5iJeKaMhSSEIURROwKDqU58ZqHVR0g4H9L7rGUnf5Q=; b=HQwfgKzRRt0YpOIEAkrnL4wwRgshX2Zes6siJAo4/LABbpS/0VlHMhGvTPS1rMoNirVGRu91yI1ewrWY8CE3aOqjrcNlOAtKAvbOUHbZBHlHNtsSq1ERPnletBEYD2l8u9BlGWMRLJGHAjyhfWF8Izb3asfJ6um/wUzyAul2O6U= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705961870356795.8551650170722; Mon, 22 Jan 2024 14:17:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rS2aV-0004vC-R9; Mon, 22 Jan 2024 17:16:15 -0500 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 1rS2aE-0004qS-Tt for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:59 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rS2aC-0005xF-54 for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:15:58 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d731314e67so7136745ad.1 for ; Mon, 22 Jan 2024 14:15:55 -0800 (PST) Received: from grind.. ([152.234.127.94]) by smtp.gmail.com with ESMTPSA id kr8-20020a170903080800b001d7338977e6sm4029104plb.223.2024.01.22.14.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705961753; x=1706566553; 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=O5iJeKaMhSSEIURROwKDqU58ZqHVR0g4H9L7rGUnf5Q=; b=k0uRMoN8RNswmdViYjzorjlyt3qLglxbB7ZxFzephDbRYFp1hPLJXlcVXLlxCzXxgD dRVb4hZc3IXYj6hh/rwQPCoX/6AKQFtiwGy43JCiOLtRHM0/e9y/NppT7HXCODJsJxNf H5W817r1nXsoCguDrDEhfb4NUUG8NtPAKevyE5cjoVlF3f6c6fyga75pdWXf316AOltv Rs2V37EXSSpSBf+9mhW+8ZUvsqpM8df0CNFVfzJGPxJRAYcs5W/yA/0wuB9PoEtm4f9U 8INhfeK5jJwbObTAFfLy3DqtmJ5hIlK9bstAiCQYAekO8JcOGsI7efNjRz93Z9kGw2Bz LjJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705961753; x=1706566553; 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=O5iJeKaMhSSEIURROwKDqU58ZqHVR0g4H9L7rGUnf5Q=; b=MKLKkC+TjZPCnYdnQALaofzxL2WuumvK6EsOBfa2XQIIEK3uMX8hevIetXR9cXCPvV fGeW5uBTGH8Ib0qZjHLB3p/Us0FQIRECA+5FiGPo8aMxsecVDv/NmRsQXeqCpGm/je0m Qn9fvUWk60+3HzWHeTZRDZsUIU06KUwJc2NjiXXjt/VGDrFsc9uYHBxkmWnbzcGnS1vg LkssT+gHy6N7/TJ4Y28UOcDFTkhWIUtG9qB6HcpVbaG2cl6WuhsElQnV6tt6KqynDrfl 4Q7auuzyc3MafK3XLb9v0T5TJnyGv6gNfgzIhBFD1jSvhMo3qWNMmJchmREXWKwYVbjA Hbnw== X-Gm-Message-State: AOJu0YxbynXvzZchDm8SUJP9d2UzOJGrlOmXvLcxfHK8AT5wRkn92Yv0 hQQ9gekNqt7s4SrD2VJii/Q1pMlIrR6JVZLJAPYG4N1bNGVuZVSfasJorvaqhrE5BoKsDkKpRhP 0 X-Google-Smtp-Source: AGHT+IHgf6blRaPvZqSH7SYMlfoiOcbAG7XmobK3zlocwbsM3KDDWm48s0i73fH4i0VKNNhktSCMRA== X-Received: by 2002:a17:903:3305:b0:1d5:e313:8380 with SMTP id jk5-20020a170903330500b001d5e3138380mr2025694plb.2.1705961753222; Mon, 22 Jan 2024 14:15:53 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH 6/7] hw/riscv/virt.c: use g_autofree in virt_machine_init() Date: Mon, 22 Jan 2024 19:15:28 -0300 Message-ID: <20240122221529.86562-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122221529.86562-1-dbarboza@ventanamicro.com> References: <20240122221529.86562-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::630; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x630.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, T_SCC_BODY_TEXT_LINE=-0.01 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 @ventanamicro.com) X-ZM-MESSAGEID: 1705961872211100005 Content-Type: text/plain; charset="utf-8" Move 'soc_name' to the loop, and give it g_autofree, to avoid the manual g_free(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/riscv/virt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index f8278df83f..710fbbda2c 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1356,7 +1356,6 @@ static void virt_machine_init(MachineState *machine) RISCVVirtState *s =3D RISCV_VIRT_MACHINE(machine); MemoryRegion *system_memory =3D get_system_memory(); MemoryRegion *mask_rom =3D g_new(MemoryRegion, 1); - char *soc_name; DeviceState *mmio_irqchip, *virtio_irqchip, *pcie_irqchip; int i, base_hartid, hart_count; int socket_count =3D riscv_socket_count(machine); @@ -1376,6 +1375,8 @@ static void virt_machine_init(MachineState *machine) /* Initialize sockets */ mmio_irqchip =3D virtio_irqchip =3D pcie_irqchip =3D NULL; for (i =3D 0; i < socket_count; i++) { + g_autofree char *soc_name =3D g_strdup_printf("soc%d", i); + if (!riscv_socket_check_hartids(machine, i)) { error_report("discontinuous hartids in socket%d", i); exit(1); @@ -1393,10 +1394,8 @@ static void virt_machine_init(MachineState *machine) exit(1); } =20 - soc_name =3D g_strdup_printf("soc%d", i); object_initialize_child(OBJECT(machine), soc_name, &s->soc[i], TYPE_RISCV_HART_ARRAY); - g_free(soc_name); object_property_set_str(OBJECT(&s->soc[i]), "cpu-type", machine->cpu_type, &error_abort); object_property_set_int(OBJECT(&s->soc[i]), "hartid-base", --=20 2.43.0 From nobody Tue Nov 26 17:24:36 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1705961836; cv=none; d=zohomail.com; s=zohoarc; b=N5qHTNSB/pfvBZKO2sCob8XWSNn/JrbAECV29RGox5Pk/0CmVoQ1BKtRbxYWLARE0DSr+6IKDNGXiT0iVm0uQyyaKBb2nEk3XyRee+0iHf1x4M+Z13QvNlNW1fy5laNHBV8OAIRhNO5ycjWXKPreskeSp+g9a6tAMNSNkfZeZ4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705961836; h=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=f1lfnOL/zskZ9L7ddbkt+DFlYPrXC723I051S4uA0mA=; b=UbeDNZAuIldydhnqB1wXbdddyEL0oHApLbCV36YtgZjylfxMxf7DLfCOUbjJfUS3esyGG4r7ubQc45DOUGSIIv8O5gRNX4glii7fp7gVjea5Z6YfLoW7y9Tk/KZB/Y6SG6oCd6QJtbJdXv34MZKUMif3O9V3jzvGZKrBx8PiEXo= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705961836283226.33434985887197; Mon, 22 Jan 2024 14:17:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rS2aU-0004tn-Sn; Mon, 22 Jan 2024 17:16:14 -0500 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 1rS2aH-0004r3-8s for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:16:02 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rS2aF-0005xu-8t for qemu-devel@nongnu.org; Mon, 22 Jan 2024 17:16:01 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1d73066880eso18253345ad.3 for ; Mon, 22 Jan 2024 14:15:58 -0800 (PST) Received: from grind.. ([152.234.127.94]) by smtp.gmail.com with ESMTPSA id kr8-20020a170903080800b001d7338977e6sm4029104plb.223.2024.01.22.14.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:15:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1705961757; x=1706566557; 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=f1lfnOL/zskZ9L7ddbkt+DFlYPrXC723I051S4uA0mA=; b=gXH/37ztO/gFUm3T1Xo+NYlCwRYg3ljPDkoYYiiTS/NHSghCNCk6nBpJzu6/w6hOIN y2af6rH/4EMpN8MWzvo4I410w+akDAf/9JV6ThGasAUWX9akqcMJdMprfSt6Cjtnls3o wKyVMKsky4rv19q2WFF1vtasvUEJ9IJ4JI6LWpGcobbL0HsO/dPnFI3FYMqEvVtWlfbU V8qPcvJULa70pg0SmcunNOTEGN0QHRvjMxD2m+B8HRlnxO6f3H3OVbzWbaNTaPiRuWPP S6C4NOKeiRPhEOAV9ETSVffmbyG6GGAdfpQzJz5+682shoigucmupXZFToncFeEYVCnq Xf4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705961757; x=1706566557; 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=f1lfnOL/zskZ9L7ddbkt+DFlYPrXC723I051S4uA0mA=; b=hC0r6DSlFddpWXYq7y63aUmEdu3Q7ugiTUjjuVJZ6LxVpvRBH1EsA9WS/tcbYggr8o A+h84d2zdyct7QwAzNpSbFTZdDWEl5VZlUT6R5NIvULJASY/Zhek27qS/QiK4/2BQRjW yYWOrBNB3n8gQNMf//iJw2KT9EgjX7c+9t7tqjTE5WYP/xOGPxWvuOcz4YicaRtXMeer khQFfQHB1Y9aLmVEY+QkqjY4ZcsQVZjVH0x/NUTbpbpqDw5f6FdABMiOCPadu1GXUmfH uyC/gd0O/JayCG+J0aGiPp+DYVu2KZLrqN8OJ48+H3B6/CyKz+nlLQPs3l/RclGPthe9 SZpQ== X-Gm-Message-State: AOJu0Yyjcb35PuMOCLTSA1hbJOqcltJFI9K+qHp2au2zbE3q+37XhFqC nHy5XcbjtYPR6EULrx8GUyX/4JbKlTSQk6etCFaV7nBhHKUZHyrJsNwX82jFuTcnsbVEzPIFAkm Z X-Google-Smtp-Source: AGHT+IH81WuBt5nftvnWT2Qn+XhLB/OfG5He9bjn4SlTZRpuADtk9FmWOBaB/o7RGWjY1YHFA+5HKQ== X-Received: by 2002:a17:902:c948:b0:1d6:fb10:7430 with SMTP id i8-20020a170902c94800b001d6fb107430mr6719009pla.113.1705961756863; Mon, 22 Jan 2024 14:15:56 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH 7/7] hw/riscv/virt.c: use g_autofree in create_fdt_* Date: Mon, 22 Jan 2024 19:15:29 -0300 Message-ID: <20240122221529.86562-8-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122221529.86562-1-dbarboza@ventanamicro.com> References: <20240122221529.86562-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::62e; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62e.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, T_FILL_THIS_FORM_SHORT=0.01, T_SCC_BODY_TEXT_LINE=-0.01 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 @ventanamicro.com) X-ZM-MESSAGEID: 1705961838131100002 Content-Type: text/plain; charset="utf-8" We have a lot of cases where a char or an uint32_t pointer is used once to alloc a string/array, read/written during the function, and then g_free() at the end. There's no pointer re-use - a single alloc, a single g_free(). Use 'g_autofree' to avoid the g_free() calls. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 78 ++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 56 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 710fbbda2c..1c257e89d2 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -285,7 +285,7 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, i= nt socket, static void create_fdt_socket_memory(RISCVVirtState *s, const MemMapEntry *memmap, int socket) { - char *mem_name; + g_autofree char *mem_name =3D NULL; uint64_t addr, size; MachineState *ms =3D MACHINE(s); =20 @@ -297,7 +297,6 @@ static void create_fdt_socket_memory(RISCVVirtState *s, addr >> 32, addr, size >> 32, size); qemu_fdt_setprop_string(ms->fdt, mem_name, "device_type", "memory"); riscv_socket_fdt_write_id(ms, mem_name, socket); - g_free(mem_name); } =20 static void create_fdt_socket_clint(RISCVVirtState *s, @@ -305,8 +304,8 @@ static void create_fdt_socket_clint(RISCVVirtState *s, uint32_t *intc_phandles) { int cpu; - char *clint_name; - uint32_t *clint_cells; + g_autofree char *clint_name =3D NULL; + g_autofree uint32_t *clint_cells =3D NULL; unsigned long clint_addr; MachineState *ms =3D MACHINE(s); static const char * const clint_compat[2] =3D { @@ -333,9 +332,6 @@ static void create_fdt_socket_clint(RISCVVirtState *s, qemu_fdt_setprop(ms->fdt, clint_name, "interrupts-extended", clint_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 4); riscv_socket_fdt_write_id(ms, clint_name, socket); - g_free(clint_name); - - g_free(clint_cells); } =20 static void create_fdt_socket_aclint(RISCVVirtState *s, @@ -346,9 +342,9 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, char *name; unsigned long addr, size; uint32_t aclint_cells_size; - uint32_t *aclint_mswi_cells; - uint32_t *aclint_sswi_cells; - uint32_t *aclint_mtimer_cells; + g_autofree uint32_t *aclint_mswi_cells =3D NULL; + g_autofree uint32_t *aclint_sswi_cells =3D NULL; + g_autofree uint32_t *aclint_mtimer_cells =3D NULL; MachineState *ms =3D MACHINE(s); =20 aclint_mswi_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 2); @@ -420,10 +416,6 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, riscv_socket_fdt_write_id(ms, name, socket); g_free(name); } - - g_free(aclint_mswi_cells); - g_free(aclint_mtimer_cells); - g_free(aclint_sswi_cells); } =20 static void create_fdt_socket_plic(RISCVVirtState *s, @@ -432,8 +424,8 @@ static void create_fdt_socket_plic(RISCVVirtState *s, uint32_t *plic_phandles) { int cpu; - char *plic_name; - uint32_t *plic_cells; + g_autofree char *plic_name =3D NULL; + g_autofree uint32_t *plic_cells; unsigned long plic_addr; MachineState *ms =3D MACHINE(s); static const char * const plic_compat[2] =3D { @@ -493,10 +485,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s, memmap[VIRT_PLATFORM_BUS].size, VIRT_PLATFORM_BUS_IRQ); } - - g_free(plic_name); - - g_free(plic_cells); } =20 uint32_t imsic_num_bits(uint32_t count) @@ -515,11 +503,12 @@ static void create_fdt_one_imsic(RISCVVirtState *s, h= waddr base_addr, bool m_mode, uint32_t imsic_guest_bits) { int cpu, socket; - char *imsic_name; + g_autofree char *imsic_name =3D NULL; MachineState *ms =3D MACHINE(s); int socket_count =3D riscv_socket_count(ms); - uint32_t imsic_max_hart_per_socket; - uint32_t *imsic_cells, *imsic_regs, imsic_addr, imsic_size; + uint32_t imsic_max_hart_per_socket, imsic_addr, imsic_size; + g_autofree uint32_t *imsic_cells =3D NULL; + g_autofree uint32_t *imsic_regs =3D NULL; =20 imsic_cells =3D g_new0(uint32_t, ms->smp.cpus * 2); imsic_regs =3D g_new0(uint32_t, socket_count * 4); @@ -571,10 +560,6 @@ static void create_fdt_one_imsic(RISCVVirtState *s, hw= addr base_addr, IMSIC_MMIO_GROUP_MIN_SHIFT); } qemu_fdt_setprop_cell(ms->fdt, imsic_name, "phandle", msi_phandle); - - g_free(imsic_name); - g_free(imsic_regs); - g_free(imsic_cells); } =20 static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, @@ -606,12 +591,10 @@ static void create_fdt_one_aplic(RISCVVirtState *s, i= nt socket, bool m_mode, int num_harts) { int cpu; - char *aplic_name; - uint32_t *aplic_cells; + g_autofree char *aplic_name =3D NULL; + g_autofree uint32_t *aplic_cells =3D g_new0(uint32_t, num_harts * 2); MachineState *ms =3D MACHINE(s); =20 - aplic_cells =3D g_new0(uint32_t, num_harts * 2); - for (cpu =3D 0; cpu < num_harts; cpu++) { aplic_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); aplic_cells[cpu * 2 + 1] =3D cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_= S_EXT); @@ -646,9 +629,6 @@ static void create_fdt_one_aplic(RISCVVirtState *s, int= socket, =20 riscv_socket_fdt_write_id(ms, aplic_name, socket); qemu_fdt_setprop_cell(ms->fdt, aplic_name, "phandle", aplic_phandle); - - g_free(aplic_name); - g_free(aplic_cells); } =20 static void create_fdt_socket_aplic(RISCVVirtState *s, @@ -660,7 +640,7 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, uint32_t *aplic_phandles, int num_harts) { - char *aplic_name; + g_autofree char *aplic_name =3D NULL; unsigned long aplic_addr; MachineState *ms =3D MACHINE(s); uint32_t aplic_m_phandle, aplic_s_phandle; @@ -695,23 +675,18 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, VIRT_PLATFORM_BUS_IRQ); } =20 - g_free(aplic_name); - aplic_phandles[socket] =3D aplic_s_phandle; } =20 static void create_fdt_pmu(RISCVVirtState *s) { - char *pmu_name; + g_autofree char *pmu_name =3D g_strdup_printf("/pmu"); MachineState *ms =3D MACHINE(s); RISCVCPU hart =3D s->soc[0].harts[0]; =20 - pmu_name =3D g_strdup_printf("/pmu"); qemu_fdt_add_subnode(ms->fdt, pmu_name); qemu_fdt_setprop_string(ms->fdt, pmu_name, "compatible", "riscv,pmu"); riscv_pmu_generate_fdt_node(ms->fdt, hart.pmu_avail_ctrs, pmu_name); - - g_free(pmu_name); } =20 static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memma= p, @@ -847,7 +822,7 @@ static void create_fdt_pcie(RISCVVirtState *s, const Me= mMapEntry *memmap, uint32_t irq_pcie_phandle, uint32_t msi_pcie_phandle) { - char *name; + g_autofree char *name =3D NULL; MachineState *ms =3D MACHINE(s); =20 name =3D g_strdup_printf("/soc/pci@%lx", @@ -881,7 +856,6 @@ static void create_fdt_pcie(RISCVVirtState *s, const Me= mMapEntry *memmap, 2, virt_high_pcie_memmap.base, 2, virt_high_pcie_memmap.size); =20 create_pcie_irq_map(s, ms->fdt, name, irq_pcie_phandle); - g_free(name); } =20 static void create_fdt_reset(RISCVVirtState *s, const MemMapEntry *memmap, @@ -928,7 +902,7 @@ static void create_fdt_reset(RISCVVirtState *s, const M= emMapEntry *memmap, static void create_fdt_uart(RISCVVirtState *s, const MemMapEntry *memmap, uint32_t irq_mmio_phandle) { - char *name; + g_autofree char *name =3D NULL; MachineState *ms =3D MACHINE(s); =20 name =3D g_strdup_printf("/soc/serial@%lx", (long)memmap[VIRT_UART0].b= ase); @@ -946,13 +920,12 @@ static void create_fdt_uart(RISCVVirtState *s, const = MemMapEntry *memmap, } =20 qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name); - g_free(name); } =20 static void create_fdt_rtc(RISCVVirtState *s, const MemMapEntry *memmap, uint32_t irq_mmio_phandle) { - char *name; + g_autofree char *name =3D NULL; MachineState *ms =3D MACHINE(s); =20 name =3D g_strdup_printf("/soc/rtc@%lx", (long)memmap[VIRT_RTC].base); @@ -968,41 +941,36 @@ static void create_fdt_rtc(RISCVVirtState *s, const M= emMapEntry *memmap, } else { qemu_fdt_setprop_cells(ms->fdt, name, "interrupts", RTC_IRQ, 0x4); } - g_free(name); } =20 static void create_fdt_flash(RISCVVirtState *s, const MemMapEntry *memmap) { - char *name; MachineState *ms =3D MACHINE(s); hwaddr flashsize =3D virt_memmap[VIRT_FLASH].size / 2; hwaddr flashbase =3D virt_memmap[VIRT_FLASH].base; + g_autofree char *name =3D g_strdup_printf("/flash@%" PRIx64, flashbase= ); =20 - name =3D g_strdup_printf("/flash@%" PRIx64, flashbase); qemu_fdt_add_subnode(ms->fdt, name); qemu_fdt_setprop_string(ms->fdt, name, "compatible", "cfi-flash"); qemu_fdt_setprop_sized_cells(ms->fdt, name, "reg", 2, flashbase, 2, flashsize, 2, flashbase + flashsize, 2, flashsize); qemu_fdt_setprop_cell(ms->fdt, name, "bank-width", 4); - g_free(name); } =20 static void create_fdt_fw_cfg(RISCVVirtState *s, const MemMapEntry *memmap) { - char *nodename; MachineState *ms =3D MACHINE(s); hwaddr base =3D memmap[VIRT_FW_CFG].base; hwaddr size =3D memmap[VIRT_FW_CFG].size; + g_autofree char *nodename =3D g_strdup_printf("/fw-cfg@%" PRIx64, base= ); =20 - nodename =3D g_strdup_printf("/fw-cfg@%" PRIx64, base); qemu_fdt_add_subnode(ms->fdt, nodename); qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "qemu,fw-cfg-mmio"); qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size); qemu_fdt_setprop(ms->fdt, nodename, "dma-coherent", NULL, 0); - g_free(nodename); } =20 static void finalize_fdt(RISCVVirtState *s) @@ -1149,7 +1117,7 @@ static DeviceState *virt_create_plic(const MemMapEntr= y *memmap, int socket, int base_hartid, int hart_count) { DeviceState *ret; - char *plic_hart_config; + g_autofree char *plic_hart_config =3D NULL; =20 /* Per-socket PLIC hart topology configuration string */ plic_hart_config =3D riscv_plic_hart_config_string(hart_count); @@ -1168,8 +1136,6 @@ static DeviceState *virt_create_plic(const MemMapEntr= y *memmap, int socket, VIRT_PLIC_CONTEXT_STRIDE, memmap[VIRT_PLIC].size); =20 - g_free(plic_hart_config); - return ret; } =20 --=20 2.43.0