int err;
if (!ppmu)
- return NULL;
+ return ERR_PTR(-ENXIO);
if ((s64)counter->hw_event.irq_period < 0)
- return NULL;
+ return ERR_PTR(-EINVAL);
if (!perf_event_raw(&counter->hw_event)) {
ev = perf_event_id(&counter->hw_event);
if (ev >= ppmu->n_generic || ppmu->generic_events[ev] == 0)
- return NULL;
+ return ERR_PTR(-EOPNOTSUPP);
ev = ppmu->generic_events[ev];
} else {
ev = perf_event_config(&counter->hw_event);
n = collect_events(counter->group_leader, ppmu->n_counter - 1,
ctrs, events);
if (n < 0)
- return NULL;
+ return ERR_PTR(-EINVAL);
}
events[n] = ev;
ctrs[n] = counter;
if (check_excludes(ctrs, n, 1))
- return NULL;
+ return ERR_PTR(-EINVAL);
if (power_check_constraints(events, n + 1))
- return NULL;
+ return ERR_PTR(-EINVAL);
counter->hw.config = events[n];
atomic64_set(&counter->hw.period_left, counter->hw_event.irq_period);
counter->destroy = hw_perf_counter_destroy;
if (err)
- return NULL;
+ return ERR_PTR(err);
return &power_perf_ops;
}
{
const struct hw_perf_counter_ops *hw_ops;
struct perf_counter *counter;
+ long err;
counter = kzalloc(sizeof(*counter), gfpflags);
if (!counter)
- return NULL;
+ return ERR_PTR(-ENOMEM);
/*
* Single counters are their own group leaders, with an
hw_ops = tp_perf_counter_init(counter);
break;
}
+done:
+ err = 0;
+ if (!hw_ops)
+ err = -EINVAL;
+ else if (IS_ERR(hw_ops))
+ err = PTR_ERR(hw_ops);
- if (!hw_ops) {
+ if (err) {
kfree(counter);
- return NULL;
+ return ERR_PTR(err);
}
-done:
+
counter->hw_ops = hw_ops;
return counter;
goto err_put_context;
}
- ret = -EINVAL;
counter = perf_counter_alloc(&hw_event, cpu, ctx, group_leader,
GFP_KERNEL);
- if (!counter)
+ ret = PTR_ERR(counter);
+ if (IS_ERR(counter))
goto err_put_context;
ret = anon_inode_getfd("[perf_counter]", &perf_fops, counter, 0);
child_counter = perf_counter_alloc(&parent_counter->hw_event,
parent_counter->cpu, child_ctx,
group_leader, GFP_KERNEL);
- if (!child_counter)
- return NULL;
+ if (IS_ERR(child_counter))
+ return child_counter;
/*
* Link it up in the child's context:
{
struct perf_counter *leader;
struct perf_counter *sub;
+ struct perf_counter *child_ctr;
leader = inherit_counter(parent_counter, parent, parent_ctx,
child, NULL, child_ctx);
- if (!leader)
- return -ENOMEM;
+ if (IS_ERR(leader))
+ return PTR_ERR(leader);
list_for_each_entry(sub, &parent_counter->sibling_list, list_entry) {
- if (!inherit_counter(sub, parent, parent_ctx,
- child, leader, child_ctx))
- return -ENOMEM;
+ child_ctr = inherit_counter(sub, parent, parent_ctx,
+ child, leader, child_ctx);
+ if (IS_ERR(child_ctr))
+ return PTR_ERR(child_ctr);
}
return 0;
}