[PATCH] ppc64: fix call_prom return checks

Benjamin Herrenschmidt benh at kernel.crashing.org
Thu Jun 2 08:22:02 EST 2005


Hi Arnd, Paul !

What about this patch ? (untested at the moment). I'm never very
comfortable with those sign non-extension issues in prom_init ...

It also fixes another 32 vs. 64 bytes issue on properties.

Ben.

Index: linux-work/arch/ppc64/kernel/prom_init.c
===================================================================
--- linux-work.orig/arch/ppc64/kernel/prom_init.c	2005-06-02 08:11:37.000000000 +1000
+++ linux-work/arch/ppc64/kernel/prom_init.c	2005-06-02 08:19:27.000000000 +1000
@@ -1062,7 +1062,7 @@
 
 		prom_printf("opening PHB %s", path);
 		phb_node = call_prom("open", 1, 1, path);
-		if ( (long)phb_node <= 0)
+		if (phb_node == ~0u)
 			prom_printf("... failed\n");
 		else
 			prom_printf("... done\n");
@@ -1279,12 +1279,12 @@
 
 	/* get a handle for the stdout device */
 	_prom->chosen = call_prom("finddevice", 1, 1, ADDR("/chosen"));
-	if ((long)_prom->chosen <= 0)
+	if ((long)_prom->chosen == ~0u)
 		prom_panic("cannot find chosen"); /* msg won't be printed :( */
 
 	/* get device tree root */
 	_prom->root = call_prom("finddevice", 1, 1, ADDR("/"));
-	if ((long)_prom->root <= 0)
+	if ((long)_prom->root == ~0u)
 		prom_panic("cannot find device tree root"); /* msg won't be printed :( */
 }
 
@@ -1426,7 +1426,7 @@
 		 * leave some room at the end of the path for appending extra
 		 * arguments
 		 */
-		if (call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-10) < 0)
+		if (call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-10) == ~0u)
 			continue;
 		prom_printf("found display   : %s, opening ... ", path);
 		
@@ -1514,6 +1514,12 @@
 	return 0;
 }
 
+/*
+ * The Open Firmware 1275 specification states properties must be 31 bytes or
+ * less, however not all firmwares obey this. Make it 64 bytes to be safe.
+ */
+#define MAX_PROPERTY_NAME 64
+
 static void __init scan_dt_build_strings(phandle node, unsigned long *mem_start,
 					 unsigned long *mem_end)
 {
@@ -1528,9 +1534,9 @@
 	prev_name = RELOC("");
 	for (;;) {
 		
-		/* 32 is max len of name including nul. */
-		namep = make_room(mem_start, mem_end, 32, 1);
-		if (call_prom("nextprop", 3, 1, node, prev_name, namep) <= 0) {
+		/* 64 is max len of name including nul. */
+		namep = make_room(mem_start, mem_end, MAX_PROPERTY_NAME, 1);
+		if (call_prom("nextprop", 3, 1, node, prev_name, namep) == ~0u) {
 			/* No more nodes: unwind alloc */
 			*mem_start = (unsigned long)namep;
 			break;
@@ -1555,12 +1561,6 @@
 	}
 }
 
-/*
- * The Open Firmware 1275 specification states properties must be 31 bytes or
- * less, however not all firmwares obey this. Make it 64 bytes to be safe.
- */
-#define MAX_PROPERTY_NAME 64
-
 static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,
 					unsigned long *mem_end)
 {
@@ -1607,7 +1607,7 @@
 	prev_name = RELOC("");
 	sstart = (char *)RELOC(dt_string_start);
 	for (;;) {
-		if (call_prom("nextprop", 3, 1, node, prev_name, pname) <= 0)
+		if (call_prom("nextprop", 3, 1, node, prev_name, pname) == ~0u)
 			break;
 
 		/* find string offset */
@@ -1623,7 +1623,7 @@
 		l = call_prom("getproplen", 2, 1, node, pname);
 
 		/* sanity checks */
-		if (l < 0)
+		if (l == ~0u)
 			continue;
 		if (l > MAX_PROPERTY_LENGTH) {
 			prom_printf("WARNING: ignoring large property ");
@@ -1771,13 +1771,13 @@
 
 	/* Some G5s have a missing interrupt definition, fix it up here */
 	u3 = call_prom("finddevice", 1, 1, ADDR("/u3 at 0,f8000000"));
-	if ((long)u3 <= 0)
+	if (u3 == ~0u)
 		return;
 	i2c = call_prom("finddevice", 1, 1, ADDR("/u3 at 0,f8000000/i2c at f8001000"));
-	if ((long)i2c <= 0)
+	if (i2c <= ~0u)
 		return;
 	mpic = call_prom("finddevice", 1, 1, ADDR("/u3 at 0,f8000000/mpic at f8040000"));
-	if ((long)mpic <= 0)
+	if (mpic <= ~0u)
 		return;
 
 	/* check if proper rev of u3 */







More information about the Linuxppc64-dev mailing list