commit 81076e8aa4cbf23c8ad890ec8515f7917bae2ab8 Author: Jayachandran C Date: Tue Oct 18 00:57:46 2011 +0530 OF_finddevice should return -1 on error Fix the implementation, and fixup the callers. diff --git a/sys/dev/fdt/fdt_common.c b/sys/dev/fdt/fdt_common.c index d25715b..8702df2 100644 --- a/sys/dev/fdt/fdt_common.c +++ b/sys/dev/fdt/fdt_common.c @@ -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; } diff --git a/sys/dev/fdt/fdtbus.c b/sys/dev/fdt/fdtbus.c index e2808d1..d5296a9 100644 --- a/sys/dev/fdt/fdtbus.c +++ b/sys/dev/fdt/fdtbus.c @@ -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); diff --git a/sys/dev/ofw/ofw_fdt.c b/sys/dev/ofw/ofw_fdt.c index 806f17c..7b3b0e9 100644 --- a/sys/dev/ofw/ofw_fdt.c +++ b/sys/dev/ofw/ofw_fdt.c @@ -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) diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c index a8cb8f7..f543dce 100644 --- a/sys/dev/ofw/openfirm.c +++ b/sys/dev/ofw/openfirm.c @@ -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; diff --git a/sys/dev/uart/uart_bus_fdt.c b/sys/dev/uart/uart_bus_fdt.c index 4209866..8bb62ea 100644 --- a/sys/dev/uart/uart_bus_fdt.c +++ b/sys/dev/uart/uart_bus_fdt.c @@ -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);