Currently, the build-in PMUs are not added to pmu_idr. This makes
a inconvenience for finding PMU by type.

Signed-off-by: Yan, Zheng <zheng.z....@intel.com>
---
 kernel/events/core.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index ed50b09..bafc416 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6496,14 +6496,15 @@ int perf_pmu_register(struct pmu *pmu, const char 
*name, int type)
                goto skip_type;
        pmu->name = name;
 
-       if (type < 0) {
-               type = idr_alloc(&pmu_idr, pmu, PERF_TYPE_MAX, 0, GFP_KERNEL);
-               if (type < 0) {
-                       ret = type;
-                       goto free_pdc;
-               }
+       ret = idr_alloc(&pmu_idr, pmu, type >= 0 ? type : PERF_TYPE_MAX,
+                       0, GFP_KERNEL);
+       if (ret < 0)
+               goto free_pdc;
+       pmu->type = ret;
+       if (WARN_ON_ONCE(type >= 0 && pmu->type != type)) {
+               ret = -EINVAL;
+               goto free_idr;
        }
-       pmu->type = type;
 
        if (pmu_bus_running) {
                ret = pmu_dev_alloc(pmu);
@@ -6575,8 +6576,7 @@ free_dev:
        put_device(pmu->dev);
 
 free_idr:
-       if (pmu->type >= PERF_TYPE_MAX)
-               idr_remove(&pmu_idr, pmu->type);
+       idr_remove(&pmu_idr, pmu->type);
 
 free_pdc:
        free_percpu(pmu->pmu_disable_count);
@@ -6598,8 +6598,7 @@ void perf_pmu_unregister(struct pmu *pmu)
        synchronize_rcu();
 
        free_percpu(pmu->pmu_disable_count);
-       if (pmu->type >= PERF_TYPE_MAX)
-               idr_remove(&pmu_idr, pmu->type);
+       idr_remove(&pmu_idr, pmu->type);
        device_del(pmu->dev);
        put_device(pmu->dev);
        free_pmu_context(pmu);
-- 
1.9.0

--
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/

Reply via email to