Fix OF_finddevice error return value in case of FDT.

According to the open firmware standard, finddevice call has to return
a phandle with value of -1 in case of error.

This commit is to:
- Fix the FDT implementation of this interface (ofw_fdt_finddevice) to
  return (phandle_t)-1 in case of error, instead of 0 as it does now.
- Fix up the callers of OF_finddevice() to compare the return value with
  -1 instead of 0 to check for errors.
- Since phandle_t is unsigned, the return value of OF_finddevice should
  be checked with '== -1' rather than '<= 0' or '> 0', fix up these cases
  as well.

Reported by:	nwhitehorn

Reviewed by:	raj
Approved by:	raj, nwhitehorn
This commit is contained in:
Jayachandran C. 2011-12-02 15:24:39 +00:00
parent c8973d9e6c
commit 07042bef45
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=228201
12 changed files with 24 additions and 22 deletions

View File

@ -1693,7 +1693,7 @@ fdt_get_ranges(const char *nodename, void *buf, int size, int *tuples,
int len, tuple_size, tuples_count;
node = OF_finddevice(nodename);
if (node <= 0)
if (node == -1)
return (EINVAL);
if ((fdt_addrsize_cells(node, &addr_cells, &size_cells)) != 0)
@ -1762,11 +1762,11 @@ win_cpu_from_dt(void)
/*
* Retrieve CESA SRAM data.
*/
if ((node = OF_finddevice("sram")) != 0)
if ((node = OF_finddevice("sram")) != -1)
if (fdt_is_compatible(node, "mrvl,cesa-sram"))
goto moveon;
if ((node = OF_finddevice("/")) == 0)
if ((node = OF_finddevice("/")) != -1)
return (ENXIO);
if ((node = fdt_find_compatible(node, "mrvl,cesa-sram", 0)) == 0)
@ -1796,7 +1796,7 @@ fdt_win_setup(void)
int err, i;
node = OF_finddevice("/");
if (node == 0)
if (node == -1)
panic("fdt_win_setup: no root node");
node = fdt_find_compatible(node, "simple-bus", 1);

View File

@ -617,13 +617,13 @@ platform_mpp_init(void)
/*
* Try to access the MPP node directly i.e. through /aliases/mpp.
*/
if ((node = OF_finddevice("mpp")) != 0)
if ((node = OF_finddevice("mpp")) != -1)
if (fdt_is_compatible(node, "mrvl,mpp"))
goto moveon;
/*
* Find the node the long way.
*/
if ((node = OF_finddevice("/")) == 0)
if ((node = OF_finddevice("/")) == -1)
return (ENXIO);
if ((node = fdt_find_compatible(node, "simple-bus", 0)) == 0)
@ -752,7 +752,7 @@ platform_devmap_init(void)
/*
* PCI range(s).
*/
if ((root = OF_finddevice("/")) == 0)
if ((root = OF_finddevice("/")) == -1)
return (ENXIO);
for (child = OF_child(root); child != 0; child = OF_peer(child))
@ -779,7 +779,7 @@ platform_devmap_init(void)
/*
* CESA SRAM range.
*/
if ((child = OF_finddevice("sram")) != 0)
if ((child = OF_finddevice("sram")) != -1)
if (fdt_is_compatible(child, "mrvl,cesa-sram"))
goto moveon;

View File

@ -74,13 +74,13 @@ fdt_immr_addr(vm_offset_t immr_va)
/*
* Try to access the SOC node directly i.e. through /aliases/.
*/
if ((node = OF_finddevice("soc")) != 0)
if ((node = OF_finddevice("soc")) != -1)
if (fdt_is_compatible_strict(node, "simple-bus"))
goto moveon;
/*
* Find the node the long way.
*/
if ((node = OF_finddevice("/")) == 0)
if ((node = OF_finddevice("/")) == -1)
return (ENXIO);
if ((node = fdt_find_compatible(node, "simple-bus", 1)) == 0)
@ -576,7 +576,7 @@ fdt_get_mem_regions(struct mem_region *mr, int *mrcnt, uint32_t *memsize)
max_size = sizeof(reg);
memory = OF_finddevice("/memory");
if (memory <= 0) {
if (memory == -1) {
rv = ENXIO;
goto out;
}

View File

@ -62,7 +62,7 @@ fdt_fixup_busfreq(phandle_t root)
* This fixup uses /cpus/ bus-frequency prop value to set simple-bus
* bus-frequency property.
*/
if ((cpus = OF_finddevice("/cpus")) == 0)
if ((cpus = OF_finddevice("/cpus")) == -1)
return;
if ((child = OF_child(cpus)) == 0)

View File

@ -177,7 +177,7 @@ fdtbus_attach(device_t dev)
u_long start, end;
int error;
if ((root = OF_peer(0)) == 0)
if ((root = OF_finddevice("/")) == -1)
panic("fdtbus_attach: no root node.");
sc = device_get_softc(dev);

View File

@ -392,6 +392,8 @@ ofw_fdt_finddevice(ofw_t ofw, const char *device)
int offset;
offset = fdt_path_offset(fdtp, device);
if (offset < 0)
return (-1);
return (fdt_offset_phandle(offset));
}
@ -420,7 +422,7 @@ ofw_fdt_fixup(ofw_t ofw)
ssize_t len;
int i;
if ((root = ofw_fdt_finddevice(ofw, "/")) == 0)
if ((root = ofw_fdt_finddevice(ofw, "/")) == -1)
return (ENODEV);
if ((len = ofw_fdt_getproplen(ofw, root, "model")) <= 0)

View File

@ -131,7 +131,7 @@ OF_init(void *cookie)
rv = OFW_INIT(ofw_obj, cookie);
if ((chosen = OF_finddevice("/chosen")) > 0)
if ((chosen = OF_finddevice("/chosen")) != -1)
if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
stdout = -1;

View File

@ -155,11 +155,11 @@ uart_cpu_getdev(int devtype, struct uart_devinfo *di)
/*
* Retrieve /chosen/std{in,out}.
*/
if ((chosen = OF_finddevice("/chosen")) == 0)
if ((chosen = OF_finddevice("/chosen")) == -1)
return (ENXIO);
if (OF_getprop(chosen, "stdin", buf, sizeof(buf)) <= 0)
return (ENXIO);
if ((node = OF_finddevice(buf)) == 0)
if ((node = OF_finddevice(buf)) == -1)
return (ENXIO);
if (OF_getprop(chosen, "stdout", buf, sizeof(buf)) <= 0)
return (ENXIO);

View File

@ -189,7 +189,7 @@ bare_timebase_freq(platform_t plat, struct cpuref *cpuref)
} else
ticks = 0;
if ((cpus = OF_finddevice("/cpus")) == 0)
if ((cpus = OF_finddevice("/cpus")) == -1)
goto out;
if ((child = OF_child(cpus)) == 0)

