[rtems commit] libfdt: return correct value if #size-cells property is not present

Sebastian Huber sebh at rtems.org
Mon Mar 2 06:52:33 UTC 2020


Module:    rtems
Branch:    master
Commit:    8bd3915555bc21c7d53d17cdbd5cf64ff6a48cb9
Changeset: http://git.rtems.org/rtems/commit/?id=8bd3915555bc21c7d53d17cdbd5cf64ff6a48cb9

Author:    John Clarke <johnc at kirriwa.net>
Date:      Fri Nov  2 12:46:22 2018 +1100

libfdt: return correct value if #size-cells property is not present

According to the device tree specification, the default value for
#size-cells is 1, but fdt_size_cells() was returning 2 if this property
was not present.

This patch also makes fdt_address_cells() and fdt_size_cells() conform
to the behaviour documented in libfdt.h. The defaults are only returned
if fdt_getprop() returns -FDT_ERR_NOTFOUND, otherwise the actual error
is returned.

Signed-off-by: John Clarke <johnc at kirriwa.net>

---

 cpukit/dtc/libfdt/fdt_addresses.c | 16 +++++++++++++---
 cpukit/include/libfdt.h           |  2 +-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/cpukit/dtc/libfdt/fdt_addresses.c b/cpukit/dtc/libfdt/fdt_addresses.c
index 49537b5..f13a87d 100644
--- a/cpukit/dtc/libfdt/fdt_addresses.c
+++ b/cpukit/dtc/libfdt/fdt_addresses.c
@@ -64,7 +64,7 @@ static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
 
 	c = fdt_getprop(fdt, nodeoffset, name, &len);
 	if (!c)
-		return 2;
+		return len;
 
 	if (len != sizeof(*c))
 		return -FDT_ERR_BADNCELLS;
@@ -78,10 +78,20 @@ static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
 
 int fdt_address_cells(const void *fdt, int nodeoffset)
 {
-	return fdt_cells(fdt, nodeoffset, "#address-cells");
+	int val;
+
+	val = fdt_cells(fdt, nodeoffset, "#address-cells");
+	if (val == -FDT_ERR_NOTFOUND)
+		return 2;
+	return val;
 }
 
 int fdt_size_cells(const void *fdt, int nodeoffset)
 {
-	return fdt_cells(fdt, nodeoffset, "#size-cells");
+	int val;
+
+	val = fdt_cells(fdt, nodeoffset, "#size-cells");
+	if (val == -FDT_ERR_NOTFOUND)
+		return 1;
+	return val;
 }
diff --git a/cpukit/include/libfdt.h b/cpukit/include/libfdt.h
index 830b77e..face02c 100644
--- a/cpukit/include/libfdt.h
+++ b/cpukit/include/libfdt.h
@@ -1145,7 +1145,7 @@ int fdt_address_cells(const void *fdt, int nodeoffset);
  *
  * returns:
  *	0 <= n < FDT_MAX_NCELLS, on success
- *      2, if the node has no #size-cells property
+ *      1, if the node has no #size-cells property
  *      -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
  *		#size-cells property
  *	-FDT_ERR_BADMAGIC,



More information about the vc mailing list