Skip to contentSkip to conversation

staging: binder: add __user annotation in binder.c

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

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

Fix the following spare warning
drivers/staging/android/binder.c:2691:21: warning: incorrect type in argument 1 (different address spaces)

---
 drivers/staging/android/binder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/android/binder.c +1 -1
index cfe4bc8..9418086 100644
@@ -2688,7 +2688,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 			ret = -EINVAL;
 			goto err;
 		}
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version *)ubuf)->protocol_version)) {
+		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version __user *)ubuf)->protocol_version)) {
 			ret = -EINVAL;
 			goto err;
 		}
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 staging: binder: reduce line size

---
 drivers/staging/android/binder.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/android/binder.c +2 -1
index 9418086..4e51034 100644
@@ -2688,7 +2688,8 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 			ret = -EINVAL;
 			goto err;
 		}
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version __user *)ubuf)->protocol_version)) {
+		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION,
+			&((struct binder_version __user *)ubuf)->protocol_version)) {
 			ret = -EINVAL;
 			goto err;
 		}
Signature · 1 line
1.9.1
#2 lore raw
In reply to Mathieu Maret
Quoted 1 line · Mathieu Maret

Fix the following spare warning

sparse

Quoted 1 line

drivers/staging/android/binder.c:2691:21: warning: incorrect type in argument 1 (different address spaces)

[]

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)

Quoted 1 line
drivers/staging/android/binder.c +0 -0
@@ -2688,7 +2688,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)

[]

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

Quoted 2 lines
drivers/staging/android/binder.c +1 -1
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version *)ubuf)->protocol_version)) {
+		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version __user *)ubuf)->protocol_version)) {

That's certainly one way to do it, but I'd suggest using a temporary instead

 drivers/staging/android/binder.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/staging/android/binder.c +6 -2
index cfe4bc8..1f5e249 100644
@@ -2683,16 +2683,20 @@ 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;
#3 lore raw
Quoted 39 lines · Joe Perches
Quoted 1 line · Mathieu Maret

Fix the following spare warning

sparse

Quoted 1 line

drivers/staging/android/binder.c:2691:21: warning: incorrect type in argument 1 (different address spaces)

[]

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)

Quoted 1 line
drivers/staging/android/binder.c +0 -0
@@ -2688,7 +2688,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)

[]

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

Quoted 2 lines
drivers/staging/android/binder.c +1 -1
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version *)ubuf)->protocol_version)) {
+		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version __user *)ubuf)->protocol_version)) {

That's certainly one way to do it, but I'd suggest using a temporary instead

 drivers/staging/android/binder.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/staging/android/binder.c +3 -2
index cfe4bc8..1f5e249 100644
@@ -2683,16 +2683,20 @@ 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)) {

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

Quoted 10 lines
drivers/staging/android/binder.c +3 -0
+		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION,
+			     &ver->protocol_version)) {
 			ret = -EINVAL;
 			goto err;
 		}
 		break;
+	}
 	default:
 		ret = -EINVAL;
 		goto err;

And you solve the issue with the line size btw.
Good move!