View File

@ -163,7 +163,7 @@ powermac_smp_first_cpu(platform_t plat, struct cpuref *cpuref)
* but it can be found directly
*/
dev = OF_finddevice("/cpus");
if (dev == 0)
if (dev == -1)
return (ENOENT);
}
@ -209,7 +209,7 @@ powermac_smp_get_bsp(platform_t plat, struct cpuref *cpuref)
int res;
chosen = OF_finddevice("/chosen");
if (chosen == 0)
if (chosen == -1)
return (ENXIO);
res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));

View File

@ -52,7 +52,7 @@ OF_getetheraddr(device_t dev, u_char *addr)
phandle_t node;
struct idprom idp;
if ((node = OF_finddevice("/options")) > 0 &&
if ((node = OF_finddevice("/options")) != -1 &&
OF_getprop(node, "local-mac-address?", buf, sizeof(buf)) > 0) {
buf[sizeof(buf) - 1] = '\0';
if (strcmp(buf, "true") == 0 &&

View File

@ -368,7 +368,7 @@ cpu_reset(void)
(cell_t)bspec
};
if ((chosen = OF_finddevice("/chosen")) != 0) {
if ((chosen = OF_finddevice("/chosen")) != -1) {
if (OF_getprop(chosen, "bootpath", bspec, sizeof(bspec)) == -1)
bspec[0] = '\0';
bspec[sizeof(bspec) - 1] = '\0';