summaryrefslogtreecommitdiffstats
path: root/kdbus-no-need-to-ref-current-mm.patch
blob: 0f5cbed40dcd81092707985da85435376759d6da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From: David Herrmann <dh.herrmann@gmail.com>
Date: Mon, 20 Apr 2015 11:13:54 +0200
Subject: [PATCH] kdbus: no need to ref current->mm

If we access current->mm temporarily, there is no need to ref it. It can
only be changed by us, so no-one can race with us.

Avoid ref'ing and unref'ing it just to access some of its fields, similar
to what syscalls in mm/ do.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
---
 ipc/kdbus/metadata.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

diff --git a/ipc/kdbus/metadata.c b/ipc/kdbus/metadata.c
index a85eac34a5c4..c36b9cc67637 100644
--- a/ipc/kdbus/metadata.c
+++ b/ipc/kdbus/metadata.c
@@ -282,15 +282,10 @@ static void kdbus_meta_proc_collect_pid_comm(struct kdbus_meta_proc *mp)
 
 static void kdbus_meta_proc_collect_exe(struct kdbus_meta_proc *mp)
 {
-	struct mm_struct *mm;
 	struct file *exe_file;
 
-	mm = get_task_mm(current);
-	if (!mm)
-		return;
-
 	rcu_read_lock();
-	exe_file = rcu_dereference(mm->exe_file);
+	exe_file = rcu_dereference(current->mm->exe_file);
 	if (exe_file) {
 		mp->exe_path = exe_file->f_path;
 		path_get(&mp->exe_path);
@@ -298,28 +293,18 @@ static void kdbus_meta_proc_collect_exe(struct kdbus_meta_proc *mp)
 		mp->valid |= KDBUS_ATTACH_EXE;
 	}
 	rcu_read_unlock();
-
-	mmput(mm);
 }
 
 static int kdbus_meta_proc_collect_cmdline(struct kdbus_meta_proc *mp)
 {
-	struct mm_struct *mm;
+	struct mm_struct *mm = current->mm;
 	char *cmdline;
 
-	mm = get_task_mm(current);
-	if (!mm)
-		return 0;
-
-	if (!mm->arg_end) {
-		mmput(mm);
+	if (!mm->arg_end)
 		return 0;
-	}
 
 	cmdline = strndup_user((const char __user *)mm->arg_start,
 			       mm->arg_end - mm->arg_start);
-	mmput(mm);
-
 	if (IS_ERR(cmdline))
 		return PTR_ERR(cmdline);