libfdt: Fix handling of trailing / in fdt_path_offset()
Currently, fdt_path_offset() returns FDL_ERR_BADOFFSET if given a path with a trailing '/'. In particular this means that fdt_path_offset("/") returns FDT_ERR_BADOFFSET rather than 0 as one would expect. This patch fixes the function to accept and ignore trailing '/' characters. As well as allowing fdt_path_offset("/") this means that fdt_path_offset("/foo/") will return the same as fdt_path_offset("/foo") which seems in keeping with the principle of least surprise. This also adds a testcase to ensure that fdt_path_offset("/") returns 0 as it should. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>main
parent
5cb1fbdd7c
commit
bd2ae2f41c
|
@ -154,7 +154,7 @@ int fdt_path_offset(const void *fdt, const char *path)
|
||||||
while (*p == '/')
|
while (*p == '/')
|
||||||
p++;
|
p++;
|
||||||
if (! *p)
|
if (! *p)
|
||||||
return -FDT_ERR_BADPATH;
|
return offset;
|
||||||
q = strchr(p, '/');
|
q = strchr(p, '/');
|
||||||
if (! q)
|
if (! q)
|
||||||
q = end;
|
q = end;
|
||||||
|
|
|
@ -58,6 +58,7 @@ int check_subnode(void *fdt, int parent, const char *name)
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
void *fdt;
|
void *fdt;
|
||||||
|
int root_offset;
|
||||||
int subnode1_offset, subnode2_offset;
|
int subnode1_offset, subnode2_offset;
|
||||||
int subnode1_offset_p, subnode2_offset_p;
|
int subnode1_offset_p, subnode2_offset_p;
|
||||||
int subsubnode1_offset, subsubnode2_offset;
|
int subsubnode1_offset, subsubnode2_offset;
|
||||||
|
@ -66,6 +67,13 @@ int main(int argc, char *argv[])
|
||||||
test_init(argc, argv);
|
test_init(argc, argv);
|
||||||
fdt = load_blob_arg(argc, argv);
|
fdt = load_blob_arg(argc, argv);
|
||||||
|
|
||||||
|
root_offset = fdt_path_offset(fdt, "/");
|
||||||
|
if (root_offset < 0)
|
||||||
|
FAIL("fdt_path_offset(\"/\") failed: %s",
|
||||||
|
fdt_strerror(root_offset));
|
||||||
|
else if (root_offset != 0)
|
||||||
|
FAIL("fdt_path_offset(\"/\") returns incorrect offset %d",
|
||||||
|
root_offset);
|
||||||
subnode1_offset = check_subnode(fdt, 0, "subnode1");
|
subnode1_offset = check_subnode(fdt, 0, "subnode1");
|
||||||
subnode2_offset = check_subnode(fdt, 0, "subnode2");
|
subnode2_offset = check_subnode(fdt, 0, "subnode2");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue