Skip to contentSkip to conversation

staging: android: Fix warning cast removes address space of expression

PATCH In review Camille Bordignon 3 participants 3 messages Apr 20, 2014 – Apr 25, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: android: Fix warning cast removes address space of expression

Fix sparse warning "cast removes address space of expression" Add lost flag "__user" due to cast

---

drivers/staging/android/binder.c +8 -3
index cfe4bc8..952c4ae 100644
@@ -2683,16 +2683,21 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		binder_free_thread(proc, thread);
 		thread = NULL;
 		break;
-	case BINDER_VERSION:
-		if (size != sizeof(struct binder_version)) {
+	case BINDER_VERSION: {
+		struct binder_version __user *bv = ubuf;
+
+		if (size != sizeof(*bv)) {
 			ret = -EINVAL;
 			goto err;
 		}
-		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, &((struct binder_version *)ubuf)->protocol_version)) {
+
+		if (put_user(BINDER_CURRENT_PROTOCOL_VERSION,
+				&bv->protocol_version)) {
 			ret = -EINVAL;
 			goto err;
 		}
 		break;
+	}
 	default:
 		ret = -EINVAL;
 		goto err;
#1 lore raw
Quoted 4 lines · Camille Bordignon

Fix sparse warning "cast removes address space of expression" Add lost flag "__user" due to cast

This one is the most perfect version of this patch yet. Unfortunately a couple other people sent it before you.

regards,
dan carpenter

#2 lore raw
In reply to Camille Bordignon
Quoted 26 lines · Camille Bordignon

Fix sparse warning "cast removes address space of expression" Add lost flag "__user" due to cast

---

drivers/staging/android/binder.c +5 -3
index cfe4bc8..952c4ae 100644
@@ -2683,16 +2683,21 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		binder_free_thread(proc, thread);
 		thread = NULL;
 		break;
-	case BINDER_VERSION:
-		if (size != sizeof(struct binder_version)) {
+	case BINDER_VERSION: {
+		struct binder_version __user *bv = ubuf;
+
+		if (size != sizeof(*bv)) {
 			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 2703

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

This does not apply to my tree :(