From patchwork Mon Jan 22 22:15:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1889414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=i+mk8dhI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TJl2S4Cgkz1yS7 for ; Tue, 23 Jan 2024 09:17:20 +1100 (AEDT) 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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The 'isa' char pointer isn't being freed after use. Issue detected by Valgrind: ==38752== 128 bytes in 1 blocks are definitely lost in loss record 3,190 of 3,884 ==38752== at 0x484280F: malloc (vg_replace_malloc.c:442) ==38752== by 0x5189619: g_malloc (gmem.c:130) ==38752== by 0x51A5BF2: g_strconcat (gstrfuncs.c:628) ==38752== by 0x6C1E3E: riscv_isa_string_ext (cpu.c:2321) ==38752== by 0x6C1E3E: riscv_isa_string (cpu.c:2343) ==38752== by 0x6BD2EA: build_rhct (virt-acpi-build.c:232) ==38752== by 0x6BD2EA: virt_acpi_build (virt-acpi-build.c:556) ==38752== by 0x6BDC86: virt_acpi_setup (virt-acpi-build.c:662) ==38752== by 0x9C8DC6: notifier_list_notify (notify.c:39) ==38752== by 0x4A595A: qdev_machine_creation_done (machine.c:1589) ==38752== by 0x61E052: qemu_machine_creation_done (vl.c:2680) ==38752== by 0x61E052: qmp_x_exit_preconfig.part.0 (vl.c:2709) ==38752== by 0x6220C6: qmp_x_exit_preconfig (vl.c:2702) ==38752== by 0x6220C6: qemu_init (vl.c:3758) ==38752== 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 = &s->soc[0].harts[0]; uint32_t mmu_offset = 0; uint8_t satp_mode_max; - char *isa; + g_autofree char *isa = NULL; AcpiTable table = { .sig = "RHCT", .rev = 1, .oem_id = s->oem_id, .oem_table_id = s->oem_table_id }; From patchwork Mon Jan 22 22:15:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1889415 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=iuKOMvdX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TJl2q1qNTz1yS7 for ; Tue, 23 Jan 2024 09:17:39 +1100 (AEDT) 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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 = NULL; + uint32_t dist_matrix_size; if (numa_enabled(ms) && ms->numa_state->have_numa_distance) { dist_matrix_size = riscv_socket_count(ms) * riscv_socket_count(ms); @@ -189,7 +190,6 @@ void riscv_socket_fdt_write_distance_matrix(const MachineState *ms) "numa-distance-map-v1"); qemu_fdt_setprop(ms->fdt, "/distance-map", "distance-matrix", dist_matrix, dist_matrix_size); - g_free(dist_matrix); } } From patchwork Mon Jan 22 22:15:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1889410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=lp7lBg0K; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TJl291wz3z1yS7 for ; Tue, 23 Jan 2024 09:17:04 +1100 (AEDT) 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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis --- 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 = MACHINE(s); - char *name, *cpu_name, *core_name, *intc_name, *sv_name; bool is_32_bit = riscv_is_32bit(&s->soc[0]); uint8_t satp_mode_max; for (cpu = s->soc[socket].num_harts - 1; cpu >= 0; cpu--) { RISCVCPU *cpu_ptr = &s->soc[socket].harts[cpu]; + g_autofree char *name = NULL; + g_autofree char *cpu_name = NULL; + g_autofree char *core_name = NULL; + g_autofree char *intc_name = NULL; + g_autofree char *sv_name = NULL; cpu_phandle = (*phandle)++; @@ -233,12 +237,10 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, sv_name = g_strdup_printf("riscv,%s", satp_mode_str(satp_mode_max, is_32_bit)); qemu_fdt_setprop_string(ms->fdt, cpu_name, "mmu-type", sv_name); - g_free(sv_name); } name = riscv_isa_string(cpu_ptr); qemu_fdt_setprop_string(ms->fdt, cpu_name, "riscv,isa", name); - g_free(name); if (cpu_ptr->cfg.ext_zicbom) { qemu_fdt_setprop_cell(ms->fdt, cpu_name, "riscv,cbom-block-size", @@ -277,10 +279,6 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, core_name = 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); } } From patchwork Mon Jan 22 22:15:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1889411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=dh0pyy1S; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TJl291zD5z23g0 for ; Tue, 23 Jan 2024 09:17:04 +1100 (AEDT) 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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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, const MemMapEntry *memmap, uint32_t *irq_virtio_phandle, uint32_t *msi_pcie_phandle) { - char *clust_name; int socket, phandle_pos; MachineState *ms = MACHINE(s); uint32_t msi_m_phandle = 0, msi_s_phandle = 0; - uint32_t *intc_phandles, xplic_phandles[MAX_NODES]; + uint32_t xplic_phandles[MAX_NODES]; + g_autofree uint32_t *intc_phandles = NULL; int socket_count = riscv_socket_count(ms); qemu_fdt_add_subnode(ms->fdt, "/cpus"); @@ -739,6 +739,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, phandle_pos = ms->smp.cpus; for (socket = (socket_count - 1); socket >= 0; socket--) { + g_autofree char *clust_name = NULL; phandle_pos -= s->soc[socket].num_harts; clust_name = g_strdup_printf("/cpus/cpu-map/cluster%d", socket); @@ -749,8 +750,6 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, create_fdt_socket_memory(s, memmap, socket); - 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, } } - g_free(intc_phandles); - if (kvm_enabled() && virt_use_kvm_aia(s)) { *irq_mmio_phandle = xplic_phandles[0]; *irq_virtio_phandle = xplic_phandles[0]; From patchwork Mon Jan 22 22:15:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1889416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=fny2502E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TJl315c0lz1yS7 for ; Tue, 23 Jan 2024 09:17:49 +1100 (AEDT) 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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis --- 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, const MemMapEntry *memmap, uint32_t irq_virtio_phandle) { int i; - char *name; MachineState *ms = MACHINE(s); for (i = 0; i < VIRTIO_COUNT; i++) { - name = g_strdup_printf("/soc/virtio_mmio@%lx", + g_autofree char *name = 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); } } From patchwork Mon Jan 22 22:15:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1889417 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=k0uRMoN8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TJl3321Sbz1yS7 for ; Tue, 23 Jan 2024 09:17:51 +1100 (AEDT) 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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis --- 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 = RISCV_VIRT_MACHINE(machine); MemoryRegion *system_memory = get_system_memory(); MemoryRegion *mask_rom = g_new(MemoryRegion, 1); - char *soc_name; DeviceState *mmio_irqchip, *virtio_irqchip, *pcie_irqchip; int i, base_hartid, hart_count; int socket_count = riscv_socket_count(machine); @@ -1376,6 +1375,8 @@ static void virt_machine_init(MachineState *machine) /* Initialize sockets */ mmio_irqchip = virtio_irqchip = pcie_irqchip = NULL; for (i = 0; i < socket_count; i++) { + g_autofree char *soc_name = 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); } - soc_name = 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", From patchwork Mon Jan 22 22:15:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1889413 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=gXH/37zt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TJl2P1mSTz23g0 for ; Tue, 23 Jan 2024 09:17:17 +1100 (AEDT) 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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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, int socket, static void create_fdt_socket_memory(RISCVVirtState *s, const MemMapEntry *memmap, int socket) { - char *mem_name; + g_autofree char *mem_name = NULL; uint64_t addr, size; MachineState *ms = MACHINE(s); @@ -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); } 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 = NULL; + g_autofree uint32_t *clint_cells = NULL; unsigned long clint_addr; MachineState *ms = MACHINE(s); static const char * const clint_compat[2] = { @@ -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); } 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 = NULL; + g_autofree uint32_t *aclint_sswi_cells = NULL; + g_autofree uint32_t *aclint_mtimer_cells = NULL; MachineState *ms = MACHINE(s); aclint_mswi_cells = 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); } 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 = NULL; + g_autofree uint32_t *plic_cells; unsigned long plic_addr; MachineState *ms = MACHINE(s); static const char * const plic_compat[2] = { @@ -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); } uint32_t imsic_num_bits(uint32_t count) @@ -515,11 +503,12 @@ static void create_fdt_one_imsic(RISCVVirtState *s, hwaddr base_addr, bool m_mode, uint32_t imsic_guest_bits) { int cpu, socket; - char *imsic_name; + g_autofree char *imsic_name = NULL; MachineState *ms = MACHINE(s); int socket_count = 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 = NULL; + g_autofree uint32_t *imsic_regs = NULL; imsic_cells = g_new0(uint32_t, ms->smp.cpus * 2); imsic_regs = g_new0(uint32_t, socket_count * 4); @@ -571,10 +560,6 @@ static void create_fdt_one_imsic(RISCVVirtState *s, hwaddr 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); } static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, @@ -606,12 +591,10 @@ static void create_fdt_one_aplic(RISCVVirtState *s, int socket, bool m_mode, int num_harts) { int cpu; - char *aplic_name; - uint32_t *aplic_cells; + g_autofree char *aplic_name = NULL; + g_autofree uint32_t *aplic_cells = g_new0(uint32_t, num_harts * 2); MachineState *ms = MACHINE(s); - aplic_cells = g_new0(uint32_t, num_harts * 2); - for (cpu = 0; cpu < num_harts; cpu++) { aplic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); aplic_cells[cpu * 2 + 1] = 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, 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); } 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 = NULL; unsigned long aplic_addr; MachineState *ms = 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); } - g_free(aplic_name); - aplic_phandles[socket] = aplic_s_phandle; } static void create_fdt_pmu(RISCVVirtState *s) { - char *pmu_name; + g_autofree char *pmu_name = g_strdup_printf("/pmu"); MachineState *ms = MACHINE(s); RISCVCPU hart = s->soc[0].harts[0]; - pmu_name = 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); } static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, @@ -847,7 +822,7 @@ static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, uint32_t irq_pcie_phandle, uint32_t msi_pcie_phandle) { - char *name; + g_autofree char *name = NULL; MachineState *ms = MACHINE(s); name = g_strdup_printf("/soc/pci@%lx", @@ -881,7 +856,6 @@ static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, 2, virt_high_pcie_memmap.base, 2, virt_high_pcie_memmap.size); create_pcie_irq_map(s, ms->fdt, name, irq_pcie_phandle); - g_free(name); } static void create_fdt_reset(RISCVVirtState *s, const MemMapEntry *memmap, @@ -928,7 +902,7 @@ static void create_fdt_reset(RISCVVirtState *s, const MemMapEntry *memmap, static void create_fdt_uart(RISCVVirtState *s, const MemMapEntry *memmap, uint32_t irq_mmio_phandle) { - char *name; + g_autofree char *name = NULL; MachineState *ms = MACHINE(s); name = g_strdup_printf("/soc/serial@%lx", (long)memmap[VIRT_UART0].base); @@ -946,13 +920,12 @@ static void create_fdt_uart(RISCVVirtState *s, const MemMapEntry *memmap, } qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", name); - g_free(name); } static void create_fdt_rtc(RISCVVirtState *s, const MemMapEntry *memmap, uint32_t irq_mmio_phandle) { - char *name; + g_autofree char *name = NULL; MachineState *ms = MACHINE(s); name = g_strdup_printf("/soc/rtc@%lx", (long)memmap[VIRT_RTC].base); @@ -968,41 +941,36 @@ static void create_fdt_rtc(RISCVVirtState *s, const MemMapEntry *memmap, } else { qemu_fdt_setprop_cells(ms->fdt, name, "interrupts", RTC_IRQ, 0x4); } - g_free(name); } static void create_fdt_flash(RISCVVirtState *s, const MemMapEntry *memmap) { - char *name; MachineState *ms = MACHINE(s); hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2; hwaddr flashbase = virt_memmap[VIRT_FLASH].base; + g_autofree char *name = g_strdup_printf("/flash@%" PRIx64, flashbase); - name = 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); } static void create_fdt_fw_cfg(RISCVVirtState *s, const MemMapEntry *memmap) { - char *nodename; MachineState *ms = MACHINE(s); hwaddr base = memmap[VIRT_FW_CFG].base; hwaddr size = memmap[VIRT_FW_CFG].size; + g_autofree char *nodename = g_strdup_printf("/fw-cfg@%" PRIx64, base); - nodename = 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); } static void finalize_fdt(RISCVVirtState *s) @@ -1149,7 +1117,7 @@ static DeviceState *virt_create_plic(const MemMapEntry *memmap, int socket, int base_hartid, int hart_count) { DeviceState *ret; - char *plic_hart_config; + g_autofree char *plic_hart_config = NULL; /* Per-socket PLIC hart topology configuration string */ plic_hart_config = riscv_plic_hart_config_string(hart_count); @@ -1168,8 +1136,6 @@ static DeviceState *virt_create_plic(const MemMapEntry *memmap, int socket, VIRT_PLIC_CONTEXT_STRIDE, memmap[VIRT_PLIC].size); - g_free(plic_hart_config); - return ret; }