[Pdbg] [PATCH v3 16/22] libpdbg: Make pdbg_set_backend() return boolean
Amitay Isaacs
amitay at ozlabs.org
Mon Sep 23 18:48:35 AEST 2019
Simplify api by using boolean status instead of int.
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
Reviewed-by: Alistair Popple <alistair at popple.id.au>
---
libpdbg/dtb.c | 9 +++++++--
libpdbg/libpdbg.h | 2 +-
src/main.c | 3 ++-
src/tests/libpdbg_probe_test.c | 6 +++---
src/tests/libpdbg_target_test.c | 2 +-
5 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
index 6c4beed..92a4efb 100644
--- a/libpdbg/dtb.c
+++ b/libpdbg/dtb.c
@@ -205,12 +205,17 @@ fail:
return NULL;
}
-int pdbg_set_backend(enum pdbg_backend backend, const char *backend_option)
+bool pdbg_set_backend(enum pdbg_backend backend, const char *backend_option)
{
+ if (pdbg_target_root()) {
+ pdbg_log(PDBG_ERROR, "pdbg_set_backend() must be called before pdbg_targets_init()\n");
+ return false;
+ }
+
pdbg_backend = backend;
pdbg_backend_option = backend_option;
- return 0;
+ return true;
}
const char *pdbg_get_backend_option(void)
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index 31a644e..64db5b9 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -107,7 +107,7 @@ enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target);
void pdbg_target_release(struct pdbg_target *target);
enum pdbg_target_status pdbg_target_status(struct pdbg_target *target);
void pdbg_target_status_set(struct pdbg_target *target, enum pdbg_target_status status);
-int pdbg_set_backend(enum pdbg_backend backend, const char *backend_option);
+bool pdbg_set_backend(enum pdbg_backend backend, const char *backend_option);
void *pdbg_default_dtb(void);
uint32_t pdbg_target_index(struct pdbg_target *target);
char *pdbg_target_path(struct pdbg_target *target);
diff --git a/src/main.c b/src/main.c
index a508034..8096222 100644
--- a/src/main.c
+++ b/src/main.c
@@ -578,7 +578,8 @@ int main(int argc, char *argv[])
}
if (backend)
- pdbg_set_backend(backend, device_node);
+ if (!pdbg_set_backend(backend, device_node))
+ return 1;
if (!pdbg_targets_init(NULL))
return 1;
diff --git a/src/tests/libpdbg_probe_test.c b/src/tests/libpdbg_probe_test.c
index fba7a23..c76f77f 100644
--- a/src/tests/libpdbg_probe_test.c
+++ b/src/tests/libpdbg_probe_test.c
@@ -73,7 +73,7 @@ static void test1(void)
{
struct pdbg_target *root, *target;
- pdbg_set_backend(PDBG_BACKEND_FAKE, NULL);
+ assert(pdbg_set_backend(PDBG_BACKEND_FAKE, NULL));
assert(pdbg_targets_init(NULL));
root = pdbg_target_root();
@@ -121,7 +121,7 @@ static void test2(void)
struct pdbg_target *root, *target;
enum pdbg_target_status status;
- pdbg_set_backend(PDBG_BACKEND_FAKE, NULL);
+ assert(pdbg_set_backend(PDBG_BACKEND_FAKE, NULL));
assert(pdbg_targets_init(NULL));
root = pdbg_target_root();
@@ -198,7 +198,7 @@ static void test3(void)
struct pdbg_target *root, *target;
enum pdbg_target_status status;
- pdbg_set_backend(PDBG_BACKEND_FAKE, NULL);
+ assert(pdbg_set_backend(PDBG_BACKEND_FAKE, NULL));
assert(pdbg_targets_init(NULL));
root = pdbg_target_root();
diff --git a/src/tests/libpdbg_target_test.c b/src/tests/libpdbg_target_test.c
index c68590f..36e6891 100644
--- a/src/tests/libpdbg_target_test.c
+++ b/src/tests/libpdbg_target_test.c
@@ -65,7 +65,7 @@ int main(void)
const char *name;
int count, i;
- pdbg_set_backend(PDBG_BACKEND_FAKE, NULL);
+ assert(pdbg_set_backend(PDBG_BACKEND_FAKE, NULL));
assert(pdbg_targets_init(NULL));
root = pdbg_target_root();
--
2.21.0
More information about the Pdbg
mailing list