Skip to content

Commit c6567f6

Browse files
fweisbecIngo Molnar
authored andcommitted
hw-breakpoints: Improve in-kernel event creation error granularity
In fail case, perf_event_create_kernel_counter() returns NULL instead of an error, which doesn't help us to inform the user about the origin of the problem from the outer most callers. Often we can just return -EINVAL, which doesn't help anyone when it's eventually about a memory allocation failure. Then, this patch makes perf_event_create_kernel_counter() always return a detailed error code. 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: Prasad <prasad@linux.vnet.ibm.com> LKML-Reference: <1259210142-5714-2-git-send-regression-fweisbec@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent d99be40 commit c6567f6

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎kernel/perf_event.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,14 +4780,17 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
47804780
*/
47814781

47824782
ctx = find_get_context(pid, cpu);
4783-
if (IS_ERR(ctx))
4784-
return NULL;
4783+
if (IS_ERR(ctx)) {
4784+
err = PTR_ERR(ctx);
4785+
goto err_exit;
4786+
}
47854787

47864788
event = perf_event_alloc(attr, cpu, ctx, NULL,
47874789
NULL, callback, GFP_KERNEL);
4788-
err = PTR_ERR(event);
4789-
if (IS_ERR(event))
4790+
if (IS_ERR(event)) {
4791+
err = PTR_ERR(event);
47904792
goto err_put_context;
4793+
}
47914794

47924795
event->filp = NULL;
47934796
WARN_ON_ONCE(ctx->parent_ctx);
@@ -4804,11 +4807,10 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
48044807

48054808
return event;
48064809

4807-
err_put_context:
4808-
if (err < 0)
4809-
put_ctx(ctx);
4810-
4811-
return NULL;
4810+
err_put_context:
4811+
put_ctx(ctx);
4812+
err_exit:
4813+
return ERR_PTR(err);
48124814
}
48134815
EXPORT_SYMBOL_GPL(perf_event_create_kernel_counter);
48144816

0 commit comments

Comments
 (0)