svn commit: r228201 - in head/sys: arm/mv dev/fdt dev/ofw dev/uart
powerpc/booke powerpc/powermac sparc64/sparc64
Jayachandran C.
jchandra at FreeBSD.org
Fri Dec 2 15:24:40 UTC 2011
Author: jchandra
Date: Fri Dec 2 15:24:39 2011
New Revision: 228201
URL: http://svn.freebsd.org/changeset/base/228201
Log:
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
Modified:
head/sys/arm/mv/common.c
head/sys/arm/mv/mv_machdep.c
head/sys/dev/fdt/fdt_common.c
head/sys/dev/fdt/fdt_powerpc.c
head/sys/dev/fdt/fdtbus.c
head/sys/dev/ofw/ofw_fdt.c
head/sys/dev/ofw/openfirm.c
head/sys/dev/uart/uart_bus_fdt.c
head/sys/powerpc/booke/platform_bare.c
head/sys/powerpc/powermac/platform_powermac.c
head/sys/sparc64/sparc64/ofw_machdep.c
head/sys/sparc64/sparc64/vm_machdep.c
Modified: head/sys/arm/mv/common.c
==============================================================================
--- head/sys/arm/mv/common.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/arm/mv/common.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -1693,7 +1693,7 @@ fdt_get_ranges(const char *nodename, voi
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);
Modified: head/sys/arm/mv/mv_machdep.c
==============================================================================
--- head/sys/arm/mv/mv_machdep.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/arm/mv/mv_machdep.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -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;
Modified: head/sys/dev/fdt/fdt_common.c
==============================================================================
--- head/sys/dev/fdt/fdt_common.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/dev/fdt/fdt_common.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -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 *m
max_size = sizeof(reg);
memory = OF_finddevice("/memory");
- if (memory <= 0) {
+ if (memory == -1) {
rv = ENXIO;
goto out;
}
Modified: head/sys/dev/fdt/fdt_powerpc.c
==============================================================================
--- head/sys/dev/fdt/fdt_powerpc.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/dev/fdt/fdt_powerpc.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -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)
Modified: head/sys/dev/fdt/fdtbus.c
==============================================================================
--- head/sys/dev/fdt/fdtbus.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/dev/fdt/fdtbus.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -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);
Modified: head/sys/dev/ofw/ofw_fdt.c
==============================================================================
--- head/sys/dev/ofw/ofw_fdt.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/dev/ofw/ofw_fdt.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -392,6 +392,8 @@ ofw_fdt_finddevice(ofw_t ofw, const char
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)
Modified: head/sys/dev/ofw/openfirm.c
==============================================================================
--- head/sys/dev/ofw/openfirm.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/dev/ofw/openfirm.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -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;
Modified: head/sys/dev/uart/uart_bus_fdt.c
==============================================================================
--- head/sys/dev/uart/uart_bus_fdt.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/dev/uart/uart_bus_fdt.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -155,11 +155,11 @@ uart_cpu_getdev(int devtype, struct uart
/*
* 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);
Modified: head/sys/powerpc/booke/platform_bare.c
==============================================================================
--- head/sys/powerpc/booke/platform_bare.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/powerpc/booke/platform_bare.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -189,7 +189,7 @@ bare_timebase_freq(platform_t plat, stru
} else
ticks = 0;
- if ((cpus = OF_finddevice("/cpus")) == 0)
+ if ((cpus = OF_finddevice("/cpus")) == -1)
goto out;
if ((child = OF_child(cpus)) == 0)
Modified: head/sys/powerpc/powermac/platform_powermac.c
==============================================================================
--- head/sys/powerpc/powermac/platform_powermac.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/powerpc/powermac/platform_powermac.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -163,7 +163,7 @@ powermac_smp_first_cpu(platform_t plat,
* 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, st
int res;
chosen = OF_finddevice("/chosen");
- if (chosen == 0)
+ if (chosen == -1)
return (ENXIO);
res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));
Modified: head/sys/sparc64/sparc64/ofw_machdep.c
==============================================================================
--- head/sys/sparc64/sparc64/ofw_machdep.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/sparc64/sparc64/ofw_machdep.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -52,7 +52,7 @@ OF_getetheraddr(device_t dev, u_char *ad
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 &&
Modified: head/sys/sparc64/sparc64/vm_machdep.c
==============================================================================
--- head/sys/sparc64/sparc64/vm_machdep.c Fri Dec 2 12:52:33 2011 (r228200)
+++ head/sys/sparc64/sparc64/vm_machdep.c Fri Dec 2 15:24:39 2011 (r228201)
@@ -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';
More information about the svn-src-head
mailing list