Skip to contentSkip to conversation

binder: simplify the return expression of binder_mmap

PATCH In review Liu Shixin 4 participants 9 messages Sep 21, 2020 – Oct 2, 2020 Android drivers

lore
Share & tools
lore

Liu Shixin

author
#0 lore raw

PATCH 1/1 binder: simplify the return expression of binder_mmap

Simplify the return expression.

---
 drivers/android/binder.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/android/binder.c +1 -4
index 37a505c41dec..1f929e0cf39f 100644
@@ -5204,10 +5204,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 	vma->vm_ops = &binder_vm_ops;
 	vma->vm_private_data = proc;
 
-	ret = binder_alloc_mmap_handler(&proc->alloc, vma);
-	if (ret)
-		return ret;
-	return 0;
+	return binder_alloc_mmap_handler(&proc->alloc, vma);
 
 err_bad_arg:
 	pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · Liu Shixin

Simplify the return expression.

---

Why not is all I can really say. :) But if this is about simplifying you could get rid of the "ret" and "failure string" variables, and the goto in that function completely by doing sm like this (__completely untested__):

drivers/android/binder.c +4 -14
index f936530a19b0..26f4dc81b008 100644
@@ -5182,9 +5182,7 @@ static const struct vm_operations_struct binder_vm_ops = {
 
 static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-       int ret;
        struct binder_proc *proc = filp->private_data;
-       const char *failure_string;
 
        if (proc->tsk != current->group_leader)
                return -EINVAL;
@@ -5196,9 +5194,9 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
                     (unsigned long)pgprot_val(vma->vm_page_prot));
 
        if (vma->vm_flags & FORBIDDEN_MMAP_FLAGS) {
-               ret = -EPERM;
-               failure_string = "bad vm_flags";
-               goto err_bad_arg;
+               pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
+                               proc->pid, vma->vm_start, vma->vm_end, "bad vm_flags", -EPERM);
+               return -EPERM;
        }
        vma->vm_flags |= VM_DONTCOPY | VM_MIXEDMAP;
        vma->vm_flags &= ~VM_MAYWRITE;
@@ -5206,15 +5204,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
        vma->vm_ops = &binder_vm_ops;
        vma->vm_private_data = proc;
 
-       ret = binder_alloc_mmap_handler(&proc->alloc, vma);
-       if (ret)
-               return ret;
-       return 0;
-
-err_bad_arg:
-       pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
-              proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
-       return ret;
+       return binder_alloc_mmap_handler(&proc->alloc, vma);
 }
 

Christian

author
#2 lore raw
Quoted 9 lines · Christian Brauner
Quoted 4 lines · Liu Shixin

Simplify the return expression.

---

Why not is all I can really say. :) But if this is about simplifying you could get rid of the "ret" and "failure string" variables, and the goto in that function completely by doing sm like this (__completely untested__):

Thanks for your advice. I will modify and test it.

Regards,
Liu Shixin

Quoted 47 lines
drivers/android/binder.c +4 -14
index f936530a19b0..26f4dc81b008 100644
@@ -5182,9 +5182,7 @@ static const struct vm_operations_struct binder_vm_ops = {
 
 static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-       int ret;
        struct binder_proc *proc = filp->private_data;
-       const char *failure_string;
 
        if (proc->tsk != current->group_leader)
                return -EINVAL;
@@ -5196,9 +5194,9 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
                     (unsigned long)pgprot_val(vma->vm_page_prot));
 
        if (vma->vm_flags & FORBIDDEN_MMAP_FLAGS) {
-               ret = -EPERM;
-               failure_string = "bad vm_flags";
-               goto err_bad_arg;
+               pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
+                               proc->pid, vma->vm_start, vma->vm_end, "bad vm_flags", -EPERM);
+               return -EPERM;
        }
        vma->vm_flags |= VM_DONTCOPY | VM_MIXEDMAP;
        vma->vm_flags &= ~VM_MAYWRITE;
