[PATCH] perf/core: Add missing device_remove_file() in pmu_dev_alloc()

From: Zhen Lei
Date: Sun Aug 08 2021 - 23:50:14 EST


The device attribute file 'nr_addr_filters' should be removed when
sysfs_update_groups() fails.

Fixes: f3a3a8257e5a ("perf/core: Add attr_groups_update into struct pmu")
Signed-off-by: Zhen Lei <thunder.leizhen@xxxxxxxxxx>
---
kernel/events/core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 464917096e73..7d465584445b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10980,11 +10980,15 @@ static int pmu_dev_alloc(struct pmu *pmu)
ret = sysfs_update_groups(&pmu->dev->kobj, pmu->attr_update);

if (ret)
- goto del_dev;
+ goto remove_file;

out:
return ret;

+remove_file:
+ if (pmu->nr_addr_filters)
+ device_remove_file(pmu->dev, &dev_attr_nr_addr_filters);
+
del_dev:
device_del(pmu->dev);

--
2.25.1