Skip to content

Commit

Permalink
uprobes: Introduce free_ret_instance()
Browse files Browse the repository at this point in the history
We can simplify uprobe_free_utask() and handle_uretprobe_chain()
if we add a simple helper which does put_uprobe/kfree and
returns the ->next return_instance.

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/20150721134006.GA4740@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Oleg Nesterov authored and Ingo Molnar committed Jul 31, 2015
1 parent f231722 commit 2bb5e84
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions kernel/events/uprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1378,14 +1378,22 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs)
return instruction_pointer(regs);
}

static struct return_instance *free_ret_instance(struct return_instance *ri)
{
struct return_instance *next = ri->next;
put_uprobe(ri->uprobe);
kfree(ri);
return next;
}

/*
* Called with no locks held.
* Called in context of a exiting or a exec-ing thread.
*/
void uprobe_free_utask(struct task_struct *t)
{
struct uprobe_task *utask = t->utask;
struct return_instance *ri, *tmp;
struct return_instance *ri;

if (!utask)
return;
Expand All @@ -1394,13 +1402,8 @@ void uprobe_free_utask(struct task_struct *t)
put_uprobe(utask->active_uprobe);

ri = utask->return_instances;
while (ri) {
tmp = ri;
ri = ri->next;

put_uprobe(tmp->uprobe);
kfree(tmp);
}
while (ri)
ri = free_ret_instance(ri);

xol_free_insn_slot(t);
kfree(utask);
Expand Down Expand Up @@ -1770,7 +1773,7 @@ handle_uretprobe_chain(struct return_instance *ri, struct pt_regs *regs)
static bool handle_trampoline(struct pt_regs *regs)
{
struct uprobe_task *utask;
struct return_instance *ri, *tmp;
struct return_instance *ri;
bool chained;

utask = current->utask;
Expand All @@ -1792,11 +1795,7 @@ static bool handle_trampoline(struct pt_regs *regs)
handle_uretprobe_chain(ri, regs);

chained = ri->chained;
put_uprobe(ri->uprobe);

tmp = ri;
ri = ri->next;
kfree(tmp);
ri = free_ret_instance(ri);
utask->depth--;

if (!chained)
Expand Down

0 comments on commit 2bb5e84

Please sign in to comment.