Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Mar 2018 00:03:50 +0000 (UTC)
From:      Oleksandr Tymoshenko <gonzo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r331229 - in head/sys: arm/amlogic/aml8726 arm/annapurna/alpine arm/broadcom/bcm2835 arm/freescale arm/freescale/vybrid arm/mv arm/samsung/exynos arm/ti/am335x dev/fdt dev/ofw dev/ow de...
Message-ID:  <201803200003.w2K03oxD019032@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gonzo
Date: Tue Mar 20 00:03:49 2018
New Revision: 331229
URL: https://svnweb.freebsd.org/changeset/base/331229

Log:
  [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

Modified:
  head/sys/arm/amlogic/aml8726/aml8726_clkmsr.c
  head/sys/arm/amlogic/aml8726/aml8726_mp.c
  head/sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c
  head/sys/arm/annapurna/alpine/alpine_machdep.c
  head/sys/arm/broadcom/bcm2835/bcm2835_fb.c
  head/sys/arm/broadcom/bcm2835/bcm2835_fbd.c
  head/sys/arm/broadcom/bcm2835/bcm2835_machdep.c
  head/sys/arm/freescale/fsl_ocotp.c
  head/sys/arm/freescale/vybrid/vf_machdep.c
  head/sys/arm/mv/mv_common.c
  head/sys/arm/samsung/exynos/chrome_ec.c
  head/sys/arm/samsung/exynos/exynos5_ehci.c
  head/sys/arm/ti/am335x/am335x_lcd.c
  head/sys/arm/ti/am335x/am335x_lcd_syscons.c
  head/sys/dev/fdt/fdt_common.c
  head/sys/dev/ofw/ofw_subr.c
  head/sys/dev/ofw/openfirmio.c
  head/sys/dev/ow/owc_gpiobus.c
  head/sys/dev/vnic/thunder_bgx_fdt.c
  head/sys/powerpc/cpufreq/mpc85xx_jog.c
  head/sys/powerpc/pseries/platform_chrp.c

Modified: head/sys/arm/amlogic/aml8726/aml8726_clkmsr.c
==============================================================================
--- head/sys/arm/amlogic/aml8726/aml8726_clkmsr.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/amlogic/aml8726/aml8726_clkmsr.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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,

Modified: head/sys/arm/amlogic/aml8726/aml8726_mp.c
==============================================================================
--- head/sys/arm/amlogic/aml8726/aml8726_mp.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/amlogic/aml8726/aml8726_mp.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -178,7 +178,7 @@ find_node_for_device(const char *device, const char **
 	 * 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 **
 	 */
 
 	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)

Modified: head/sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c
==============================================================================
--- head/sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/amlogic/aml8726/aml8726_usb_phy-m3.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -117,7 +117,7 @@ aml8726_usb_phy_mode(const char *dwcotg_path, uint32_t
 	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)

Modified: head/sys/arm/annapurna/alpine/alpine_machdep.c
==============================================================================
--- head/sys/arm/annapurna/alpine/alpine_machdep.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/annapurna/alpine/alpine_machdep.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -71,7 +71,7 @@ alpine_get_devmap_base(bus_addr_t *pa, bus_addr_t *siz
 {
 	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)

Modified: head/sys/arm/broadcom/bcm2835/bcm2835_fb.c
==============================================================================
--- head/sys/arm/broadcom/bcm2835/bcm2835_fb.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/broadcom/bcm2835/bcm2835_fb.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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",

Modified: head/sys/arm/broadcom/bcm2835/bcm2835_fbd.c
==============================================================================
--- head/sys/arm/broadcom/bcm2835/bcm2835_fbd.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/broadcom/bcm2835/bcm2835_fbd.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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) {

Modified: head/sys/arm/broadcom/bcm2835/bcm2835_machdep.c
==============================================================================
--- head/sys/arm/broadcom/bcm2835/bcm2835_machdep.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/broadcom/bcm2835/bcm2835_machdep.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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)

Modified: head/sys/arm/freescale/fsl_ocotp.c
==============================================================================
--- head/sys/arm/freescale/fsl_ocotp.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/freescale/fsl_ocotp.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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;

Modified: head/sys/arm/freescale/vybrid/vf_machdep.c
==============================================================================
--- head/sys/arm/freescale/vybrid/vf_machdep.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/freescale/vybrid/vf_machdep.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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);
 		}

Modified: head/sys/arm/mv/mv_common.c
==============================================================================
--- head/sys/arm/mv/mv_common.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/mv/mv_common.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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));

Modified: head/sys/arm/samsung/exynos/chrome_ec.c
==============================================================================
--- head/sys/arm/samsung/exynos/chrome_ec.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/samsung/exynos/chrome_ec.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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;

Modified: head/sys/arm/samsung/exynos/exynos5_ehci.c
==============================================================================
--- head/sys/arm/samsung/exynos/exynos5_ehci.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/samsung/exynos/exynos5_ehci.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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);
 	}
 

Modified: head/sys/arm/ti/am335x/am335x_lcd.c
==============================================================================
--- head/sys/arm/ti/am335x/am335x_lcd.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/ti/am335x/am335x_lcd.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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);
 	}

Modified: head/sys/arm/ti/am335x/am335x_lcd_syscons.c
==============================================================================
--- head/sys/arm/ti/am335x/am335x_lcd_syscons.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/arm/ti/am335x/am335x_lcd_syscons.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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)

Modified: head/sys/dev/fdt/fdt_common.c
==============================================================================
--- head/sys/dev/fdt/fdt_common.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/dev/fdt/fdt_common.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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)

Modified: head/sys/dev/ofw/ofw_subr.c
==============================================================================
--- head/sys/dev/ofw/ofw_subr.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/dev/ofw/ofw_subr.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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) {

Modified: head/sys/dev/ofw/openfirmio.c
==============================================================================
--- head/sys/dev/ofw/openfirmio.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/dev/ofw/openfirmio.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -247,7 +247,7 @@ openfirm_ioctl(struct cdev *dev, u_long cmd, caddr_t d
 		if (error)
 			break;
 		node = OF_finddevice(name);
-		if (node == 0 || node == -1) {
+		if (node == -1) {
 			error = ENOENT;
 			break;
 		}

Modified: head/sys/dev/ow/owc_gpiobus.c
==============================================================================
--- head/sys/dev/ow/owc_gpiobus.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/dev/ow/owc_gpiobus.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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"))

Modified: head/sys/dev/vnic/thunder_bgx_fdt.c
==============================================================================
--- head/sys/dev/vnic/thunder_bgx_fdt.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/dev/vnic/thunder_bgx_fdt.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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;
 	}

Modified: head/sys/powerpc/cpufreq/mpc85xx_jog.c
==============================================================================
--- head/sys/powerpc/cpufreq/mpc85xx_jog.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/powerpc/cpufreq/mpc85xx_jog.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -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++)

Modified: head/sys/powerpc/pseries/platform_chrp.c
==============================================================================
--- head/sys/powerpc/pseries/platform_chrp.c	Mon Mar 19 23:21:45 2018	(r331228)
+++ head/sys/powerpc/pseries/platform_chrp.c	Tue Mar 20 00:03:49 2018	(r331229)
@@ -291,7 +291,7 @@ chrp_timebase_freq(platform_t plat, struct cpuref *cpu
 	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)) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803200003.w2K03oxD019032>