aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2019-03-26 16:33:00 +0100
committerDavid Gibson <david@gibson.dropbear.id.au>2019-03-29 13:29:51 +1100
commit2bc5b66d7f6c441bf6183a6f769a95de6f90297b (patch)
tree4216cca36c2101ce095e52d192c3ef596661ae7b /tests
parent7fcf8208b8a98f65ce938a64fab674add3656f27 (diff)
downloaddtc-2bc5b66d7f6c441bf6183a6f769a95de6f90297b.zip
dtc-2bc5b66d7f6c441bf6183a6f769a95de6f90297b.tar.gz
dtc-2bc5b66d7f6c441bf6183a6f769a95de6f90297b.tar.bz2
libfdt: Add new maximum phandle lookup function
The fdt_get_max_phandle() function has some shortcomings. On one hand it returns just a uint32_t which means to check for the "negative" error code a caller has to explicitly check against the error code (uint32_t)-1. In addition, the -1 is the only error code that can be returned, so a caller cannot tell the difference between the various failures. Fix this by adding a new fdt_find_max_phandle() function that returns an error code on failure and 0 on success, just like other APIs, and stores the maximum phandle value in an output argument on success. This also refactors fdt_get_max_phandle() to use the new function. Add a note pointing out that the new fdt_find_max_phandle() function should be preferred over fdt_get_max_phandle(). Signed-off-by: Thierry Reding <treding@nvidia.com> Message-Id: <20190326153302.17109-1-thierry.reding@gmail.com> [dwg: Reword for some inaccuracies in the commit message] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tests')
-rw-r--r--tests/get_phandle.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/get_phandle.c b/tests/get_phandle.c
index 22bd7b8..6973ee4 100644
--- a/tests/get_phandle.c
+++ b/tests/get_phandle.c
@@ -46,6 +46,7 @@ int main(int argc, char *argv[])
{
uint32_t max;
void *fdt;
+ int err;
test_init(argc, argv);
fdt = load_blob_arg(argc, argv);
@@ -54,6 +55,14 @@ int main(int argc, char *argv[])
check_phandle(fdt, "/subnode@2", PHANDLE_1);
check_phandle(fdt, "/subnode@2/subsubnode@0", PHANDLE_2);
+ err = fdt_find_max_phandle(fdt, &max);
+ if (err < 0)
+ FAIL("fdt_find_max_phandle returned %d instead of 0\n", err);
+
+ if (max != PHANDLE_2)
+ FAIL("fdt_find_max_phandle found 0x%x instead of 0x%x", max,
+ PHANDLE_2);
+
max = fdt_get_max_phandle(fdt);
if (max != PHANDLE_2)
FAIL("fdt_get_max_phandle returned 0x%x instead of 0x%x\n",