kernel_context() returns an error pointer on failure, never NULL, so
the NULL checks on its return value are unreachable. On a real
allocation failure the subsequent dereference of the returned ERR_PTR
(e.g. ctx_hi->sched.priority = ...) would oops the test kernel.

Use IS_ERR() and propagate the actual error via PTR_ERR() in
live_preempt(), live_late_preempt(), live_preempt_timeout() and
preempt_client_init().

Signed-off-by: Ingyu Jang <[email protected]>
---
 drivers/gpu/drm/i915/gt/selftest_execlists.c | 28 ++++++++++++--------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/selftest_execlists.c 
b/drivers/gpu/drm/i915/gt/selftest_execlists.c
index 21e5ed9f72a30..36f51805f74e3 100644
--- a/drivers/gpu/drm/i915/gt/selftest_execlists.c
+++ b/drivers/gpu/drm/i915/gt/selftest_execlists.c
@@ -1742,13 +1742,15 @@ static int live_preempt(void *arg)
        int err = -ENOMEM;
 
        ctx_hi = kernel_context(gt->i915, NULL);
-       if (!ctx_hi)
-               return -ENOMEM;
+       if (IS_ERR(ctx_hi))
+               return PTR_ERR(ctx_hi);
        ctx_hi->sched.priority = I915_CONTEXT_MAX_USER_PRIORITY;
 
        ctx_lo = kernel_context(gt->i915, NULL);
-       if (!ctx_lo)
+       if (IS_ERR(ctx_lo)) {
+               err = PTR_ERR(ctx_lo);
                goto err_ctx_hi;
+       }
        ctx_lo->sched.priority = I915_CONTEXT_MIN_USER_PRIORITY;
 
        if (igt_spinner_init(&spin_hi, gt))
@@ -1834,12 +1836,14 @@ static int live_late_preempt(void *arg)
        int err = -ENOMEM;
 
        ctx_hi = kernel_context(gt->i915, NULL);
-       if (!ctx_hi)
-               return -ENOMEM;
+       if (IS_ERR(ctx_hi))
+               return PTR_ERR(ctx_hi);
 
        ctx_lo = kernel_context(gt->i915, NULL);
-       if (!ctx_lo)
+       if (IS_ERR(ctx_lo)) {
+               err = PTR_ERR(ctx_lo);
                goto err_ctx_hi;
+       }
 
        if (igt_spinner_init(&spin_hi, gt))
                goto err_ctx_lo;
@@ -1934,8 +1938,8 @@ struct preempt_client {
 static int preempt_client_init(struct intel_gt *gt, struct preempt_client *c)
 {
        c->ctx = kernel_context(gt->i915, NULL);
-       if (!c->ctx)
-               return -ENOMEM;
+       if (IS_ERR(c->ctx))
+               return PTR_ERR(c->ctx);
 
        if (igt_spinner_init(&c->spin, gt))
                goto err_ctx;
@@ -3384,13 +3388,15 @@ static int live_preempt_timeout(void *arg)
                return 0;
 
        ctx_hi = kernel_context(gt->i915, NULL);
-       if (!ctx_hi)
-               return -ENOMEM;
+       if (IS_ERR(ctx_hi))
+               return PTR_ERR(ctx_hi);
        ctx_hi->sched.priority = I915_CONTEXT_MAX_USER_PRIORITY;
 
        ctx_lo = kernel_context(gt->i915, NULL);
-       if (!ctx_lo)
+       if (IS_ERR(ctx_lo)) {
+               err = PTR_ERR(ctx_lo);
                goto err_ctx_hi;
+       }
        ctx_lo->sched.priority = I915_CONTEXT_MIN_USER_PRIORITY;
 
        if (igt_spinner_init(&spin_lo, gt))
-- 
2.34.1

Reply via email to