Skip to contentSkip to conversation

staging: binder: add __user annotation in binder.c

PATCH New Mathieu Maret 2 participants 4 messages Mar 25, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 staging: binder: add __user annotation in binder.c

Add __user to binder_version and correct sparse warning. Reduce line size to fit to coding style.

---
 drivers/staging/android/binder.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/staging/android/binder.c +5 -2
index cfe4bc8..6d8ee37 100644
@@ -2683,16 +2683,19 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		binder_free_thread(proc, thread);
 		thread = NULL;
 		break;
-	case BINDER_VERSION:
+	case BINDER_VERSION: {
+		struct binder_version __user *ver = ubuf;
 		if (size != sizeof(struct binder_version)) {
 			ret = -EINVAL;
 			goto err;
 		}
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version *)ubuf)->protocol_version)) {
+		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION,
+			&ver->protocol_version)) {
 			ret = -EINVAL;
 			goto err;
 		}
 		break;
+	}
 	default:
 		ret = -EINVAL;
 		goto err;
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 staging: binder: Code simplification

Remove duplicate code

---
 drivers/staging/android/binder.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/android/binder.c +3 -5
index 6d8ee37..67aaa38 100644
@@ -2685,11 +2685,9 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		break;
 	case BINDER_VERSION: {
 		struct binder_version __user *ver = ubuf;
-		if (size != sizeof(struct binder_version)) {
-			ret = -EINVAL;
-			goto err;
-		}
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION,
+
+		if (size != sizeof(struct binder_version) ||
+			put_user(BINDER_CURRENT_PROTOCOL_VERSION,
 			&ver->protocol_version)) {
 			ret = -EINVAL;
 			goto err;
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 2/2] staging: binder: Code simplification

Quoted 1 line · Mathieu Maret

Remove duplicate code

[]

drivers/staging/android/binder.c

Quoted 1 line
drivers/staging/android/binder.c +0 -0

[]

drivers/staging/android/binder.c static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 2691

Quoted 13 lines
drivers/staging/android/binder.c +3 -5
@@ -2685,11 +2685,9 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		break;
 	case BINDER_VERSION: {
 		struct binder_version __user *ver = ubuf;
-		if (size != sizeof(struct binder_version)) {
-			ret = -EINVAL;
-			goto err;
-		}
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION,
+
+		if (size != sizeof(struct binder_version) ||
+			put_user(BINDER_CURRENT_PROTOCOL_VERSION,
 			&ver->protocol_version)) {

When you do this, please align continuations at the appropriate open parenthesis using maximal initial tabs and minimal spaces for alignment.

		if (size != sizeof(struct binder_version) ||
		    put_user(BINDER_CURRENT_PROTOCOL_VERSION,
			     &ver->protocol_version)) {

2 tabs then 4 spaces then "put_user"
3 tabs then 5 spaces then "&ver->"

using scripts/checkpatch.pl --strict should alert you to this.

And, either don't submit this until after 3.15-rc1 is out and Greg KH starts taking patches again, or expect to be very patient about getting any update on this.

#3 lore raw

Re: [PATCH 2/2] staging: binder: Code simplification

Quoted 27 lines · Joe Perches
Quoted 1 line · Mathieu Maret

Remove duplicate code

[]

drivers/staging/android/binder.c

Quoted 1 line
drivers/staging/android/binder.c +0 -0

[]

drivers/staging/android/binder.c static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 2691

Quoted 13 lines
drivers/staging/android/binder.c +3 -5
@@ -2685,11 +2685,9 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		break;
 	case BINDER_VERSION: {
 		struct binder_version __user *ver = ubuf;
-		if (size != sizeof(struct binder_version)) {
-			ret = -EINVAL;
-			goto err;
-		}
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION,
+
+		if (size != sizeof(struct binder_version) ||
+			put_user(BINDER_CURRENT_PROTOCOL_VERSION,
 			&ver->protocol_version)) {

When you do this, please align continuations at the appropriate open parenthesis using maximal initial tabs and minimal spaces for alignment.

		if (size != sizeof(struct binder_version) ||
		    put_user(BINDER_CURRENT_PROTOCOL_VERSION,
			     &ver->protocol_version)) {
Quoted 9 lines

2 tabs then 4 spaces then "put_user"
3 tabs then 5 spaces then "&ver->"

using scripts/checkpatch.pl --strict should alert you to this.

And, either don't submit this until after 3.15-rc1 is out and Greg KH starts taking patches again, or expect to be very patient about getting any update on this.

Joe,

Thanks for your help and tips.
--strict is now on my todo list !

See you after 3.15-rc1