mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-14 00:37:41 -04:00
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@kirriwa.net>
This commit is contained in:
parent
da2b691ccf
commit
aa7254d9cb
4 changed files with 16 additions and 6 deletions
|
@ -64,7 +64,7 @@ static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
|
||||||
|
|
||||||
c = fdt_getprop(fdt, nodeoffset, name, &len);
|
c = fdt_getprop(fdt, nodeoffset, name, &len);
|
||||||
if (!c)
|
if (!c)
|
||||||
return 2;
|
return len;
|
||||||
|
|
||||||
if (len != sizeof(*c))
|
if (len != sizeof(*c))
|
||||||
return -FDT_ERR_BADNCELLS;
|
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)
|
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)
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1145,7 +1145,7 @@ int fdt_address_cells(const void *fdt, int nodeoffset);
|
||||||
*
|
*
|
||||||
* returns:
|
* returns:
|
||||||
* 0 <= n < FDT_MAX_NCELLS, on success
|
* 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
|
* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
|
||||||
* #size-cells property
|
* #size-cells property
|
||||||
* -FDT_ERR_BADMAGIC,
|
* -FDT_ERR_BADMAGIC,
|
||||||
|
|
|
@ -58,7 +58,7 @@ int main(int argc, char *argv[])
|
||||||
fdt = load_blob(argv[1]);
|
fdt = load_blob(argv[1]);
|
||||||
|
|
||||||
check_node(fdt, "/", 2, 2);
|
check_node(fdt, "/", 2, 2);
|
||||||
check_node(fdt, "/identity-bus@0", 2, 2);
|
check_node(fdt, "/identity-bus@0", 2, 1);
|
||||||
check_node(fdt, "/simple-bus@1000000", 2, 1);
|
check_node(fdt, "/simple-bus@1000000", 2, 1);
|
||||||
check_node(fdt, "/c0", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
|
check_node(fdt, "/c0", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
|
||||||
check_node(fdt, "/c1", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
|
check_node(fdt, "/c1", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
|
||||||
|
|
|
@ -57,6 +57,6 @@ int main(int argc, char *argv[])
|
||||||
test_init(argc, argv);
|
test_init(argc, argv);
|
||||||
fdt = load_blob(argv[1]);
|
fdt = load_blob(argv[1]);
|
||||||
|
|
||||||
check_node(fdt, "/", 2, 2);
|
check_node(fdt, "/", 2, 1);
|
||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue