From nobody Wed Nov 27 16:58:12 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697722913; cv=none; d=zohomail.com; s=zohoarc; b=dpI1ThRgrkYRs+sWBtl64R0zVqX5NHY9lp0nNc0JD+ELk2+rHBbIt0wW/N1vrWX/yDRyJ66aiPEuA/36hQBPC4NSNbblCDBJxQ0AB0mymk8xu8hWkF9mw10PSon8z94o7SUmYT2H8fXsuyQ9pQYJa9K5jzI8QMuUTVmfODlb0/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697722913; h=Content-Transfer-Encoding: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:Cc; bh=DCEBJydvw/gsEIeAPEKmaoZZ5w+fj2mZw0RxfZs5m5s=; b=lpoO5Y53o/etVLvbYaIjS137RFbAWpOWJ1lR1VPMlV9MGsTE4qcL5gLlgDUxTGo3qm1VPPppr/uxn3N9ZZ1jHp5I+BxkoA66TSSyrLiXu1G9o2xcqlxgdG+N1qoLIgwwiOxw9gn/grKIDvkaPINNPzLZILRrSPZBN2yYJS2akT0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697722913124468.9782781570043; Thu, 19 Oct 2023 06:41:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtTCo-0003g2-NK; Thu, 19 Oct 2023 09:36:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qtTBw-0001zQ-9V for qemu-devel@nongnu.org; Thu, 19 Oct 2023 09:36:02 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtTBr-0001FG-C1 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 09:35:59 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-32ddfb38c02so244047f8f.3 for ; Thu, 19 Oct 2023 06:35:51 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id d28-20020adf9b9c000000b0031f3ad17b2csm4512690wrc.52.2023.10.19.06.35.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 06:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697722550; x=1698327350; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=DCEBJydvw/gsEIeAPEKmaoZZ5w+fj2mZw0RxfZs5m5s=; b=vnvB20EIc7tXACRVRQyE26v4LieyahC/l5ZvIlmcCES2Ig1wKXs5RT/9fl2jXnx8ld kJHjho77NZEPe7ftw9WU94e84ILQEVtwWLHOksePBwfgf8b5z7kp26/7VlPRpSn3TvGf 2TdwmjlKKYVyfMww0Xj5QFyh7tlD8opQcBP+IS9IXx+2KwUT+G1AB+wKrXyVt1GE3k4O J8MAU+fRu6gxr2FRfWFhvYbAyjApM0ErAaAoRz1YLDrzsZUj4HDglVtUkB1yjYPzUbcu WHavIvoQkwP22ZbzXep5+UqHyx57f83JqzAboGyELCZLYcwJJyRZcpnw3AKpdLSdl2lH OsfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697722550; x=1698327350; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DCEBJydvw/gsEIeAPEKmaoZZ5w+fj2mZw0RxfZs5m5s=; b=GQ4kkJ4YMvJgNasfs4e30CP8Ic7o9mEBFXIKAPnpeuqE7VAeX1g6wobv1dO7O7h+yr emgyPXfgBKPPGAupqfyW/jlmJiBBC9fXt3CvhwwP5DT842mZCZnaDL9wpElDarpy1TNF pX/GWRRSMPEuE87TguZMy1b7NhPbw8pTlZ7K/405+GK2+deEF0wekUA/oTa9Ec2qlY/r edplJl0rnoBkZTLHdZxsm8ygkTqgLl6xxwUkzM5e++bmvHCkH5IigklYscyTpLbsubRs Q2MMw+hxgOYDLYyTw0pwoQtHIENLJNnTE3f5GGxjfWfIlBi97Vt/ep47ucac1tmY8LJX X3uA== X-Gm-Message-State: AOJu0YzCEbYqZ3ZTsPwxpvcJiA3Sy8Hf+KRTEYoreaAce806Vlr0j9JU aQby0z9K93bbcuvmYEdbqp/8jekz3v7bomNC+Ts= X-Google-Smtp-Source: AGHT+IEq0/Kd87UmRG7okGKg36g3dDacarUUkSMuvCPbBaptOa+Wne0RDQLZg+XD93WXVk7o8mtg6g== X-Received: by 2002:a5d:4b48:0:b0:314:1313:c3d6 with SMTP id w8-20020a5d4b48000000b003141313c3d6mr1457635wrs.33.1697722550271; Thu, 19 Oct 2023 06:35:50 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 24/24] contrib/elf2dmp: Use g_malloc(), g_new() and g_free() Date: Thu, 19 Oct 2023 14:35:37 +0100 Message-Id: <20231019133537.2114929-25-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019133537.2114929-1-peter.maydell@linaro.org> References: <20231019133537.2114929-1-peter.maydell@linaro.org> 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=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697722915346100003 Content-Type: text/plain; charset="utf-8" From: Suraj Shirvankar QEMU coding style uses the glib memory allocation APIs, not the raw libc malloc/free. Switch the allocation and free calls in elf2dmp to use these functions (dropping the now-unneeded checks for failure). Signed-off-by: Suraj Shirvankar Message-id: 169753938460.23804.11418813007617535750-1@git.sr.ht [PMM: also remove NULL checks from g_malloc() calls; beef up commit message] Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- contrib/elf2dmp/addrspace.c | 7 ++----- contrib/elf2dmp/main.c | 9 +++------ contrib/elf2dmp/pdb.c | 19 ++++++++----------- contrib/elf2dmp/qemu_elf.c | 7 ++----- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 64b5d680adc..6f608a517b1 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -72,10 +72,7 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_= elf) } } =20 - ps->block =3D malloc(sizeof(*ps->block) * ps->block_nr); - if (!ps->block) { - return 1; - } + ps->block =3D g_new(struct pa_block, ps->block_nr); =20 for (i =3D 0; i < phdr_nr; i++) { if (phdr[i].p_type =3D=3D PT_LOAD) { @@ -97,7 +94,7 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_e= lf) void pa_space_destroy(struct pa_space *ps) { ps->block_nr =3D 0; - free(ps->block); + g_free(ps->block); } =20 void va_space_set_dtb(struct va_space *vs, uint64_t dtb) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 6de5c9808ef..cbc38a7c103 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -120,14 +120,11 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase,= struct pdb_reader *pdb, } } =20 - kdbg =3D malloc(kdbg_hdr.Size); - if (!kdbg) { - return NULL; - } + kdbg =3D g_malloc(kdbg_hdr.Size); =20 if (va_space_rw(vs, KdDebuggerDataBlock, kdbg, kdbg_hdr.Size, 0)) { eprintf("Failed to extract entire KDBG\n"); - free(kdbg); + g_free(kdbg); return NULL; } =20 @@ -643,7 +640,7 @@ int main(int argc, char *argv[]) } =20 out_kdbg: - free(kdbg); + g_free(kdbg); out_pdb: pdb_exit(&pdb); out_pdb_file: diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index 8e3c18c82f7..40991f5f4c3 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -94,18 +94,18 @@ uint64_t pdb_resolve(uint64_t img_base, struct pdb_read= er *r, const char *name) =20 static void pdb_reader_ds_exit(struct pdb_reader *r) { - free(r->ds.toc); + g_free(r->ds.toc); } =20 static void pdb_exit_symbols(struct pdb_reader *r) { - free(r->modimage); - free(r->symbols); + g_free(r->modimage); + g_free(r->symbols); } =20 static void pdb_exit_segments(struct pdb_reader *r) { - free(r->segs); + g_free(r->segs); } =20 static void *pdb_ds_read(const PDB_DS_HEADER *header, @@ -120,10 +120,7 @@ static void *pdb_ds_read(const PDB_DS_HEADER *header, =20 nBlocks =3D (size + header->block_size - 1) / header->block_size; =20 - buffer =3D malloc(nBlocks * header->block_size); - if (!buffer) { - return NULL; - } + buffer =3D g_malloc(nBlocks * header->block_size); =20 for (i =3D 0; i < nBlocks; i++) { memcpy(buffer + i * header->block_size, (const char *)header + @@ -206,7 +203,7 @@ static int pdb_init_symbols(struct pdb_reader *r) return 0; =20 out_symbols: - free(symbols); + g_free(symbols); =20 return err; } @@ -263,7 +260,7 @@ static int pdb_reader_init(struct pdb_reader *r, void *= data) out_sym: pdb_exit_symbols(r); out_root: - free(r->ds.root); + g_free(r->ds.root); out_ds: pdb_reader_ds_exit(r); =20 @@ -274,7 +271,7 @@ static void pdb_reader_exit(struct pdb_reader *r) { pdb_exit_segments(r); pdb_exit_symbols(r); - free(r->ds.root); + g_free(r->ds.root); pdb_reader_ds_exit(r); } =20 diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index de6ad744c6d..055e6f8792e 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -94,10 +94,7 @@ static int init_states(QEMU_Elf *qe) =20 printf("%zu CPU states has been found\n", cpu_nr); =20 - qe->state =3D malloc(sizeof(*qe->state) * cpu_nr); - if (!qe->state) { - return 1; - } + qe->state =3D g_new(QEMUCPUState*, cpu_nr); =20 cpu_nr =3D 0; =20 @@ -115,7 +112,7 @@ static int init_states(QEMU_Elf *qe) =20 static void exit_states(QEMU_Elf *qe) { - free(qe->state); + g_free(qe->state); } =20 static bool check_ehdr(QEMU_Elf *qe) --=20 2.34.1