From: Frederic Weisbecker <fweis...@gmail.com> Do this in order to prepare for toggle event inheritance support that will rely on pre-allocated perf event.
Signed-off-by: Frederic Weisbecker <fweis...@gmail.com> Signed-off-by: Jiri Olsa <jo...@redhat.com> Cc: Arnaldo Carvalho de Melo <a...@redhat.com> Cc: Corey Ashford <cjash...@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweis...@gmail.com> Cc: Ingo Molnar <mi...@elte.hu> Cc: Paul Mackerras <pau...@samba.org> Cc: Peter Zijlstra <a.p.zijls...@chello.nl> Cc: Arnaldo Carvalho de Melo <a...@redhat.com> --- kernel/events/core.c | 59 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 2a19b64..fa1d229 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6673,31 +6673,23 @@ static void account_event(struct perf_event *event) account_event_cpu(event, event->cpu); } -/* - * Allocate and initialize a event structure - */ -static struct perf_event * -perf_event_alloc(struct perf_event_attr *attr, int cpu, - struct task_struct *task, - struct perf_event *group_leader, - struct perf_event *parent_event, - perf_overflow_handler_t overflow_handler, - void *context) +static int perf_init_event(struct perf_event *event, + struct perf_event_attr *attr, int cpu, + struct task_struct *task, + struct perf_event *group_leader, + struct perf_event *parent_event, + perf_overflow_handler_t overflow_handler, + void *context) { struct pmu *pmu; - struct perf_event *event; struct hw_perf_event *hwc; - long err = -EINVAL; + int err = -EINVAL; if ((unsigned)cpu >= nr_cpu_ids) { if (!task || cpu != -1) - return ERR_PTR(-EINVAL); + return err; } - event = kzalloc(sizeof(*event), GFP_KERNEL); - if (!event) - return ERR_PTR(-ENOMEM); - /* * Single events are their own group leaders, with an * empty sibling list: @@ -6791,7 +6783,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, } } - return event; + return 0; err_pmu: if (event->destroy) @@ -6799,9 +6791,36 @@ err_pmu: err_ns: if (event->ns) put_pid_ns(event->ns); - kfree(event); - return ERR_PTR(err); + return err; +} + +/* + * Allocate and initialize a event structure + */ +static struct perf_event * +perf_event_alloc(struct perf_event_attr *attr, int cpu, + struct task_struct *task, + struct perf_event *group_leader, + struct perf_event *parent_event, + perf_overflow_handler_t overflow_handler, + void *context) +{ + struct perf_event *event; + int err; + + event = kzalloc(sizeof(*event), GFP_KERNEL); + if (!event) + return ERR_PTR(-ENOMEM); + + err = perf_init_event(event, attr, cpu, task, group_leader, + parent_event, overflow_handler, context); + if (err) { + kfree(event); + return ERR_PTR(err); + } + + return event; } static int perf_copy_attr(struct perf_event_attr __user *uattr, -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/