@@ -5206,15 +5204,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
        vma->vm_ops = &binder_vm_ops;
        vma->vm_private_data = proc;
 
-       ret = binder_alloc_mmap_handler(&proc->alloc, vma);
-       if (ret)
-               return ret;
-       return 0;
-
-err_bad_arg:
-       pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
-              proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
-       return ret;
+       return binder_alloc_mmap_handler(&proc->alloc, vma);
 }
 

Christian
.

author
#3 lore raw

PATCH 1/1 binder: simplify the return expression of binder_mmap

In reply to Christian Brauner

Simplify the return expression.

---
 drivers/android/binder.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/android/binder.c +4 -14
index 37a505c41dec..49c0700816a5 100644
@@ -5180,9 +5180,7 @@ static const struct vm_operations_struct binder_vm_ops = {
 
 static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-	int ret;
 	struct binder_proc *proc = filp->private_data;
-	const char *failure_string;
 
 	if (proc->tsk != current->group_leader)
 		return -EINVAL;
@@ -5194,9 +5192,9 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 		     (unsigned long)pgprot_val(vma->vm_page_prot));
 
 	if (vma->vm_flags & FORBIDDEN_MMAP_FLAGS) {
-		ret = -EPERM;
-		failure_string = "bad vm_flags";
-		goto err_bad_arg;
+		pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
+		       proc->pid, vma->vm_start, vma->vm_end, "bad vm_flags", -EPERM);
+		return -EPERM;
 	}
 	vma->vm_flags |= VM_DONTCOPY | VM_MIXEDMAP;
 	vma->vm_flags &= ~VM_MAYWRITE;
@@ -5204,15 +5202,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 	vma->vm_ops = &binder_vm_ops;
 	vma->vm_private_data = proc;
 
-	ret = binder_alloc_mmap_handler(&proc->alloc, vma);
-	if (ret)
-		return ret;
-	return 0;
-
-err_bad_arg:
-	pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
-	       proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
-	return ret;
+	return binder_alloc_mmap_handler(&proc->alloc, vma);
 }
 
 static int binder_open(struct inode *nodp, struct file *filp)
Signature · 1 line
2.25.1
#4 lore raw
Quoted 6 lines · Liu Shixin

Simplify the return expression.

---
 drivers/android/binder.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

Is this a v2 patch?

If so, please properly label it and say what changed from the v1 version below the --- line.

Please fix up and resend a v3.

thanks,

greg k-h

author
#5 lore raw

PATCH v3 1/1 binder: simplify the return expression of binder_mmap

Simplify the return expression.

---
v3: Add the change description.
v2: Get rid of the "ret" and "failure string" variables.
v1: Simplify the return expression.

---
 drivers/android/binder.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/android/binder.c +4 -14
index 37a505c41dec..49c0700816a5 100644
@@ -5180,9 +5180,7 @@ static const struct vm_operations_struct binder_vm_ops = {
 
 static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-	int ret;
 	struct binder_proc *proc = filp->private_data;
-	const char *failure_string;
 
 	if (proc->tsk != current->group_leader)
 		return -EINVAL;
@@ -5194,9 +5192,9 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 		     (unsigned long)pgprot_val(vma->vm_page_prot));
 
 	if (vma->vm_flags & FORBIDDEN_MMAP_FLAGS) {
-		ret = -EPERM;
-		failure_string = "bad vm_flags";
-		goto err_bad_arg;
+		pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
+		       proc->pid, vma->vm_start, vma->vm_end, "bad vm_flags", -EPERM);
+		return -EPERM;
 	}
 	vma->vm_flags |= VM_DONTCOPY | VM_MIXEDMAP;
 	vma->vm_flags &= ~VM_MAYWRITE;
@@ -5204,15 +5202,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 	vma->vm_ops = &binder_vm_ops;
 	vma->vm_private_data = proc;
 
