From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: Viktor Prutyanov <viktor.prutyanov@phystech.edu>,
Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH v4 07/19] contrib/elf2dmp: Fix error reporting style in pdb.c
Date: Thu, 07 Mar 2024 19:20:50 +0900 [thread overview]
Message-ID: <20240307-elf2dmp-v4-7-4f324ad4d99d@daynix.com> (raw)
In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com>
include/qapi/error.h says:
> We recommend
> * bool-valued functions return true on success / false on failure,
> ...
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
contrib/elf2dmp/pdb.h | 2 +-
contrib/elf2dmp/main.c | 2 +-
contrib/elf2dmp/pdb.c | 50 +++++++++++++++++++++++++-------------------------
3 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/contrib/elf2dmp/pdb.h b/contrib/elf2dmp/pdb.h
index 2a50da56ac96..feddf1862f08 100644
--- a/contrib/elf2dmp/pdb.h
+++ b/contrib/elf2dmp/pdb.h
@@ -233,7 +233,7 @@ struct pdb_reader {
size_t segs_size;
};
-int pdb_init_from_file(const char *name, struct pdb_reader *reader);
+bool pdb_init_from_file(const char *name, struct pdb_reader *reader);
void pdb_exit(struct pdb_reader *reader);
uint64_t pdb_resolve(uint64_t img_base, struct pdb_reader *r, const char *name);
uint64_t pdb_find_public_v3_symbol(struct pdb_reader *reader, const char *name);
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index d295fd92be2f..7a3a7225905e 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -596,7 +596,7 @@ int main(int argc, char *argv[])
goto out_ps;
}
- if (pdb_init_from_file(PDB_NAME, &pdb)) {
+ if (!pdb_init_from_file(PDB_NAME, &pdb)) {
eprintf("Failed to initialize PDB reader\n");
goto out_pdb_file;
}
diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c
index abf17c2e7c12..1c5051425185 100644
--- a/contrib/elf2dmp/pdb.c
+++ b/contrib/elf2dmp/pdb.c
@@ -158,30 +158,30 @@ static void *pdb_ds_read_file(struct pdb_reader* r, uint32_t file_number)
return pdb_ds_read(r->ds.header, block_list, file_size[file_number]);
}
-static int pdb_init_segments(struct pdb_reader *r)
+static bool pdb_init_segments(struct pdb_reader *r)
{
unsigned stream_idx = r->segments;
r->segs = pdb_ds_read_file(r, stream_idx);
if (!r->segs) {
- return 1;
+ return false;
}
r->segs_size = pdb_get_file_size(r, stream_idx);
if (!r->segs_size) {
- return 1;
+ return false;
}
- return 0;
+ return true;
}
-static int pdb_init_symbols(struct pdb_reader *r)
+static bool pdb_init_symbols(struct pdb_reader *r)
{
PDB_SYMBOLS *symbols;
symbols = pdb_ds_read_file(r, 3);
if (!symbols) {
- return 1;
+ return false;
}
r->symbols = symbols;
@@ -198,18 +198,18 @@ static int pdb_init_symbols(struct pdb_reader *r)
goto out_symbols;
}
- return 0;
+ return true;
out_symbols:
g_free(symbols);
- return 1;
+ return false;
}
-static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
+static bool pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
{
if (hdr->block_size == 0) {
- return 1;
+ return false;
}
memset(r->file_used, 0, sizeof(r->file_used));
@@ -218,22 +218,22 @@ static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr)
hdr->toc_page * hdr->block_size), hdr->toc_size);
if (!r->ds.toc) {
- return 1;
+ return false;
}
- return 0;
+ return true;
}
-static int pdb_reader_init(struct pdb_reader *r, void *data)
+static bool pdb_reader_init(struct pdb_reader *r, void *data)
{
const char pdb7[] = "Microsoft C/C++ MSF 7.00";
if (memcmp(data, pdb7, sizeof(pdb7) - 1)) {
- return 1;
+ return false;
}
- if (pdb_reader_ds_init(r, data)) {
- return 1;
+ if (!pdb_reader_ds_init(r, data)) {
+ return false;
}
r->ds.root = pdb_ds_read_file(r, 1);
@@ -241,15 +241,15 @@ static int pdb_reader_init(struct pdb_reader *r, void *data)
goto out_ds;
}
- if (pdb_init_symbols(r)) {
+ if (!pdb_init_symbols(r)) {
goto out_root;
}
- if (pdb_init_segments(r)) {
+ if (!pdb_init_segments(r)) {
goto out_sym;
}
- return 0;
+ return true;
out_sym:
pdb_exit_symbols(r);
@@ -258,7 +258,7 @@ out_root:
out_ds:
pdb_reader_ds_exit(r);
- return 1;
+ return false;
}
static void pdb_reader_exit(struct pdb_reader *r)
@@ -269,7 +269,7 @@ static void pdb_reader_exit(struct pdb_reader *r)
pdb_reader_ds_exit(r);
}
-int pdb_init_from_file(const char *name, struct pdb_reader *reader)
+bool pdb_init_from_file(const char *name, struct pdb_reader *reader)
{
GError *gerr = NULL;
void *map;
@@ -278,21 +278,21 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader)
if (gerr) {
eprintf("Failed to map PDB file \'%s\'\n", name);
g_error_free(gerr);
- return 1;
+ return false;
}
reader->file_size = g_mapped_file_get_length(reader->gmf);
map = g_mapped_file_get_contents(reader->gmf);
- if (pdb_reader_init(reader, map)) {
+ if (!pdb_reader_init(reader, map)) {
goto out_unmap;
}
- return 0;
+ return true;
out_unmap:
g_mapped_file_unref(reader->gmf);
- return 1;
+ return false;
}
void pdb_exit(struct pdb_reader *reader)
--
2.44.0
next prev parent reply other threads:[~2024-03-07 10:24 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 10:20 [PATCH v4 00/19] contrib/elf2dmp: Improve robustness Akihiko Odaki
2024-03-07 10:20 ` [PATCH v4 01/19] contrib/elf2dmp: Remove unnecessary err flags Akihiko Odaki
2024-03-07 10:20 ` [PATCH v4 02/19] contrib/elf2dmp: Assume error by default Akihiko Odaki
2024-03-07 10:20 ` [PATCH v4 03/19] contrib/elf2dmp: Continue even contexts are lacking Akihiko Odaki
2024-03-07 10:20 ` [PATCH v4 04/19] contrib/elf2dmp: Change pa_space_create() signature Akihiko Odaki
2024-03-07 10:25 ` Philippe Mathieu-Daudé
2024-03-07 10:20 ` [PATCH v4 05/19] contrib/elf2dmp: Fix error reporting style in addrspace.c Akihiko Odaki
2024-03-07 10:25 ` Philippe Mathieu-Daudé
2024-03-07 10:20 ` [PATCH v4 06/19] contrib/elf2dmp: Fix error reporting style in download.c Akihiko Odaki
2024-03-07 13:08 ` Peter Maydell
2024-03-07 10:20 ` Akihiko Odaki [this message]
2024-03-07 13:10 ` [PATCH v4 07/19] contrib/elf2dmp: Fix error reporting style in pdb.c Peter Maydell
2024-03-07 10:20 ` [PATCH v4 08/19] contrib/elf2dmp: Fix error reporting style in qemu_elf.c Akihiko Odaki
2024-03-07 13:11 ` Peter Maydell
2024-03-07 10:20 ` [PATCH v4 09/19] contrib/elf2dmp: Fix error reporting style in main.c Akihiko Odaki
2024-03-07 13:12 ` Peter Maydell
2024-03-07 10:20 ` [PATCH v4 10/19] contrib/elf2dmp: Always check for PA resolution failure Akihiko Odaki
2024-03-07 10:20 ` [PATCH v4 11/19] contrib/elf2dmp: Always destroy PA space Akihiko Odaki
2024-03-07 10:20 ` [PATCH v4 12/19] contrib/elf2dmp: Ensure segment fits in file Akihiko Odaki
2024-03-07 10:20 ` [PATCH v4 13/19] contrib/elf2dmp: Use lduw_le_p() to read PDB Akihiko Odaki
2024-03-07 10:27 ` Philippe Mathieu-Daudé
2024-03-07 10:20 ` [PATCH v4 14/19] contrib/elf2dmp: Use rol64() to decode Akihiko Odaki
2024-03-07 10:29 ` Philippe Mathieu-Daudé
2024-03-07 10:20 ` [PATCH v4 15/19] MAINTAINERS: Add Akihiko Odaki as a elf2dmp reviewer Akihiko Odaki
2024-03-07 10:29 ` Philippe Mathieu-Daudé
2024-03-10 19:43 ` Viktor Prutyanov
2024-03-07 10:20 ` [PATCH v4 16/19] contrib/elf2dmp: Build only for little endian host Akihiko Odaki
2024-03-07 10:21 ` [PATCH v4 17/19] contrib/elf2dmp: Use GPtrArray Akihiko Odaki
2024-03-07 10:21 ` [PATCH v4 18/19] contrib/elf2dmp: Clamp QEMU note to file size Akihiko Odaki
2024-03-07 10:21 ` [PATCH v4 19/19] contrib/elf2dmp: Ensure phdrs fit in file Akihiko Odaki
2024-03-07 13:14 ` Peter Maydell
2024-03-10 20:25 ` [PATCH v4 00/19] contrib/elf2dmp: Improve robustness Viktor Prutyanov
2024-03-11 17:09 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240307-elf2dmp-v4-7-4f324ad4d99d@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=viktor.prutyanov@phystech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).