diff options
author | Oleg Nesterov <oleg@redhat.com> | 2015-07-21 09:40:03 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-07-31 04:38:03 -0400 |
commit | f231722a2b27ee99cbcd0c6bcf4c866612b78137 (patch) | |
tree | 73dac72e5f6926559e263a9ecae93380548a5533 /kernel/events/uprobes.c | |
parent | 41d279aaf5b57a050a08fa88c70aad1890e018cd (diff) |
uprobes: Introduce get_uprobe()
Cosmetic. Add the new trivial helper, get_uprobe(). It matches
put_uprobe() we already have and we can simplify a couple of its
users.
Tested-by: Pratyush Anand <panand@redhat.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Acked-by: Anton Arapov <arapov@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20150721134003.GA4736@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/events/uprobes.c')
-rw-r--r-- | kernel/events/uprobes.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index cb346f26a22d..a9847b4ec1e7 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c | |||
@@ -366,6 +366,18 @@ set_orig_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long v | |||
366 | return uprobe_write_opcode(mm, vaddr, *(uprobe_opcode_t *)&auprobe->insn); | 366 | return uprobe_write_opcode(mm, vaddr, *(uprobe_opcode_t *)&auprobe->insn); |
367 | } | 367 | } |
368 | 368 | ||
369 | static struct uprobe *get_uprobe(struct uprobe *uprobe) | ||
370 | { | ||
371 | atomic_inc(&uprobe->ref); | ||
372 | return uprobe; | ||
373 | } | ||
374 | |||
375 | static void put_uprobe(struct uprobe *uprobe) | ||
376 | { | ||
377 | if (atomic_dec_and_test(&uprobe->ref)) | ||
378 | kfree(uprobe); | ||
379 | } | ||
380 | |||
369 | static int match_uprobe(struct uprobe *l, struct uprobe *r) | 381 | static int match_uprobe(struct uprobe *l, struct uprobe *r) |
370 | { | 382 | { |
371 | if (l->inode < r->inode) | 383 | if (l->inode < r->inode) |
@@ -393,10 +405,8 @@ static struct uprobe *__find_uprobe(struct inode *inode, loff_t offset) | |||
393 | while (n) { | 405 | while (n) { |
394 | uprobe = rb_entry(n, struct uprobe, rb_node); | 406 | uprobe = rb_entry(n, struct uprobe, rb_node); |
395 | match = match_uprobe(&u, uprobe); | 407 | match = match_uprobe(&u, uprobe); |
396 | if (!match) { | 408 | if (!match) |
397 | atomic_inc(&uprobe->ref); | 409 | return get_uprobe(uprobe); |
398 | return uprobe; | ||
399 | } | ||
400 | 410 | ||
401 | if (match < 0) | 411 | if (match < 0) |
402 | n = n->rb_left; | 412 | n = n->rb_left; |
@@ -432,10 +442,8 @@ static struct uprobe *__insert_uprobe(struct uprobe *uprobe) | |||
432 | parent = *p; | 442 | parent = *p; |
433 | u = rb_entry(parent, struct uprobe, rb_node); | 443 | u = rb_entry(parent, struct uprobe, rb_node); |
434 | match = match_uprobe(uprobe, u); | 444 | match = match_uprobe(uprobe, u); |
435 | if (!match) { | 445 | if (!match) |
436 | atomic_inc(&u->ref); | 446 | return get_uprobe(u); |
437 | return u; | ||
438 | } | ||
439 | 447 | ||
440 | if (match < 0) | 448 | if (match < 0) |
441 | p = &parent->rb_left; | 449 | p = &parent->rb_left; |
@@ -472,12 +480,6 @@ static struct uprobe *insert_uprobe(struct uprobe *uprobe) | |||
472 | return u; | 480 | return u; |
473 | } | 481 | } |
474 | 482 | ||
475 | static void put_uprobe(struct uprobe *uprobe) | ||
476 | { | ||
477 | if (atomic_dec_and_test(&uprobe->ref)) | ||
478 | kfree(uprobe); | ||
479 | } | ||
480 | |||
481 | static struct uprobe *alloc_uprobe(struct inode *inode, loff_t offset) | 483 | static struct uprobe *alloc_uprobe(struct inode *inode, loff_t offset) |
482 | { | 484 | { |
483 | struct uprobe *uprobe, *cur_uprobe; | 485 | struct uprobe *uprobe, *cur_uprobe; |
@@ -1039,14 +1041,14 @@ static void build_probe_list(struct inode *inode, | |||
1039 | if (u->inode != inode || u->offset < min) | 1041 | if (u->inode != inode || u->offset < min) |
1040 | break; | 1042 | break; |
1041 | list_add(&u->pending_list, head); | 1043 | list_add(&u->pending_list, head); |
1042 | atomic_inc(&u->ref); | 1044 | get_uprobe(u); |
1043 | } | 1045 | } |
1044 | for (t = n; (t = rb_next(t)); ) { | 1046 | for (t = n; (t = rb_next(t)); ) { |
1045 | u = rb_entry(t, struct uprobe, rb_node); | 1047 | u = rb_entry(t, struct uprobe, rb_node); |
1046 | if (u->inode != inode || u->offset > max) | 1048 | if (u->inode != inode || u->offset > max) |
1047 | break; | 1049 | break; |
1048 | list_add(&u->pending_list, head); | 1050 | list_add(&u->pending_list, head); |
1049 | atomic_inc(&u->ref); | 1051 | get_uprobe(u); |
1050 | } | 1052 | } |
1051 | } | 1053 | } |
1052 | spin_unlock(&uprobes_treelock); | 1054 | spin_unlock(&uprobes_treelock); |
@@ -1437,7 +1439,7 @@ static int dup_utask(struct task_struct *t, struct uprobe_task *o_utask) | |||
1437 | return -ENOMEM; | 1439 | return -ENOMEM; |
1438 | 1440 | ||
1439 | *n = *o; | 1441 | *n = *o; |
1440 | atomic_inc(&n->uprobe->ref); | 1442 | get_uprobe(n->uprobe); |
1441 | n->next = NULL; | 1443 | n->next = NULL; |
1442 | 1444 | ||
1443 | *p = n; | 1445 | *p = n; |
@@ -1565,8 +1567,7 @@ static void prepare_uretprobe(struct uprobe *uprobe, struct pt_regs *regs) | |||
1565 | orig_ret_vaddr = utask->return_instances->orig_ret_vaddr; | 1567 | orig_ret_vaddr = utask->return_instances->orig_ret_vaddr; |
1566 | } | 1568 | } |
1567 | 1569 | ||
1568 | atomic_inc(&uprobe->ref); | 1570 | ri->uprobe = get_uprobe(uprobe); |
1569 | ri->uprobe = uprobe; | ||
1570 | ri->func = instruction_pointer(regs); | 1571 | ri->func = instruction_pointer(regs); |
1571 | ri->orig_ret_vaddr = orig_ret_vaddr; | 1572 | ri->orig_ret_vaddr = orig_ret_vaddr; |
1572 | ri->chained = chained; | 1573 | ri->chained = chained; |