From nobody Tue Nov 26 08:53:02 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=1709059896; cv=none; d=zohomail.com; s=zohoarc; b=GAN3XscrFKO5UQw2HcHtCR52rgd2zByvvIJeprdvU8EheMROBUWHdI1ojXDQbPahbwxFhCpM6+Ev4LVtZ68INmyQLLHj/7lvImfB5URBFbwIu48t0EX7lqUI+uS2QQdO3StvmXIcZvvZiLQWWdy8lozCpVrSpNpT07Ui5nlEt50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709059896; 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=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; b=LHOp4zkBgk0kHi76x5Ikm9qOnDGO3FBoO5Ufwy66xpwe+8ffmNxkn0JvF5be9GXmfl2RG6D9AeuIrkhDqr6zwg25zsMNlaUNx7D4HTLOFQPim2ObCB5X442YkwRHJ+HeDIf1jkPJxR+IDwSyqjxmxS4tAJO2yd45iKPyOM0+T5k= 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 1709059896274980.120097457609; Tue, 27 Feb 2024 10:51:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf2VR-0006WC-Jy; Tue, 27 Feb 2024 13:48:45 -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 1rf2VQ-0006VZ-4p for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:44 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rf2VO-0001T1-Dm for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:48:43 -0500 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6e4ca46ab04so2862653b3a.3 for ; Tue, 27 Feb 2024 10:48:42 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b006e555d40951sm533465pfo.188.2024.02.27.10.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709059721; x=1709664521; 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=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; b=tZKCD9EcLCeJpd6jK0rsk/Llmj4h6oZbe6kdgW7K+BDGg1KAGtyznYuZKjs9LMVTtT UOFi/z/ceoQfLg1S4U+JlnV18R6WHmhflANj1sRjUNQXsHmhvWX648AKT45ty9KrupLJ hG+O9SiHsWUxpbZes47/CTPr2rv34kjB5YSFMguxEQZGkLf8bl5AAZm0Lh47Pfp9w8xh g2/h53CBS6pP+fEG7Hf7DLGNGH0KlDyhWSHRv1hXuXvRfVueOHe8yaEdSGRFecMPB5Dz CjWkcUGcbRIo5UmH5rs8byL4YlrPTwMfcqs7b8sY3jFWCeKa0EMo/gQdOcPKX+CW8p4G 3NPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709059721; x=1709664521; 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=PXNbhyM3M1ZvaxsPU8XRtEyhAyhYazBaocnAfgHjiNM=; b=lzKJyFyt/BSZA7veABBLR2J+HmjQHIkuyQn6FByiZx+9hn2eWPScjptxI06ZWBLJy7 WQvTysdOXMHKTSqDyAtRqSo9nC7lsjbcBtw4CRh8RuEht9snJamS1DXlJWgujdNHVsyN nZ60nlJInxV17t6fiJGX0Ca5RtM1Bo8fgayu/bAPMcOvau3rIXv3DtfOl9ynHcy/QJv6 pm6f42SqpOAGy7g9kB1iDIZDxtTPyiJjihQj3qmuajhWvwtzcJEBEXHGuS+J/ydSjic4 dfhdzhW23OLqvnQYBsaBQX0pDDlNK0o8a1mk3LKCHEi96oNKyKJokv9eK6zJ7J5Z6Nln nohg== X-Gm-Message-State: AOJu0YyU33+/LNfZXjrbcrVk+kTXQNQ1U8M1q7d+RJ3Os69OxwEczHCK 8fwvceb8ZrexgywKf1+wbWyh/QE5MfvcuJpeFKEFByYW4V9I4iACXA3ZWsjPaHthvsTvV3JQAdQ / X-Google-Smtp-Source: AGHT+IF30TBkxuhs2mX9HYQ8yuqG1edE8Jc0TsI+BIaFzV3uILEv74NbmnTG0GCbyyRnDLE49XWsNg== X-Received: by 2002:a05:6a00:ce:b0:6e5:2cc9:c898 with SMTP id e14-20020a056a0000ce00b006e52cc9c898mr7190892pfj.26.1709059720912; Tue, 27 Feb 2024 10:48:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 03/14] linux-user/elfload: Tidy fill_note_info and struct elf_note_info Date: Tue, 27 Feb 2024 08:48:22 -1000 Message-Id: <20240227184833.193836-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240227184833.193836-1-richard.henderson@linaro.org> References: <20240227184833.193836-1-richard.henderson@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=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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=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: 1709059897435100003 Content-Type: text/plain; charset="utf-8" In fill_note_info, there were unnecessary checks for success of g_new/g_malloc. But these structures do not need to be dyamically allocated at all, and can in fact be statically allocated within the parent structure. This removes all error paths from fill_note_info, so change the return type to void. Change type of signr to match both caller (elf_core_dump) and callee (fill_prstatus), which both use int for signr. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 48 +++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 7b3a2c20f2..cc43487a37 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4066,10 +4066,12 @@ struct elf_thread_status { int num_notes; }; =20 +#define NUMNOTES 3 + struct elf_note_info { - struct memelfnote *notes; - struct target_elf_prstatus *prstatus; /* NT_PRSTATUS */ - struct target_elf_prpsinfo *psinfo; /* NT_PRPSINFO */ + struct memelfnote notes[NUMNOTES]; + struct target_elf_prstatus prstatus; /* NT_PRSTATUS */ + struct target_elf_prpsinfo psinfo; /* NT_PRPSINFO */ =20 QTAILQ_HEAD(, elf_thread_status) thread_list; #if 0 @@ -4117,7 +4119,7 @@ static void fill_auxv_note(struct memelfnote *, const= TaskState *); static void fill_elf_note_phdr(struct elf_phdr *, int, off_t); static size_t note_size(const struct memelfnote *); static void free_note_info(struct elf_note_info *); -static int fill_note_info(struct elf_note_info *, long, const CPUArchState= *); +static void fill_note_info(struct elf_note_info *, int, const CPUArchState= *); static void fill_thread_info(struct elf_note_info *, const CPUArchState *); =20 static int dump_write(int, const void *, size_t); @@ -4514,44 +4516,33 @@ static void fill_thread_info(struct elf_note_info *= info, const CPUArchState *env info->notes_size +=3D note_size(&ets->notes[0]); } =20 -static int fill_note_info(struct elf_note_info *info, - long signr, const CPUArchState *env) +static void fill_note_info(struct elf_note_info *info, + int signr, const CPUArchState *env) { -#define NUMNOTES 3 CPUState *cpu =3D env_cpu((CPUArchState *)env); TaskState *ts =3D (TaskState *)cpu->opaque; - int i; =20 memset(info, 0, sizeof (*info)); QTAILQ_INIT(&info->thread_list); =20 - info->notes =3D g_new0(struct memelfnote, NUMNOTES); - if (info->notes =3D=3D NULL) - return (-ENOMEM); - info->prstatus =3D g_malloc0(sizeof (*info->prstatus)); - if (info->prstatus =3D=3D NULL) - return (-ENOMEM); - info->psinfo =3D g_malloc0(sizeof (*info->psinfo)); - if (info->prstatus =3D=3D NULL) - return (-ENOMEM); - /* * First fill in status (and registers) of current thread * including process info & aux vector. */ - fill_prstatus(info->prstatus, ts, signr); - elf_core_copy_regs(&info->prstatus->pr_reg, env); + fill_prstatus(&info->prstatus, ts, signr); + elf_core_copy_regs(&info->prstatus.pr_reg, env); fill_note(&info->notes[0], "CORE", NT_PRSTATUS, - sizeof (*info->prstatus), info->prstatus); - fill_psinfo(info->psinfo, ts); + sizeof(info->prstatus), &info->prstatus); + fill_psinfo(&info->psinfo, ts); fill_note(&info->notes[1], "CORE", NT_PRPSINFO, - sizeof (*info->psinfo), info->psinfo); + sizeof(info->psinfo), &info->psinfo); fill_auxv_note(&info->notes[2], ts); info->numnote =3D 3; =20 info->notes_size =3D 0; - for (i =3D 0; i < info->numnote; i++) + for (int i =3D 0; i < info->numnote; i++) { info->notes_size +=3D note_size(&info->notes[i]); + } =20 /* read and fill status of all threads */ WITH_QEMU_LOCK_GUARD(&qemu_cpu_list_lock) { @@ -4562,8 +4553,6 @@ static int fill_note_info(struct elf_note_info *info, fill_thread_info(info, cpu_env(cpu)); } } - - return (0); } =20 static void free_note_info(struct elf_note_info *info) @@ -4575,10 +4564,6 @@ static void free_note_info(struct elf_note_info *inf= o) QTAILQ_REMOVE(&info->thread_list, ets, ets_link); g_free(ets); } - - g_free(info->prstatus); - g_free(info->psinfo); - g_free(info->notes); } =20 static int write_note_info(struct elf_note_info *info, int fd) @@ -4694,8 +4679,7 @@ static int elf_core_dump(int signr, const CPUArchStat= e *env) goto out; =20 /* fill in the in-memory version of notes */ - if (fill_note_info(&info, signr, env) < 0) - goto out; + fill_note_info(&info, signr, env); =20 offset +=3D sizeof (elf); /* elf header */ offset +=3D (segs + 1) * sizeof (struct elf_phdr); /* program heade= rs */ --=20 2.34.1