Commit c7e548b4 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Ingo Molnar

perf: Factor out strncpy() in perf_event_mmap_event()

While this is really minor, but strncpy() does the unnecessary
zero-padding till the end of tmp[16] and it is called every time
we are going to use the string literal.

Turn these strncpy()'s into the single strlcpy() under the new
label, saves 72 bytes.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20131017182417.GA17753@redhat.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent a94d342b
...@@ -5144,8 +5144,8 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) ...@@ -5144,8 +5144,8 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
buf = kmalloc(PATH_MAX, GFP_KERNEL); buf = kmalloc(PATH_MAX, GFP_KERNEL);
if (!buf) { if (!buf) {
name = strncpy(tmp, "//enomem", sizeof(tmp)); name = "//enomem";
goto got_name; goto cpy_name;
} }
/* /*
* d_path() works from the end of the rb backwards, so we * d_path() works from the end of the rb backwards, so we
...@@ -5154,8 +5154,8 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) ...@@ -5154,8 +5154,8 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
*/ */
name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64)); name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
if (IS_ERR(name)) { if (IS_ERR(name)) {
name = strncpy(tmp, "//toolong", sizeof(tmp)); name = "//toolong";
goto got_name; goto cpy_name;
} }
inode = file_inode(vma->vm_file); inode = file_inode(vma->vm_file);
dev = inode->i_sb->s_dev; dev = inode->i_sb->s_dev;
...@@ -5163,30 +5163,30 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) ...@@ -5163,30 +5163,30 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
gen = inode->i_generation; gen = inode->i_generation;
maj = MAJOR(dev); maj = MAJOR(dev);
min = MINOR(dev); min = MINOR(dev);
goto got_name;
} else { } else {
name = (char *)arch_vma_name(vma); name = (char *)arch_vma_name(vma);
if (name) { if (name)
name = strncpy(tmp, name, sizeof(tmp) - 1); goto cpy_name;
tmp[sizeof(tmp) - 1] = '\0';
goto got_name;
}
if (vma->vm_start <= vma->vm_mm->start_brk && if (vma->vm_start <= vma->vm_mm->start_brk &&
vma->vm_end >= vma->vm_mm->brk) { vma->vm_end >= vma->vm_mm->brk) {
name = strncpy(tmp, "[heap]", sizeof(tmp)); name = "[heap]";
goto got_name; goto cpy_name;
} }
if (vma->vm_start <= vma->vm_mm->start_stack && if (vma->vm_start <= vma->vm_mm->start_stack &&
vma->vm_end >= vma->vm_mm->start_stack) { vma->vm_end >= vma->vm_mm->start_stack) {
name = strncpy(tmp, "[stack]", sizeof(tmp)); name = "[stack]";
goto got_name; goto cpy_name;
} }
name = strncpy(tmp, "//anon", sizeof(tmp)); name = "//anon";
goto got_name; goto cpy_name;
} }
cpy_name:
strlcpy(tmp, name, sizeof(tmp));
name = tmp;
got_name: got_name:
/* /*
* Since our buffer works in 8 byte units we need to align our string * Since our buffer works in 8 byte units we need to align our string
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment