Skip to content

Commit 605bfae

Browse files
fweisbecIngo Molnar
authored andcommitted
hw-breakpoints: Simplify error handling in breakpoint creation requests
This simplifies the error handling when we create a breakpoint. We don't need to check the NULL return value corner case anymore since we have improved perf_event_create_kernel_counter() to always return an error code in the failure case. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Prasad <prasad@linux.vnet.ibm.com> LKML-Reference: <1259210142-5714-3-git-send-regression-fweisbec@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent c6567f6 commit 605bfae

4 files changed

Lines changed: 7 additions & 24 deletions

File tree

‎arch/x86/kernel/ptrace.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,7 @@ static int ptrace_write_dr7(struct task_struct *tsk, unsigned long data)
657657
tsk, true);
658658
thread->ptrace_bps[i] = NULL;
659659

660-
if (!bp) { /* incorrect bp, or we have a bug in bp API */
661-
rc = -EINVAL;
662-
break;
663-
}
660+
/* Incorrect bp, or we have a bug in bp API */
664661
if (IS_ERR(bp)) {
665662
rc = PTR_ERR(bp);
666663
bp = NULL;
@@ -729,9 +726,6 @@ static int ptrace_set_breakpoint_addr(struct task_struct *tsk, int nr,
729726
tsk,
730727
bp->attr.disabled);
731728
}
732-
733-
if (!bp)
734-
return -EIO;
735729
/*
736730
* CHECKME: the previous code returned -EIO if the addr wasn't a
737731
* valid task virtual addr. The new one will return -EINVAL in this

‎kernel/hw_breakpoint.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ register_wide_hw_breakpoint(unsigned long addr,
442442

443443
*pevent = bp;
444444

445-
if (IS_ERR(bp) || !bp) {
445+
if (IS_ERR(bp)) {
446446
err = PTR_ERR(bp);
447447
goto fail;
448448
}
@@ -453,7 +453,7 @@ register_wide_hw_breakpoint(unsigned long addr,
453453
fail:
454454
for_each_possible_cpu(cpu) {
455455
pevent = per_cpu_ptr(cpu_events, cpu);
456-
if (IS_ERR(*pevent) || !*pevent)
456+
if (IS_ERR(*pevent))
457457
break;
458458
unregister_hw_breakpoint(*pevent);
459459
}

‎kernel/trace/trace_ksym.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,9 @@ int process_new_ksym_entry(char *ksymname, int op, unsigned long addr)
200200
entry->ksym_hbp = register_wide_hw_breakpoint(entry->ksym_addr,
201201
entry->len, entry->type,
202202
ksym_hbp_handler, true);
203+
203204
if (IS_ERR(entry->ksym_hbp)) {
204-
entry->ksym_hbp = NULL;
205205
ret = PTR_ERR(entry->ksym_hbp);
206-
}
207-
208-
if (!entry->ksym_hbp) {
209206
printk(KERN_INFO "ksym_tracer request failed. Try again"
210207
" later!!\n");
211208
goto err;
@@ -332,21 +329,16 @@ static ssize_t ksym_trace_filter_write(struct file *file,
332329
if (changed) {
333330
unregister_wide_hw_breakpoint(entry->ksym_hbp);
334331
entry->type = op;
332+
ret = 0;
335333
if (op > 0) {
336334
entry->ksym_hbp =
337335
register_wide_hw_breakpoint(entry->ksym_addr,
338336
entry->len, entry->type,
339337
ksym_hbp_handler, true);
340338
if (IS_ERR(entry->ksym_hbp))
341-
entry->ksym_hbp = NULL;
342-
343-
/* modified without problem */
344-
if (entry->ksym_hbp) {
345-
ret = 0;
339+
ret = PTR_ERR(entry->ksym_hbp);
340+
else
346341
goto out;
347-
}
348-
} else {
349-
ret = 0;
350342
}
351343
/* Error or "symbol:---" case: drop it */
352344
ksym_filter_entry_count--;

‎samples/hw_breakpoint/data_breakpoint.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ static int __init hw_break_module_init(void)
6161
if (IS_ERR(sample_hbp)) {
6262
ret = PTR_ERR(sample_hbp);
6363
goto fail;
64-
} else if (!sample_hbp) {
65-
ret = -EINVAL;
66-
goto fail;
6764
}
6865

6966
printk(KERN_INFO "HW Breakpoint for %s write installed\n", ksym_name);

0 commit comments

Comments
 (0)