Skip to content

Commit 9a0e3b9

Browse files
Liao Changctmarinas
authored andcommitted
arm64: Return early when break handler is found on linked-list
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>
1 parent f819281 commit 9a0e3b9

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

arch/arm64/kernel/debug-monitors.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
303303
{
304304
struct break_hook *hook;
305305
struct list_head *list;
306-
int (*fn)(struct pt_regs *regs, unsigned long esr) = NULL;
307306

308307
list = user_mode(regs) ? &user_break_hook : &kernel_break_hook;
309308

@@ -313,10 +312,10 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
313312
*/
314313
list_for_each_entry_rcu(hook, list, node) {
315314
if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm)
316-
fn = hook->fn;
315+
return hook->fn(regs, esr);
317316
}
318317

319-
return fn ? fn(regs, esr) : DBG_HOOK_ERROR;
318+
return DBG_HOOK_ERROR;
320319
}
321320
NOKPROBE_SYMBOL(call_break_hook);
322321

0 commit comments

Comments
 (0)