uprobes: Introduce free_ret_instance()
authorOleg Nesterov <[email protected]>
Tue, 21 Jul 2015 13:40:06 +0000 (15:40 +0200)
committerIngo Molnar <[email protected]>
Fri, 31 Jul 2015 08:38:03 +0000 (10:38 +0200)
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 <[email protected]>
Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Srikar Dronamraju <[email protected]>
Acked-by: Anton Arapov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
kernel/events/uprobes.c

index a9847b4ec1e7cb961fae293e85ee2ee147802b80..d8c702fc836f01e6653a1e76d2a4c8391180bf82 100644 (file)
@@ -1378,6 +1378,14 @@ 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.
@@ -1385,7 +1393,7 @@ unsigned long uprobe_get_trap_addr(struct pt_regs *regs)
 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;
@@ -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);
@@ -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;
@@ -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)