test_stream() calls i915_perf_get_oa_config() which takes a reference
on the returned oa_config. On the error path where stream allocation
fails, the function returns without calling i915_oa_config_put() on
the oa_config, leaking the reference.

Move the oa_config check after the props.engine check and add
i915_oa_config_put(oa_config) on the error path to properly release
the reference.

Fixes: 9677a9f3b1ad ("drm/i915/perf: Move gt-specific data from i915->perf to 
gt->perf")
Cc: [email protected]
Signed-off-by: Wentao Liang <[email protected]>
---
 drivers/gpu/drm/i915/selftests/i915_perf.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_perf.c 
b/drivers/gpu/drm/i915/selftests/i915_perf.c
index e9469e27f42a..a3e0afb0549e 100644
--- a/drivers/gpu/drm/i915/selftests/i915_perf.c
+++ b/drivers/gpu/drm/i915/selftests/i915_perf.c
@@ -104,14 +104,16 @@ test_stream(struct i915_perf *perf)
        struct i915_perf_stream *stream;
        struct intel_gt *gt;
 
-       if (!props.engine)
-               return NULL;
-
        gt = props.engine->gt;
 
        if (!oa_config)
                return NULL;
 
+       if (!props.engine) {
+               i915_oa_config_put(oa_config);
+               return NULL;
+       }
+
        props.metrics_set = oa_config->id;
 
        stream = kzalloc_obj(*stream);
-- 
2.34.1

Reply via email to