Skip to contentSkip to conversation

sparc: fix warning on prom_getproperty in openprom.c

PATCH Applied Martin Habets 2 participants 4 messages May 7, 2006 – May 12, 2006 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc: fix warning on prom_getproperty in openprom.c

This patch resolves the following build warnings seen in 2.6.17-rc3:
drivers/sbus/char/openprom.c:395: warning: ignoring return value of `prom_getproperty', declared with attribute warn_unused_result

Please apply.
Martin

---

drivers/sbus/char/openprom.c renamed from drivers/sbus/char/openprom.c.orig +4 -3
@@ -392,12 +392,13 @@
 			return -ENOMEM;
 		}
 
-		prom_getproperty(op.op_nodeid, str, tmp, len);
+		error = prom_getproperty(op.op_nodeid, str, tmp, len);
 
 		tmp[len] = '\0';
 
-		if (__copy_to_user(argp, &op, sizeof(op)) != 0
-		    || copy_to_user(op.op_buf, tmp, len) != 0)
+		if ((error <= 0) ||
+		    __copy_to_user(argp, &op, sizeof(op)) != 0 ||
+		    copy_to_user(op.op_buf, tmp, len) != 0)
 			error = -EFAULT;
 
 		kfree(tmp);
maintainer
#1 lore raw

From: Martin Habets <[email protected]>
Date: Sun, 7 May 2006 16:24:50 +0100

Quoted 7 lines

This patch resolves the following build warnings seen in 2.6.17-rc3:
drivers/sbus/char/openprom.c:395: warning: ignoring return value of `prom_getproperty', declared with attribute warn_unused_result

Please apply.
Martin

The intention is correct but if we get an error from prom_getproperty() then -EFAULT is not likely the appropiate thing to return. Perhaps -EINVAL or something like that.

#2 lore raw
In reply to Martin Habets
Quoted 6 lines · David S. Miller

From: Martin Habets <[email protected]>
Date: Sun, 7 May 2006 16:24:50 +0100

Quoted 3 lines

This patch resolves the following build warnings seen in 2.6.17-rc3:
drivers/sbus/char/openprom.c:395: warning: ignoring return value of `prom_getproperty', declared with attribute warn_unused_result

Quoted 8 lines
Quoted 4 lines

Please apply.
Martin

The intention is correct but if we get an error from prom_getproperty() then -EFAULT is not likely the appropiate thing to return. Perhaps -EINVAL or something like that.

Seems like a hypothetical case to me, since the code just did a prom_getproplen() a few lines before. It makes the patch a bit bigger.

Signature · 29 lines
Martin

	Signed-off-by: Martin Habets <[email protected]>

--- 2.6.17-rc3/drivers/sbus/char/openprom.c.orig	2006-05-06 18:48:44.000000000 +0100
+++ 2.6.17-rc3/drivers/sbus/char/openprom.c	2006-05-09 21:52:14.000000000 +0100
@@ -392,13 +392,16 @@
 			return -ENOMEM;
 		}
 
-		prom_getproperty(op.op_nodeid, str, tmp, len);
-
-		tmp[len] = '\0';
+		cnt = prom_getproperty(op.op_nodeid, str, tmp, len);
+		if (cnt <= 0) {
+			error = -EINVAL;
+		} else {
+			tmp[len] = '\0';
 
-		if (__copy_to_user(argp, &op, sizeof(op)) != 0
-		    || copy_to_user(op.op_buf, tmp, len) != 0)
-			error = -EFAULT;
+			if (__copy_to_user(argp, &op, sizeof(op)) != 0 ||
+			    copy_to_user(op.op_buf, tmp, len) != 0)
+				error = -EFAULT;
+		}
 
 		kfree(tmp);
 		kfree(str);