[U-Boot] [PATCH 006/080] lib: fdtdec: Fix some style violations

Mario Six mario.six at gdsys.cc
Fri Sep 29 12:51:24 UTC 2017


Fix some style violations in fdtdec.c, and reduce the scope of some
variables.

Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
 lib/fdtdec.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index f354a1f9af..b291c155a9 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -230,10 +230,10 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
 				addr->phys_mid = fdt32_to_cpu(cell[1]);
 				addr->phys_lo = fdt32_to_cpu(cell[1]);
 				break;
-			} else {
-				cell += (FDT_PCI_ADDR_CELLS +
-					 FDT_PCI_SIZE_CELLS);
 			}
+
+			cell += (FDT_PCI_ADDR_CELLS +
+				 FDT_PCI_SIZE_CELLS);
 		}
 
 		if (i == num) {
@@ -242,10 +242,10 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
 		}
 
 		return 0;
-	} else {
-		ret = -EINVAL;
 	}
 
+	ret = -EINVAL;
+
 fail:
 	debug("(not found)\n");
 	return ret;
@@ -262,11 +262,9 @@ int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
 
 	end = list + len;
 	while (list < end) {
-		char *s;
-
 		len = strlen(list);
 		if (len >= strlen("pciVVVV,DDDD")) {
-			s = strstr(list, "pci");
+			char *s = strstr(list, "pci");
 
 			/*
 			 * check if the string is something like pciVVVV,DDDD.RR
@@ -296,7 +294,7 @@ int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr,
 
 	/* extract the bar number from fdt_pci_addr */
 	barnum = addr->phys_hi & 0xff;
-	if ((barnum < PCI_BASE_ADDRESS_0) || (barnum > PCI_CARDBUS_CIS))
+	if (barnum < PCI_BASE_ADDRESS_0 || barnum > PCI_CARDBUS_CIS)
 		return -EINVAL;
 
 	barnum = (barnum - PCI_BASE_ADDRESS_0) / 4;
@@ -332,7 +330,7 @@ int fdtdec_get_is_enabled(const void *blob, int node)
 	 */
 	cell = fdt_getprop(blob, node, "status", NULL);
 	if (cell)
-		return 0 == strcmp(cell, "okay");
+		return strcmp(cell, "okay") == 0;
 	return 1;
 }
 
@@ -342,8 +340,8 @@ enum fdt_compat_id fdtdec_lookup(const void *blob, int node)
 
 	/* Search our drivers */
 	for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++)
-		if (0 == fdt_node_check_compatible(blob, node,
-				compat_names[id]))
+		if (fdt_node_check_compatible(blob, node,
+					      compat_names[id]) == 0)
 			return id;
 	return COMPAT_UNKNOWN;
 }
@@ -662,12 +660,14 @@ int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
 			 u32 *array, int count)
 {
 	const u32 *cell;
-	int i, err = 0;
+	int err = 0;
 
 	debug("%s: %s\n", __func__, prop_name);
 	cell = get_prop_check_min_len(blob, node, prop_name,
 				      sizeof(u32) * count, &err);
 	if (!err) {
+		int i;
+
 		for (i = 0; i < count; i++)
 			array[i] = fdt32_to_cpu(cell[i]);
 	}
@@ -972,7 +972,8 @@ int fdt_get_resource(const void *fdt, int node, const char *property,
 
 	while (ptr + na + ns <= end) {
 		if (i == index) {
-			res->start = res->end = fdtdec_get_number(ptr, na);
+			res->start = fdtdec_get_number(ptr, na);
+			res->end = res->start;
 			res->end += fdtdec_get_number(&ptr[na], ns) - 1;
 			return 0;
 		}
@@ -1224,7 +1225,7 @@ int fdtdec_setup(void)
 #  elif defined CONFIG_FIT_EMBED
 	gd->fdt_blob = locate_dtb_in_fit(&_end);
 
-	if (gd->fdt_blob == NULL || gd->fdt_blob <= ((void *)&_end)) {
+	if (!gd->fdt_blob || gd->fdt_blob <= ((void *)&_end)) {
 		puts("Failed to find proper dtb in embedded FIT Image\n");
 		return -1;
 	}
-- 
2.11.0



More information about the U-Boot mailing list