-	ret = binder_alloc_mmap_handler(&proc->alloc, vma);
-	if (ret)
-		return ret;
-	return 0;
-
-err_bad_arg:
-	pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
-	       proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
-	return ret;
+	return binder_alloc_mmap_handler(&proc->alloc, vma);
 }
 
 static int binder_open(struct inode *nodp, struct file *filp)
Signature · 1 line
2.25.1
#6 lore raw
Quoted 57 lines · Liu Shixin

Simplify the return expression.

---
v3: Add the change description.
v2: Get rid of the "ret" and "failure string" variables.
v1: Simplify the return expression.

---
 drivers/android/binder.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/android/binder.c +4 -14
index 37a505c41dec..49c0700816a5 100644
@@ -5180,9 +5180,7 @@ static const struct vm_operations_struct binder_vm_ops = {
 
 static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-	int ret;
 	struct binder_proc *proc = filp->private_data;
-	const char *failure_string;
 
 	if (proc->tsk != current->group_leader)
 		return -EINVAL;
@@ -5194,9 +5192,9 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 		     (unsigned long)pgprot_val(vma->vm_page_prot));
 
 	if (vma->vm_flags & FORBIDDEN_MMAP_FLAGS) {
-		ret = -EPERM;
-		failure_string = "bad vm_flags";
-		goto err_bad_arg;
+		pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
+		       proc->pid, vma->vm_start, vma->vm_end, "bad vm_flags", -EPERM);
+		return -EPERM;
 	}
 	vma->vm_flags |= VM_DONTCOPY | VM_MIXEDMAP;
 	vma->vm_flags &= ~VM_MAYWRITE;
@@ -5204,15 +5202,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 	vma->vm_ops = &binder_vm_ops;
 	vma->vm_private_data = proc;
 
-	ret = binder_alloc_mmap_handler(&proc->alloc, vma);
-	if (ret)
-		return ret;
-	return 0;
-
-err_bad_arg:
-	pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
-	       proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
-	return ret;
+	return binder_alloc_mmap_handler(&proc->alloc, vma);
 }
 
 static int binder_open(struct inode *nodp, struct file *filp)
Signature · 1 line
2.25.1

Todd and other Binder maintainers, what do you think of this?

thanks,

greg k-h

Acked-by on v3 1/1
#7 lore raw
In reply to Liu Shixin

Thanks!

Quoted 4 lines · Liu Shixin

Simplify the return expression.

Quoted 55 lines

---
v3: Add the change description.
v2: Get rid of the "ret" and "failure string" variables.
v1: Simplify the return expression.

---
 drivers/android/binder.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/android/binder.c +4 -15
index 37a505c41dec..49c0700816a5 100644
@@ -5180,9 +5180,7 @@ static const struct vm_operations_struct binder_vm_ops = {
 
 static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
 {
-       int ret;
        struct binder_proc *proc = filp->private_data;
-       const char *failure_string;
 
        if (proc->tsk != current->group_leader)
                return -EINVAL;
@@ -5194,9 +5192,9 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
                     (unsigned long)pgprot_val(vma->vm_page_prot));
 
        if (vma->vm_flags & FORBIDDEN_MMAP_FLAGS) {
-               ret = -EPERM;
-               failure_string = "bad vm_flags";
-               goto err_bad_arg;
+               pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
+                      proc->pid, vma->vm_start, vma->vm_end, "bad vm_flags", -EPERM);
+               return -EPERM;
        }
        vma->vm_flags |= VM_DONTCOPY | VM_MIXEDMAP;
        vma->vm_flags &= ~VM_MAYWRITE;
@@ -5204,15 +5202,7 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
        vma->vm_ops = &binder_vm_ops;
        vma->vm_private_data = proc;
 
-       ret = binder_alloc_mmap_handler(&proc->alloc, vma);
-       if (ret)
-               return ret;
-       return 0;
-
-err_bad_arg:
-       pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
-              proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
-       return ret;
+       return binder_alloc_mmap_handler(&proc->alloc, vma);
 }
 
 static int binder_open(struct inode *nodp, struct file *filp)
--

2.25.1