diff --git a/kernel/events/core.c b/kernel/events/core.c index 3cd13a30f73292..bac38d972bb2ee 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9737,7 +9737,8 @@ void perf_pmu_unregister(struct pmu *pmu) device_del(pmu->dev); put_device(pmu->dev); } - free_pmu_context(pmu); + if (!find_pmu_context(pmu->task_ctx_nr)) + free_pmu_context(pmu); mutex_unlock(&pmus_lock); } EXPORT_SYMBOL_GPL(perf_pmu_unregister);