linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* libfdt: Fix handling of trailing / in fdt_path_offset()
@ 2007-08-29  2:22 David Gibson
  2007-08-30 13:52 ` Jon Loeliger
  0 siblings, 1 reply; 2+ messages in thread
From: David Gibson @ 2007-08-29  2:22 UTC (permalink / raw)
  To: Jon Loeliger; +Cc: linuxppc-dev

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>

Index: dtc/tests/path_offset.c
===================================================================
--- dtc.orig/tests/path_offset.c	2007-08-29 12:04:54.000000000 +1000
+++ dtc/tests/path_offset.c	2007-08-29 12:04:57.000000000 +1000
@@ -58,6 +58,7 @@
 int main(int argc, char *argv[])
 {
 	void *fdt;
+	int root_offset;
 	int subnode1_offset, subnode2_offset;
 	int subnode1_offset_p, subnode2_offset_p;
 	int subsubnode1_offset, subsubnode2_offset;
@@ -66,6 +67,13 @@
 	test_init(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");
 	subnode2_offset = check_subnode(fdt, 0, "subnode2");
 
Index: dtc/libfdt/fdt_ro.c
===================================================================
--- dtc.orig/libfdt/fdt_ro.c	2007-08-29 12:08:48.000000000 +1000
+++ dtc/libfdt/fdt_ro.c	2007-08-29 12:08:55.000000000 +1000
@@ -154,7 +154,7 @@
 		while (*p == '/')
 			p++;
 		if (! *p)
-			return -FDT_ERR_BADPATH;
+			return offset;
 		q = strchr(p, '/');
 		if (! q)
 			q = end;

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: libfdt: Fix handling of trailing / in fdt_path_offset()
  2007-08-29  2:22 libfdt: Fix handling of trailing / in fdt_path_offset() David Gibson
@ 2007-08-30 13:52 ` Jon Loeliger
  0 siblings, 0 replies; 2+ messages in thread
From: Jon Loeliger @ 2007-08-30 13:52 UTC (permalink / raw)
  To: David Gibson; +Cc: linuxppc-dev

So, like, the other day David Gibson mumbled:
> 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>

Applied.

Thanks,
jdl

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-30 13:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-29  2:22 libfdt: Fix handling of trailing / in fdt_path_offset() David Gibson
2007-08-30 13:52 ` Jon Loeliger

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).