[ofw] fix errneous checks for OF_finddevice(9) return value

OF_finddevices returns ((phandle_t)-1) in case of failure. Some code
in existing drivers checked return value to be equal to 0 or
less/equal to 0 which is also wrong because phandle_t is unsigned
type. Most of these checks were for negative cases that were never
triggered so trhere was no impact on functionality.

Reviewed by:	nwhitehorn
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D14645
This commit is contained in:
Oleksandr Tymoshenko 2018-03-20 00:03:49 +00:00
parent 5f5baf0e96
commit 108117cc22
21 changed files with 26 additions and 26 deletions

View File

@ -255,14 +255,14 @@ aml8726_clkmsr_bus_frequency()
* Try to access the clkmsr node directly i.e. through /aliases/.
*/
if ((node = OF_finddevice("clkmsr")) != 0)
if ((node = OF_finddevice("clkmsr")) != -1)
if (fdt_is_compatible_strict(node, "amlogic,aml8726-clkmsr"))
goto moveon;
/*
* Find the node the long way.
*/
if ((node = OF_finddevice("/soc")) == 0)
if ((node = OF_finddevice("/soc")) == -1)
return (0);
if ((node = fdt_find_compatible(node,

View File

@ -178,7 +178,7 @@ find_node_for_device(const char *device, const char **compatible)
* Try to access the node directly i.e. through /aliases/.
*/
if ((node = OF_finddevice(device)) != 0)
if ((node = OF_finddevice(device)) != -1)
for (i = 0; compatible[i]; i++)
if (fdt_is_compatible_strict(node, compatible[i]))
return node;
@ -188,7 +188,7 @@ find_node_for_device(const char *device, const char **compatible)
*/
for (i = 0; compatible[i]; i++) {
if ((node = OF_finddevice("/soc")) == 0)
if ((node = OF_finddevice("/soc")) == -1)
return (0);
if ((node = fdt_find_compatible(node, compatible[i], 1)) != 0)

View File

@ -117,7 +117,7 @@ aml8726_usb_phy_mode(const char *dwcotg_path, uint32_t *mode)
phandle_t node;
ssize_t len;
if ((node = OF_finddevice(dwcotg_path)) == 0)
if ((node = OF_finddevice(dwcotg_path)) == -1)
return (ENXIO);
if (fdt_is_compatible_strict(node, "synopsys,designware-hs-otg2") == 0)

View File

@ -71,7 +71,7 @@ alpine_get_devmap_base(bus_addr_t *pa, bus_addr_t *size)
{
phandle_t node;
if ((node = OF_finddevice("/")) == 0)
if ((node = OF_finddevice("/")) == -1)
return (ENXIO);
if ((node = fdt_find_compatible(node, "simple-bus", 1)) == 0)

View File

@ -452,7 +452,7 @@ bcmfb_configure(int flags)
* finally go with defaults if everything else has failed.
*/
chosen = OF_finddevice("/chosen");
if (chosen != 0 &&
if (chosen != -1 &&
OF_getprop(chosen, "bootargs", &bootargs, sizeof(bootargs)) > 0) {
p = bootargs;
while ((v = strsep(&p, " ")) != NULL) {
@ -472,7 +472,7 @@ bcmfb_configure(int flags)
}
root = OF_finddevice("/");
if ((root != 0) &&
if ((root != -1) &&
(display = fdt_find_compatible(root, "broadcom,bcm2835-fb", 1))) {
if (sc->width == 0) {
if ((OF_getencprop(display, "broadcom,width",

View File

@ -223,7 +223,7 @@ bcm_fb_attach(device_t dev)
/* Newer firmware versions needs an inverted color palette. */
sc->fbswap = 0;
chosen = OF_finddevice("/chosen");
if (chosen != 0 &&
if (chosen != -1 &&
OF_getprop(chosen, "bootargs", &bootargs, sizeof(bootargs)) > 0) {
p = bootargs;
while ((v = strsep(&p, " ")) != NULL) {

View File

@ -81,7 +81,7 @@ bcm2835_late_init(platform_t plat)
int len;
system = OF_finddevice("/system");
if (system != 0) {
if (system != -1) {
len = OF_getencprop(system, "linux,serial", cells,
sizeof(cells));
if (len > 0)

View File

@ -72,7 +72,7 @@ fsl_ocotp_devmap(void)
phandle_t child, root;
u_long base, size;
if ((root = OF_finddevice("/")) == 0)
if ((root = OF_finddevice("/")) == -1)
goto fatal;
if ((child = fdt_depth_search_compatible(root, "fsl,imx6q-ocotp", 0)) == 0)
goto fatal;

View File

@ -68,7 +68,7 @@ vf_cpu_reset(platform_t plat)
goto end;
src = OF_finddevice("src");
if ((src != 0) && (OF_getencprop(src, "reg", &paddr, sizeof(paddr))) > 0) {
if ((src != -1) && (OF_getencprop(src, "reg", &paddr, sizeof(paddr))) > 0) {
if (bus_space_map(fdtbus_bs_tag, paddr, 0x10, 0, &vaddr) == 0) {
bus_space_write_4(fdtbus_bs_tag, vaddr, 0x00, SW_RST);
}

View File

@ -2367,7 +2367,7 @@ win_cpu_from_dt(void)
if (ofw_bus_node_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)
@ -2551,7 +2551,7 @@ fdt_fixup_busfreq(phandle_t root)
/*
* Fix bus speed in cpu node
*/
if ((sb = OF_finddevice("cpu")) != 0)
if ((sb = OF_finddevice("cpu")) != -1)
if (fdt_is_compatible_strict(sb, "ARM,88VS584"))
OF_setprop(sb, "bus-frequency", (void *)&freq,
sizeof(freq));

View File

@ -225,7 +225,7 @@ configure_i2c_arbitrator(struct ec_softc *sc)
/* TODO: look for compatible entry instead of hard-coded path */
arbitrator = OF_finddevice("/i2c-arbitrator");
if (arbitrator > 0 &&
if (arbitrator != -1 &&
OF_hasprop(arbitrator, "freebsd,our-gpio") &&
OF_hasprop(arbitrator, "freebsd,ec-gpio")) {
sc->have_arbitrator = 1;

View File

@ -240,7 +240,7 @@ phy_init(struct exynos_ehci_softc *esc)
reg &= ~(HOST_CTRL_RESET_LINK);
bus_space_write_4(esc->host_bst, esc->host_bsh, 0x0, reg);
if ((hub = OF_finddevice("/hsichub")) != 0) {
if ((hub = OF_finddevice("/hsichub")) != -1) {
reset_hsic_hub(esc, hub);
}

View File

@ -961,7 +961,7 @@ am335x_lcd_attach(device_t dev)
am335x_read_hdmi_property(dev);
root = OF_finddevice("/");
if (root == 0) {
if (root == -1) {
device_printf(dev, "failed to get FDT root node\n");
return (ENXIO);
}

View File

@ -382,7 +382,7 @@ am335x_syscons_configure(int flags)
* to fetch data from FDT and go with defaults if failed
*/
root = OF_finddevice("/");
if ((root != 0) &&
if ((root != -1) &&
(display = am335x_syscons_find_panel_node(root))) {
if ((OF_getencprop(display, "panel_width", &cell,
sizeof(cell))) > 0)

View File

@ -215,13 +215,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(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", 0)) == 0)

View File

@ -232,7 +232,7 @@ ofw_parse_bootargs(void)
int err;
chosen = OF_finddevice("/chosen");
if (chosen <= 0)
if (chosen == -1)
return (chosen);
if ((err = OF_getprop(chosen, "bootargs", buf, sizeof(buf))) != -1) {

View File

@ -247,7 +247,7 @@ openfirm_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
if (error)
break;
node = OF_finddevice(name);
if (node == 0 || node == -1) {
if (node == -1) {
error = ENOENT;
break;
}

View File

@ -85,7 +85,7 @@ owc_gpiobus_identify(driver_t *driver, device_t bus)
* bus overwrites the description.
*/
root = OF_finddevice("/");
if (root == 0)
if (root == -1)
return;
for (w1 = OF_child(root); w1 != 0; w1 = OF_peer(w1)) {
if (!fdt_is_compatible_strict(w1, "w1-gpio"))

View File

@ -336,7 +336,7 @@ bgx_fdt_find_node(struct bgx *bgx)
snprintf(bgx_sel, len + 1, "/"BGX_NODE_NAME"%d", bgx->bgx_id);
/* First try the root node */
node = OF_finddevice(bgx_sel);
if ((int)node > 0) {
if (node != -1) {
/* Found relevant node */
goto out;
}

View File

@ -129,7 +129,7 @@ mpc85xx_jog_devcompat()
int i;
node = OF_finddevice("/soc");
if (node <= 0)
if (node == -1)
return (NULL);
for (i = 0; jog_compat[i].ocd_str != NULL; i++)

View File

@ -291,7 +291,7 @@ chrp_timebase_freq(platform_t plat, struct cpuref *cpuref)
char buf[8];
cpus = OF_finddevice("/cpus");
if (cpus <= 0)
if (cpus == -1)
panic("CPU tree not found on Open Firmware\n");
for (cpunode = OF_child(cpus); cpunode != 0; cpunode = OF_peer(cpunode)) {