[Pdbg] [PATCH 16/23] libpdbg: Drop argument from pdbg_targets_init()
Alistair Popple
alistair at popple.id.au
Thu Sep 19 14:43:27 AEST 2019
Can we drop this for now? I am not convinced that we won't still need to use
it in a standalone environment and we have enough other applications out there
consuming this API that changing it now will cause some amount of pain.
- Alistair
On Thursday, 19 September 2019 12:33:26 PM AEST Amitay Isaacs wrote:
> Now that all device tree detection is built in libpdbg, there is no need
> to pass device tree blob to pdbg_targets_init(). Also, make it return
> status to indicate success or failure.
>
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
> libpdbg/device.c | 12 +++++++-----
> libpdbg/libpdbg.h | 2 +-
> src/main.c | 3 ++-
> src/tests/libpdbg_dtree_test.c | 2 +-
> src/tests/libpdbg_probe_test.c | 6 +++---
> src/tests/libpdbg_target_test.c | 2 +-
> 6 files changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/libpdbg/device.c b/libpdbg/device.c
> index b499171..00bcf10 100644
> --- a/libpdbg/device.c
> +++ b/libpdbg/device.c
> @@ -718,23 +718,25 @@ skip:
> }
> }
>
> -void pdbg_targets_init(void *fdt)
> +bool pdbg_targets_init(void)
> {
> - if (!fdt)
> - fdt = pdbg_default_dtb();
> + void *fdt;
>
> + fdt = pdbg_default_dtb();
> if (!fdt) {
> pdbg_log(PDBG_ERROR, "Could not find a system device tree\n");
> - return;
> + return false;
> }
>
> /* Root node needs to be valid when this function returns */
> pdbg_dt_root = dt_new_node("", NULL, 0);
> - assert(pdbg_dt_root);
> + if (!pdbg_dt_root)
> + return false;
>
> dt_expand(pdbg_dt_root, fdt);
>
> pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root);
> + return true;
> }
>
> char *pdbg_target_path(struct pdbg_target *target)
> diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
> index df74e43..7603b96 100644
> --- a/libpdbg/libpdbg.h
> +++ b/libpdbg/libpdbg.h
> @@ -101,7 +101,7 @@ uint64_t pdbg_target_address(struct pdbg_target *target,
uint64_t *size);
> (index == 0 ? pdbg_target_address(target, size) : assert(0))
>
> /* Misc. */
> -void pdbg_targets_init(void *fdt);
> +bool pdbg_targets_init(void);
> void pdbg_target_probe_all(struct pdbg_target *parent);
> enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target);
> void pdbg_target_release(struct pdbg_target *target);
> diff --git a/src/main.c b/src/main.c
> index f7f891a..2ef61a3 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -580,7 +580,8 @@ int main(int argc, char *argv[])
> if (backend)
> pdbg_set_backend(backend, device_node);
>
> - pdbg_targets_init(NULL);
> + if (!pdbg_targets_init())
> + return 1;
>
> if (pathsel_count) {
> if (!path_target_parse(pathsel, pathsel_count))
> diff --git a/src/tests/libpdbg_dtree_test.c b/src/tests/libpdbg_dtree_test.c
> index 434728a..4f1ff08 100644
> --- a/src/tests/libpdbg_dtree_test.c
> +++ b/src/tests/libpdbg_dtree_test.c
> @@ -55,7 +55,7 @@ static void usage(void)
>
> int main(int argc, const char **argv)
> {
> - pdbg_targets_init(NULL);
> + assert(pdbg_targets_init());
>
> if (argc < 2)
> usage();
> diff --git a/src/tests/libpdbg_probe_test.c b/src/tests/libpdbg_probe_test.c
> index 8b78b2e..02f91d1 100644
> --- a/src/tests/libpdbg_probe_test.c
> +++ b/src/tests/libpdbg_probe_test.c
> @@ -74,7 +74,7 @@ static void test1(void)
> struct pdbg_target *root, *target;
>
> pdbg_set_backend(PDBG_BACKEND_FAKE, NULL);
> - pdbg_targets_init(NULL);
> + assert(pdbg_targets_init());
>
> root = pdbg_target_root();
> assert(root);
> @@ -122,7 +122,7 @@ static void test2(void)
> enum pdbg_target_status status;
>
> pdbg_set_backend(PDBG_BACKEND_FAKE, NULL);
> - pdbg_targets_init(NULL);
> + assert(pdbg_targets_init());
>
> root = pdbg_target_root();
> assert(root);
> @@ -186,7 +186,7 @@ static void test3(void)
> enum pdbg_target_status status;
>
> pdbg_set_backend(PDBG_BACKEND_FAKE, NULL);
> - pdbg_targets_init(NULL);
> + assert(pdbg_targets_init());
>
> root = pdbg_target_root();
> assert(root);
> diff --git a/src/tests/libpdbg_target_test.c b/src/tests/
libpdbg_target_test.c
> index b5f7fdd..0af3ebb 100644
> --- a/src/tests/libpdbg_target_test.c
> +++ b/src/tests/libpdbg_target_test.c
> @@ -66,7 +66,7 @@ int main(void)
> int count;
>
> pdbg_set_backend(PDBG_BACKEND_FAKE, NULL);
> - pdbg_targets_init(NULL);
> + assert(pdbg_targets_init());
>
> root = pdbg_target_root();
> assert(root);
>
More information about the Pdbg
mailing list