Commit 2bb5e840 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Ingo Molnar

uprobes: Introduce free_ret_instance()

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: default avatarPratyush Anand <panand@redhat.com>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarSrikar Dronamraju <srikar@linux.vnet.ibm.com>
Acked-by: default avatarAnton 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.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent f231722a
...@@ -1378,6 +1378,14 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs) ...@@ -1378,6 +1378,14 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs)
return instruction_pointer(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 with no locks held.
* Called in context of a exiting or a exec-ing thread. * Called in context of a exiting or a exec-ing thread.
...@@ -1385,7 +1393,7 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs) ...@@ -1385,7 +1393,7 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs)
void uprobe_free_utask(struct task_struct *t) void uprobe_free_utask(struct task_struct *t)
{ {
struct uprobe_task *utask = t->utask; struct uprobe_task *utask = t->utask;
struct return_instance *ri, *tmp; struct return_instance *ri;
if (!utask) if (!utask)
return; return;
...@@ -1394,13 +1402,8 @@ void uprobe_free_utask(struct task_struct *t) ...@@ -1394,13 +1402,8 @@ void uprobe_free_utask(struct task_struct *t)
put_uprobe(utask->active_uprobe); put_uprobe(utask->active_uprobe);
ri = utask->return_instances; ri = utask->return_instances;
while (ri) { while (ri)
tmp = ri; ri = free_ret_instance(ri);
ri = ri->next;
put_uprobe(tmp->uprobe);
kfree(tmp);
}
xol_free_insn_slot(t); xol_free_insn_slot(t);
kfree(utask); kfree(utask);
...@@ -1770,7 +1773,7 @@ handle_uretprobe_chain(struct return_instance *ri, struct pt_regs *regs) ...@@ -1770,7 +1773,7 @@ handle_uretprobe_chain(struct return_instance *ri, struct pt_regs *regs)
static bool handle_trampoline(struct pt_regs *regs) static bool handle_trampoline(struct pt_regs *regs)
{ {
struct uprobe_task *utask; struct uprobe_task *utask;
struct return_instance *ri, *tmp; struct return_instance *ri;
bool chained; bool chained;
utask = current->utask; utask = current->utask;
...@@ -1792,11 +1795,7 @@ static bool handle_trampoline(struct pt_regs *regs) ...@@ -1792,11 +1795,7 @@ static bool handle_trampoline(struct pt_regs *regs)
handle_uretprobe_chain(ri, regs); handle_uretprobe_chain(ri, regs);
chained = ri->chained; chained = ri->chained;
put_uprobe(ri->uprobe); ri = free_ret_instance(ri);
tmp = ri;
ri = ri->next;
kfree(tmp);
utask->depth--; utask->depth--;
if (!chained) if (!chained)
......
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