Skip to content

Commit

Permalink
hw-breakpoints: Simplify error handling in breakpoint creation requests
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Prasad <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
fweisbec authored and Ingo Molnar committed Nov 26, 2009
1 parent c6567f6 commit 605bfae
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
8 changes: 1 addition & 7 deletions arch/x86/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,7 @@ static int ptrace_write_dr7(struct task_struct *tsk, unsigned long data)
tsk, true);
thread->ptrace_bps[i] = NULL;

if (!bp) { /* incorrect bp, or we have a bug in bp API */
rc = -EINVAL;
break;
}
/* Incorrect bp, or we have a bug in bp API */
if (IS_ERR(bp)) {
rc = PTR_ERR(bp);
bp = NULL;
Expand Down Expand Up @@ -729,9 +726,6 @@ static int ptrace_set_breakpoint_addr(struct task_struct *tsk, int nr,
tsk,
bp->attr.disabled);
}

if (!bp)
return -EIO;
/*
* CHECKME: the previous code returned -EIO if the addr wasn't a
* valid task virtual addr. The new one will return -EINVAL in this
Expand Down
4 changes: 2 additions & 2 deletions kernel/hw_breakpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ register_wide_hw_breakpoint(unsigned long addr,

*pevent = bp;

if (IS_ERR(bp) || !bp) {
if (IS_ERR(bp)) {
err = PTR_ERR(bp);
goto fail;
}
Expand All @@ -453,7 +453,7 @@ register_wide_hw_breakpoint(unsigned long addr,
fail:
for_each_possible_cpu(cpu) {
pevent = per_cpu_ptr(cpu_events, cpu);
if (IS_ERR(*pevent) || !*pevent)
if (IS_ERR(*pevent))
break;
unregister_hw_breakpoint(*pevent);
}
Expand Down
16 changes: 4 additions & 12 deletions kernel/trace/trace_ksym.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,9 @@ int process_new_ksym_entry(char *ksymname, int op, unsigned long addr)
entry->ksym_hbp = register_wide_hw_breakpoint(entry->ksym_addr,
entry->len, entry->type,
ksym_hbp_handler, true);

if (IS_ERR(entry->ksym_hbp)) {
entry->ksym_hbp = NULL;
ret = PTR_ERR(entry->ksym_hbp);
}

if (!entry->ksym_hbp) {
printk(KERN_INFO "ksym_tracer request failed. Try again"
" later!!\n");
goto err;
Expand Down Expand Up @@ -332,21 +329,16 @@ static ssize_t ksym_trace_filter_write(struct file *file,
if (changed) {
unregister_wide_hw_breakpoint(entry->ksym_hbp);
entry->type = op;
ret = 0;
if (op > 0) {
entry->ksym_hbp =
register_wide_hw_breakpoint(entry->ksym_addr,
entry->len, entry->type,
ksym_hbp_handler, true);
if (IS_ERR(entry->ksym_hbp))
entry->ksym_hbp = NULL;

/* modified without problem */
if (entry->ksym_hbp) {
ret = 0;
ret = PTR_ERR(entry->ksym_hbp);
else
goto out;
}
} else {
ret = 0;
}
/* Error or "symbol:---" case: drop it */
ksym_filter_entry_count--;
Expand Down
3 changes: 0 additions & 3 deletions samples/hw_breakpoint/data_breakpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ static int __init hw_break_module_init(void)
if (IS_ERR(sample_hbp)) {
ret = PTR_ERR(sample_hbp);
goto fail;
} else if (!sample_hbp) {
ret = -EINVAL;
goto fail;
}

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

0 comments on commit 605bfae

Please sign in to comment.