kprobes: Cleanup collect_one_slot() and __disable_kprobe()

If kip->nused is not zero, collect_one_slot() return false, otherwise do
a lot of linked list operations, reverse the processing order to make the
code if nesting more concise. __disable_kprobe() is the same as well.

Link: https://lore.kernel.org/all/20240813115334.3922580-4-ruanjinjie@huawei.com/

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
This commit is contained in:
Jinjie Ruan 2024-08-13 19:53:34 +08:00 committed by Masami Hiramatsu (Google)
parent ce7f27dcd7
commit da93dd931b

View File

@ -206,7 +206,9 @@ static bool collect_one_slot(struct kprobe_insn_page *kip, int idx)
{
kip->slot_used[idx] = SLOT_CLEAN;
kip->nused--;
if (kip->nused == 0) {
if (kip->nused != 0)
return false;
/*
* Page is no longer in use. Free it unless
* it's the last one. We keep the last one
@ -228,8 +230,6 @@ static bool collect_one_slot(struct kprobe_insn_page *kip, int idx)
}
return true;
}
return false;
}
static int collect_garbage_slots(struct kprobe_insn_cache *c)
{
@ -1725,7 +1725,9 @@ static struct kprobe *__disable_kprobe(struct kprobe *p)
if (unlikely(orig_p == NULL))
return ERR_PTR(-EINVAL);
if (!kprobe_disabled(p)) {
if (kprobe_disabled(p))
return orig_p;
/* Disable probe if it is a child probe */
if (p != orig_p)
p->flags |= KPROBE_FLAG_DISABLED;
@ -1747,7 +1749,6 @@ static struct kprobe *__disable_kprobe(struct kprobe *p)
}
orig_p->flags |= KPROBE_FLAG_DISABLED;
}
}
return orig_p;
}