]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
arm64: Return early when break handler is found on linked-list
authorLiao Chang <liaochang1@huawei.com>
Thu, 24 Oct 2024 03:41:20 +0000 (03:41 +0000)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 1 Nov 2024 15:31:02 +0000 (15:31 +0000)
The search for breakpoint handlers iterate through the entire
linked list. Given that all registered hook has a valid fn field, and no
registered hooks share the same mask and imm. This commit optimize the
efficiency slightly by returning early as a matching handler is found.

Signed-off-by: Liao Chang <liaochang1@huawei.com>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20241024034120.3814224-1-liaochang1@huawei.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/kernel/debug-monitors.c

index 024a7b245056a8e159ec5df14047daca10cf06c3..4713a4c65b1b06d4c569462d81b12073f676e2cc 100644 (file)
@@ -303,7 +303,6 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
 {
        struct break_hook *hook;
        struct list_head *list;
-       int (*fn)(struct pt_regs *regs, unsigned long esr) = NULL;
 
        list = user_mode(regs) ? &user_break_hook : &kernel_break_hook;
 
@@ -313,10 +312,10 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
         */
        list_for_each_entry_rcu(hook, list, node) {
                if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm)
-                       fn = hook->fn;
+                       return hook->fn(regs, esr);
        }
 
-       return fn ? fn(regs, esr) : DBG_HOOK_ERROR;
+       return DBG_HOOK_ERROR;
 }
 NOKPROBE_SYMBOL(call_break_hook);