Skip to contentSkip to conversation

perf: fix the missing event initialization when pmu is found in idr

PATCH Lin Ming 2 participants 3 messages Feb 27, 2011 – Mar 4, 2011

lore
Share & tools
lore

Lin Ming

author
#0 lore raw

Currently, the event is not initialized if pmu is found in idr. This never causes bug just because now no pmu is associated with the idr id.
This patch fixes the potential bug.

---
 kernel/perf_event.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
kernel/perf_event.c +7 -2
index 64a018e..821ce82 100644
@@ -6098,17 +6098,22 @@ struct pmu *perf_init_event(struct perf_event *event)
 {
 	struct pmu *pmu = NULL;
 	int idx;
+	int ret;
 
 	idx = srcu_read_lock(&pmus_srcu);
 
 	rcu_read_lock();
 	pmu = idr_find(&pmu_idr, event->attr.type);
 	rcu_read_unlock();
-	if (pmu)
+	if (pmu) {
+		ret = pmu->event_init(event);
+		if (ret)
+			pmu = ERR_PTR(ret);
 		goto unlock;
+	}
 
 	list_for_each_entry_rcu(pmu, &pmus, entry) {
-		int ret = pmu->event_init(event);
+		ret = pmu->event_init(event);
 		if (!ret)
 			goto unlock;
 
#1 lore raw
Quoted 3 lines · Lin Ming

Currently, the event is not initialized if pmu is found in idr. This never causes bug just because now no pmu is associated with the idr id.

Yeah, d'0h, thanks!

#2 lore raw

[tip:perf/core] perf: Fix the missing event initialization when pmu is found in idr

In reply to Lin Ming
Commit-ID:  940c5b2971de443df22eed0441bc74fb0116e9f5
Gitweb:     http://git.kernel.org/tip/940c5b2971de443df22eed0441bc74fb0116e9f5
Author:     Lin Ming <[email protected]>
AuthorDate: Sun, 27 Feb 2011 21:13:31 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Mar 2011 11:32:50 +0100

perf: Fix the missing event initialization when pmu is found in idr

Currently, the event is not initialized if pmu is found in idr. This never causes bug just because now no pmu is associated with the idr id.

LKML-Reference: <1298812411.2699.9.camel@localhost>

---
 kernel/perf_event.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
kernel/perf_event.c +7 -2
index 64a018e..821ce82 100644
@@ -6098,17 +6098,22 @@ struct pmu *perf_init_event(struct perf_event *event)
 {
 	struct pmu *pmu = NULL;
 	int idx;
+	int ret;
 
 	idx = srcu_read_lock(&pmus_srcu);
 
 	rcu_read_lock();
 	pmu = idr_find(&pmu_idr, event->attr.type);
 	rcu_read_unlock();
-	if (pmu)
+	if (pmu) {
+		ret = pmu->event_init(event);
+		if (ret)
+			pmu = ERR_PTR(ret);
 		goto unlock;
+	}
 
 	list_for_each_entry_rcu(pmu, &pmus, entry) {
-		int ret = pmu->event_init(event);
+		ret = pmu->event_init(event);
 		if (!ret)
 			goto unlock;