From nobody Tue Nov 26 06:45: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 ARC-Seal: i=1; a=rsa-sha256; t=1709705826; cv=none; d=zohomail.com; s=zohoarc; b=jaBw2n6W18LENdrQ7gocbLeRdYGPx/AOBtfVCtdwAyoVL4SsP5YszpZzhIJnd5hP7eETkvY9oOAEEe8H3ufPcWYYWXgd51xbSu+a2N3actNebpy43G9a7SbsfzznAtkHlgIwHF7pbtB6IOYhUx+uTw/nOl6Ms1VwJIZhP6DnH0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705826; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=g0+eTNzDAfP/I8pMSpLdPirrAbqQUuAszFkDupkQLY8=; b=PbPumNTtuSQUVJ3mID5mcylnbz5WixajiP4nS0TQY2CURECchASOWzoHebg9cD5s06/0XuVgT7XODYJIUOx8D2ZDo2S6kqAZoQzbixA+g3gaCq/0g8zQ1Jplhw/eRRdluXqHfEU1FVqyUcSORGRxZmd3Q46hj/xH5JEBfzfQmsM= 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 1709705826033927.4544159439163; Tue, 5 Mar 2024 22:17:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWJ-0004yT-Hh; Wed, 06 Mar 2024 01:12:51 -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 1rhkW8-0004ug-JH for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:40 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkW6-0006Fw-Sb for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:40 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dc3b4b9b62so4130215ad.1 for ; Tue, 05 Mar 2024 22:12:38 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id z3-20020a170902708300b001dcc0d06959sm11598502plk.245.2024.03.05.22.12.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705557; x=1710310357; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=g0+eTNzDAfP/I8pMSpLdPirrAbqQUuAszFkDupkQLY8=; b=i/8c8RhlncBkFKQClT6JXGGPFAU9mOZK0f2Mgf+RDz+HGV34ItR4NGrs5JSc+5J3Cd EaQuRXtCWRASZI9/Vv8I/FE2HWMP0yHMvsIptCpyWtzDrgBNXCuy2ZGhIzgitCx4Js+7 AJrR3AqvV9JtmYIqgIShOPVftJLLcQT/eb0O7ZJNx8KCv0K8fNDo92O0E/hMtKSyUk62 wM0jSZ+yj6grhif2W8YjypWoB9KuaioS4oNa1dATtBxgQI4A+G5wio3sl7Ued/cTukOA jaMr+tXq9YCOH+A/xWN14iHqbRjy0cWPydmJb96DNMEWcwpsI0qEmNLK1JnDPb374I+R LolQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705557; x=1710310357; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g0+eTNzDAfP/I8pMSpLdPirrAbqQUuAszFkDupkQLY8=; b=e4PgjZDJuBEslITeOPVqYkz9de4T0fVcXUIrJs+pNvkHqS4M4yUoWnXBdd3gpPKAtm PWbJDcc8XluFynrJ9AtLtDcZDQzomtCwl8tR/IYog+3OEKDxSldohPL6lAbnFLbKiYKo +/CvSomuOVpEvbvX9vtjk7FHZlGqeeKkvZTEKTV8Po+NU0LSOrFy1BqAuYDtnGhTRq9f wWUPpmkYWALBHKzV0lQfslOfj0OGSjFk3yNwBEQGnfmdXlPMlfUoqCJboqtRnQmUEML9 BqXVFB20rwEsXAXJrmRIJ+i9RkQiGP8qXRTs1xJ0oZXyzB59h2wysbIuDRwzTI6Vv6Sw zhPw== X-Gm-Message-State: AOJu0YyA55iFWFcpWJehq+tXJReFyUYdbrDkmfSkbUK8Sb0VFDPQdZAA eg3L+XS8LZZWLsQXXvqRz3ed/1BYNMZ4PGeMywKI/EvgEkRAEarizW6r6gux6Kc= X-Google-Smtp-Source: AGHT+IHbM2F+BRdhsU+fa3EHe9K3ovl/QnbPrj4jXua0I4f0FoAjjkmltm2aRhioi7iMJ3BnaLDQDQ== X-Received: by 2002:a17:903:2594:b0:1db:dd24:9962 with SMTP id jb20-20020a170903259400b001dbdd249962mr4412087plb.21.1709705557499; Tue, 05 Mar 2024 22:12:37 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:14 +0900 Subject: [PATCH v3 08/19] contrib/elf2dmp: Fix error reporting style in qemu_elf.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-8-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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: none client-ip=2607:f8b0:4864:20::62b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705828146100009 include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/qemu_elf.h | 2 +- contrib/elf2dmp/main.c | 2 +- contrib/elf2dmp/qemu_elf.c | 32 ++++++++++++++++---------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.h b/contrib/elf2dmp/qemu_elf.h index afa75f10b2d2..adc50238b46b 100644 --- a/contrib/elf2dmp/qemu_elf.h +++ b/contrib/elf2dmp/qemu_elf.h @@ -42,7 +42,7 @@ typedef struct QEMU_Elf { int has_kernel_gs_base; } QEMU_Elf; =20 -int QEMU_Elf_init(QEMU_Elf *qe, const char *filename); +bool QEMU_Elf_init(QEMU_Elf *qe, const char *filename); void QEMU_Elf_exit(QEMU_Elf *qe); =20 Elf64_Phdr *elf64_getphdr(void *map); diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 7a3a7225905e..cb28971789e4 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -535,7 +535,7 @@ int main(int argc, char *argv[]) return 1; } =20 - if (QEMU_Elf_init(&qemu_elf, argv[1])) { + if (!QEMU_Elf_init(&qemu_elf, argv[1])) { eprintf("Failed to initialize QEMU ELF dump\n"); return 1; } diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index 055e6f8792e9..a22c057d3ec3 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -60,7 +60,7 @@ Elf64_Half elf_getphdrnum(void *map) return ehdr->e_phnum; } =20 -static int init_states(QEMU_Elf *qe) +static bool init_states(QEMU_Elf *qe) { Elf64_Phdr *phdr =3D elf64_getphdr(qe->map); Elf64_Nhdr *start =3D (void *)((uint8_t *)qe->map + phdr[0].p_offset); @@ -70,7 +70,7 @@ static int init_states(QEMU_Elf *qe) =20 if (phdr[0].p_type !=3D PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); - return 1; + return false; } =20 qe->has_kernel_gs_base =3D 1; @@ -107,7 +107,7 @@ static int init_states(QEMU_Elf *qe) =20 qe->state_nr =3D cpu_nr; =20 - return 0; + return true; } =20 static void exit_states(QEMU_Elf *qe) @@ -162,7 +162,7 @@ static bool check_ehdr(QEMU_Elf *qe) return true; } =20 -static int QEMU_Elf_map(QEMU_Elf *qe, const char *filename) +static bool QEMU_Elf_map(QEMU_Elf *qe, const char *filename) { #ifdef CONFIG_LINUX struct stat st; @@ -173,13 +173,13 @@ static int QEMU_Elf_map(QEMU_Elf *qe, const char *fil= ename) fd =3D open(filename, O_RDONLY, 0); if (fd =3D=3D -1) { eprintf("Failed to open ELF dump file \'%s\'\n", filename); - return 1; + return false; } =20 if (fstat(fd, &st)) { eprintf("Failed to get size of ELF dump file\n"); close(fd); - return 1; + return false; } qe->size =3D st.st_size; =20 @@ -188,7 +188,7 @@ static int QEMU_Elf_map(QEMU_Elf *qe, const char *filen= ame) if (qe->map =3D=3D MAP_FAILED) { eprintf("Failed to map ELF file\n"); close(fd); - return 1; + return false; } =20 close(fd); @@ -201,14 +201,14 @@ static int QEMU_Elf_map(QEMU_Elf *qe, const char *fil= ename) if (gerr) { eprintf("Failed to map ELF dump file \'%s\'\n", filename); g_error_free(gerr); - return 1; + return false; } =20 qe->map =3D g_mapped_file_get_contents(qe->gmf); qe->size =3D g_mapped_file_get_length(qe->gmf); #endif =20 - return 0; + return true; } =20 static void QEMU_Elf_unmap(QEMU_Elf *qe) @@ -220,25 +220,25 @@ static void QEMU_Elf_unmap(QEMU_Elf *qe) #endif } =20 -int QEMU_Elf_init(QEMU_Elf *qe, const char *filename) +bool QEMU_Elf_init(QEMU_Elf *qe, const char *filename) { - if (QEMU_Elf_map(qe, filename)) { - return 1; + if (!QEMU_Elf_map(qe, filename)) { + return false; } =20 if (!check_ehdr(qe)) { eprintf("Input file has the wrong format\n"); QEMU_Elf_unmap(qe); - return 1; + return false; } =20 - if (init_states(qe)) { + if (!init_states(qe)) { eprintf("Failed to extract QEMU CPU states\n"); QEMU_Elf_unmap(qe); - return 1; + return false; } =20 - return 0; + return true; } =20 void QEMU_Elf_exit(QEMU_Elf *qe) --=20 2.44.0