If idr_alloc() fails, the error path jumps to sysfs_err, which only drops
metrics_lock and falls through to reg_err, where i915_oa_config_put()
releases the last reference and frees the config. The sysfs group is
never removed. Fix the error path so that sysfs group is also cleaned up.

Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG 
interface")
Reported-by: Martin Hodo <[email protected]>
Signed-off-by: Umesh Nerlige Ramappa <[email protected]>
Assisted-by: Claude:claude-opus-5
---
 drivers/gpu/drm/i915/i915_perf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 96823dcd3fae..abda7b1c4956 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4728,7 +4728,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, 
void *data,
                drm_dbg(&perf->i915->drm,
                        "Failed to create sysfs entry for OA config\n");
                err = oa_config->id;
-               goto sysfs_err;
+               goto remove_sysfs;
        }
        id = oa_config->id;
 
@@ -4738,6 +4738,8 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, 
void *data,
 
        return id;
 
+remove_sysfs:
+       sysfs_remove_group(perf->metrics_kobj, &oa_config->sysfs_metric);
 sysfs_err:
        mutex_unlock(&perf->metrics_lock);
 reg_err:
-- 
2.53.0

Reply via email to