Commit edc924e023ae2022fc29f1246e115c610c9abf38
Committed by
Linus Torvalds
1 parent
198d1597cc
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
fs/proc/array.c: convert to use string_escape_str()
Instead of custom approach let's use string_escape_str() to escape a given string (task_name in this case). Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 7 additions and 27 deletions Side-by-side Diff
fs/proc/array.c
... | ... | @@ -81,6 +81,7 @@ |
81 | 81 | #include <linux/pid_namespace.h> |
82 | 82 | #include <linux/ptrace.h> |
83 | 83 | #include <linux/tracehook.h> |
84 | +#include <linux/string_helpers.h> | |
84 | 85 | #include <linux/user_namespace.h> |
85 | 86 | |
86 | 87 | #include <asm/pgtable.h> |
87 | 88 | |
88 | 89 | |
... | ... | @@ -89,39 +90,18 @@ |
89 | 90 | |
90 | 91 | static inline void task_name(struct seq_file *m, struct task_struct *p) |
91 | 92 | { |
92 | - int i; | |
93 | - char *buf, *end; | |
94 | - char *name; | |
93 | + char *buf; | |
95 | 94 | char tcomm[sizeof(p->comm)]; |
96 | 95 | |
97 | 96 | get_task_comm(tcomm, p); |
98 | 97 | |
99 | 98 | seq_puts(m, "Name:\t"); |
100 | - end = m->buf + m->size; | |
101 | 99 | buf = m->buf + m->count; |
102 | - name = tcomm; | |
103 | - i = sizeof(tcomm); | |
104 | - while (i && (buf < end)) { | |
105 | - unsigned char c = *name; | |
106 | - name++; | |
107 | - i--; | |
108 | - *buf = c; | |
109 | - if (!c) | |
110 | - break; | |
111 | - if (c == '\\') { | |
112 | - buf++; | |
113 | - if (buf < end) | |
114 | - *buf++ = c; | |
115 | - continue; | |
116 | - } | |
117 | - if (c == '\n') { | |
118 | - *buf++ = '\\'; | |
119 | - if (buf < end) | |
120 | - *buf++ = 'n'; | |
121 | - continue; | |
122 | - } | |
123 | - buf++; | |
124 | - } | |
100 | + | |
101 | + /* Ignore error for now */ | |
102 | + string_escape_str(tcomm, &buf, m->size - m->count, | |
103 | + ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\"); | |
104 | + | |
125 | 105 | m->count = buf - m->buf; |
126 | 106 | seq_putc(m, '\n'); |
127 | 107 | } |