diff options
author | Oleksandr Tymoshenko <gonzo@FreeBSD.org> | 2018-03-20 00:03:49 +0000 |
---|---|---|
committer | Oleksandr Tymoshenko <gonzo@FreeBSD.org> | 2018-03-20 00:03:49 +0000 |
commit | 108117cc22335234f817584a42704258209ca78c (patch) | |
tree | 35821278566f932eed35ee949df3ea3e14a796a3 /sys | |
parent | 5f5baf0e9697eea27a5a8e77fbdb639397f7f388 (diff) | |
download | src-108117cc22335234f817584a42704258209ca78c.tar.gz src-108117cc22335234f817584a42704258209ca78c.zip |
[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
Notes
Notes:
svn path=/head/; revision=331229
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arm/amlogic/aml8726/aml8726_clkmsr.c | 4 | ||||
-rw-r--r-- | sys/arm/amlogic/aml8726/aml8726_mp.c | 4 | ||||
-rw-r--r-- | sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c | 2 | ||||
-rw-r--r-- | sys/arm/annapurna/alpine/alpine_machdep.c | 2 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_fb.c | 4 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_fbd.c | 2 | ||||
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_machdep.c | 2 | ||||
-rw-r--r-- | sys/arm/freescale/fsl_ocotp.c | 2 | ||||
-rw-r--r-- | sys/arm/freescale/vybrid/vf_machdep.c | 2 | ||||
-rw-r--r-- | sys/arm/mv/mv_common.c | 4 | ||||
-rw-r--r-- | sys/arm/samsung/exynos/chrome_ec.c | 2 | ||||
-rw-r--r-- | sys/arm/samsung/exynos/exynos5_ehci.c | 2 | ||||
-rw-r--r-- | sys/arm/ti/am335x/am335x_lcd.c | 2 | ||||
-rw-r--r-- | sys/arm/ti/am335x/am335x_lcd_syscons.c | 2 | ||||
-rw-r--r-- | sys/dev/fdt/fdt_common.c | 4 | ||||
-rw-r--r-- | sys/dev/ofw/ofw_subr.c | 2 | ||||
-rw-r--r-- | sys/dev/ofw/openfirmio.c | 2 | ||||
-rw-r--r-- | sys/dev/ow/owc_gpiobus.c | 2 | ||||
-rw-r--r-- | sys/dev/vnic/thunder_bgx_fdt.c | 2 | ||||
-rw-r--r-- | sys/powerpc/cpufreq/mpc85xx_jog.c | 2 | ||||
-rw-r--r-- | sys/powerpc/pseries/platform_chrp.c | 2 |
21 files changed, 26 insertions, 26 deletions
diff --git a/sys/arm/amlogic/aml8726/aml8726_clkmsr.c b/sys/arm/amlogic/aml8726/aml8726_clkmsr.c index 43faa128e2cb..0cfbf775a352 100644 --- a/sys/arm/amlogic/aml8726/aml8726_clkmsr.c +++ b/sys/arm/amlogic/aml8726/aml8726_clkmsr.c @@ -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, diff --git a/sys/arm/amlogic/aml8726/aml8726_mp.c b/sys/arm/amlogic/aml8726/aml8726_mp.c index 72bc95960d2f..858445c8110c 100644 --- a/sys/arm/amlogic/aml8726/aml8726_mp.c +++ b/sys/arm/amlogic/aml8726/aml8726_mp.c @@ -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) diff --git a/sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c b/sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c index c24cd23334e0..fbf18b796009 100644 --- a/sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c +++ b/sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c @@ -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) diff --git a/sys/arm/annapurna/alpine/alpine_machdep.c b/sys/arm/annapurna/alpine/alpine_machdep.c index e57b360140eb..1b31da41d2ca 100644 --- a/sys/arm/annapurna/alpine/alpine_machdep.c +++ b/sys/arm/annapurna/alpine/alpine_machdep.c @@ -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) diff --git a/sys/arm/broadcom/bcm2835/bcm2835_fb.c b/sys/arm/broadcom/bcm2835/bcm2835_fb.c index a87fdc3e5497..dcc4f5b7fa3f 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_fb.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_fb.c @@ -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", diff --git a/sys/arm/broadcom/bcm2835/bcm2835_fbd.c b/sys/arm/broadcom/bcm2835/bcm2835_fbd.c index 0555968a91c4..9a2b3277856f 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_fbd.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_fbd.c @@ -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) { diff --git a/sys/arm/broadcom/bcm2835/bcm2835_machdep.c b/sys/arm/broadcom/bcm2835/bcm2835_machdep.c index de4b1bb4342b..6ac1ffeea27c 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_machdep.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_machdep.c @@ -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) diff --git a/sys/arm/freescale/fsl_ocotp.c b/sys/arm/freescale/fsl_ocotp.c index 9a0f9b4ec62f..6b64686f7869 100644 --- a/sys/arm/freescale/fsl_ocotp.c +++ b/sys/arm/freescale/fsl_ocotp.c @@ -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; diff --git a/sys/arm/freescale/vybrid/vf_machdep.c b/sys/arm/freescale/vybrid/vf_machdep.c index bc8e679321f3..6c5b7bcf3755 100644 --- a/sys/arm/freescale/vybrid/vf_machdep.c +++ b/sys/arm/freescale/vybrid/vf_machdep.c @@ -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); } diff --git a/sys/arm/mv/mv_common.c b/sys/arm/mv/mv_common.c index a9c6e4703aee..74fa0cfa552b 100644 --- a/sys/arm/mv/mv_common.c +++ b/sys/arm/mv/mv_common.c @@ -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)); diff --git a/sys/arm/samsung/exynos/chrome_ec.c b/sys/arm/samsung/exynos/chrome_ec.c index 8f794b79c7ee..d11971636efc 100644 --- a/sys/arm/samsung/exynos/chrome_ec.c +++ b/sys/arm/samsung/exynos/chrome_ec.c @@ -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; diff --git a/sys/arm/samsung/exynos/exynos5_ehci.c b/sys/arm/samsung/exynos/exynos5_ehci.c index a9f031474cb2..30865f245119 100644 --- a/sys/arm/samsung/exynos/exynos5_ehci.c +++ b/sys/arm/samsung/exynos/exynos5_ehci.c @@ -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); } diff --git a/sys/arm/ti/am335x/am335x_lcd.c b/sys/arm/ti/am335x/am335x_lcd.c index 857444f95824..c75a4b469234 100644 --- a/sys/arm/ti/am335x/am335x_lcd.c +++ b/sys/arm/ti/am335x/am335x_lcd.c @@ -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); } diff --git a/sys/arm/ti/am335x/am335x_lcd_syscons.c b/sys/arm/ti/am335x/am335x_lcd_syscons.c index 9522c9679a52..40e416675598 100644 --- a/sys/arm/ti/am335x/am335x_lcd_syscons.c +++ b/sys/arm/ti/am335x/am335x_lcd_syscons.c @@ -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) diff --git a/sys/dev/fdt/fdt_common.c b/sys/dev/fdt/fdt_common.c index be7dd218e5fb..a927cb9e90e2 100644 --- a/sys/dev/fdt/fdt_common.c +++ b/sys/dev/fdt/fdt_common.c @@ -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) diff --git a/sys/dev/ofw/ofw_subr.c b/sys/dev/ofw/ofw_subr.c index 25da73154ff4..f183c60d62c0 100644 --- a/sys/dev/ofw/ofw_subr.c +++ b/sys/dev/ofw/ofw_subr.c @@ -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) { diff --git a/sys/dev/ofw/openfirmio.c b/sys/dev/ofw/openfirmio.c index 1ea8f022629e..a6ee962b5c8f 100644 --- a/sys/dev/ofw/openfirmio.c +++ b/sys/dev/ofw/openfirmio.c @@ -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; } diff --git a/sys/dev/ow/owc_gpiobus.c b/sys/dev/ow/owc_gpiobus.c index 423dde811b9f..f03d01432b03 100644 --- a/sys/dev/ow/owc_gpiobus.c +++ b/sys/dev/ow/owc_gpiobus.c @@ -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")) diff --git a/sys/dev/vnic/thunder_bgx_fdt.c b/sys/dev/vnic/thunder_bgx_fdt.c index 0998e0ec6685..380d7f90697e 100644 --- a/sys/dev/vnic/thunder_bgx_fdt.c +++ b/sys/dev/vnic/thunder_bgx_fdt.c @@ -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; } diff --git a/sys/powerpc/cpufreq/mpc85xx_jog.c b/sys/powerpc/cpufreq/mpc85xx_jog.c index bb37889567f2..bbdc7193054f 100644 --- a/sys/powerpc/cpufreq/mpc85xx_jog.c +++ b/sys/powerpc/cpufreq/mpc85xx_jog.c @@ -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++) diff --git a/sys/powerpc/pseries/platform_chrp.c b/sys/powerpc/pseries/platform_chrp.c index 678e28ba20c1..9424a699e034 100644 --- a/sys/powerpc/pseries/platform_chrp.c +++ b/sys/powerpc/pseries/platform_chrp.c @@ -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)) { |