Skip to contentSkip to conversation

gru: cleanup gru_dump_context() a little

PATCH In review Dan Carpenter 2 participants 2 messages Jan 30, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 gru: cleanup gru_dump_context() a little

"ret" is zero here so we can remove the "!ret" part of the condition. "uhdr" is alread a __user pointer so we can remove the cast.

---
Btw, speaking of __user pointers there are some places where we dereference them in this file. It's not a security problem because we have already used copy_to_user() to successfully write to the pointer at point. But if you have something like PAX which puts user pointers and kernel pointers in a separate address space then this will cause problems.

Run sparse to see the issue.

drivers/misc/sgi-gru/grukdump.c +3 -3
index 2bef3f76032a..a3700a56b8ff 100644
@@ -178,10 +178,10 @@ static int gru_dump_context(struct gru_state *gru, int ctxnum,
 	hdr.cbrcnt = cbrcnt;
 	hdr.dsrcnt = dsrcnt;
 	hdr.cch_locked = cch_locked;
-	if (!ret && copy_to_user((void __user *)uhdr, &hdr, sizeof(hdr)))
-		ret = -EFAULT;
+	if (copy_to_user(uhdr, &hdr, sizeof(hdr)))
+		return -EFAULT;
 
-	return ret ? ret : bytes;
+	return bytes;
 }
 
 int gru_dump_chiplet_request(unsigned long arg)
Acked-by on v1 2/2
#1 lore raw
Quoted 32 lines · Dan Carpenter

"ret" is zero here so we can remove the "!ret" part of the condition. "uhdr" is alread a __user pointer so we can remove the cast.

---
Btw, speaking of __user pointers there are some places where we dereference them in this file. It's not a security problem because we have already used copy_to_user() to successfully write to the pointer at point. But if you have something like PAX which puts user pointers and kernel pointers in a separate address space then this will cause problems.

Run sparse to see the issue.

drivers/misc/sgi-gru/grukdump.c +3 -3
index 2bef3f76032a..a3700a56b8ff 100644
@@ -178,10 +178,10 @@ static int gru_dump_context(struct gru_state *gru, int ctxnum,
 	hdr.cbrcnt = cbrcnt;
 	hdr.dsrcnt = dsrcnt;
 	hdr.cch_locked = cch_locked;
-	if (!ret && copy_to_user((void __user *)uhdr, &hdr, sizeof(hdr)))
-		ret = -EFAULT;
+	if (copy_to_user(uhdr, &hdr, sizeof(hdr)))
+		return -EFAULT;
 
-	return ret ? ret : bytes;
+	return bytes;
 }
 
 int gru_dump_chiplet_request(unsigned long arg)