Skip to content

Commit caa7c7a

Browse files
Dan Carpenterjlahtine-intel
authored andcommitted
drm/i915/selftests: Change mock_request() to return error pointers
There was an error pointer vs NULL bug in __igt_breadcrumbs_smoketest(). The __mock_request_alloc() function implements the smoketest->request_alloc() function pointer. It was supposed to return error pointers, but it propogates the NULL return from mock_request() so in the event of a failure, it would lead to a NULL pointer dereference. To fix this, change the mock_request() function to return error pointers and update all the callers to expect that. Fixes: 52c0fdb ("drm/i915: Replace global breadcrumbs with per-context interrupt tracking") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Rodrigo Vivi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rodrigo Vivi <[email protected]> (cherry picked from commit 778fa8a) Signed-off-by: Joonas Lahtinen <[email protected]>
1 parent d0b3b7b commit caa7c7a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

drivers/gpu/drm/i915/selftests/i915_request.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ static int igt_add_request(void *arg)
7373
/* Basic preliminary test to create a request and let it loose! */
7474

7575
request = mock_request(rcs0(i915)->kernel_context, HZ / 10);
76-
if (!request)
77-
return -ENOMEM;
76+
if (IS_ERR(request))
77+
return PTR_ERR(request);
7878

7979
i915_request_add(request);
8080

@@ -91,8 +91,8 @@ static int igt_wait_request(void *arg)
9191
/* Submit a request, then wait upon it */
9292

9393
request = mock_request(rcs0(i915)->kernel_context, T);
94-
if (!request)
95-
return -ENOMEM;
94+
if (IS_ERR(request))
95+
return PTR_ERR(request);
9696

9797
i915_request_get(request);
9898

@@ -160,8 +160,8 @@ static int igt_fence_wait(void *arg)
160160
/* Submit a request, treat it as a fence and wait upon it */
161161

162162
request = mock_request(rcs0(i915)->kernel_context, T);
163-
if (!request)
164-
return -ENOMEM;
163+
if (IS_ERR(request))
164+
return PTR_ERR(request);
165165

166166
if (dma_fence_wait_timeout(&request->fence, false, T) != -ETIME) {
167167
pr_err("fence wait success before submit (expected timeout)!\n");
@@ -219,8 +219,8 @@ static int igt_request_rewind(void *arg)
219219
GEM_BUG_ON(IS_ERR(ce));
220220
request = mock_request(ce, 2 * HZ);
221221
intel_context_put(ce);
222-
if (!request) {
223-
err = -ENOMEM;
222+
if (IS_ERR(request)) {
223+
err = PTR_ERR(request);
224224
goto err_context_0;
225225
}
226226

@@ -237,8 +237,8 @@ static int igt_request_rewind(void *arg)
237237
GEM_BUG_ON(IS_ERR(ce));
238238
vip = mock_request(ce, 0);
239239
intel_context_put(ce);
240-
if (!vip) {
241-
err = -ENOMEM;
240+
if (IS_ERR(vip)) {
241+
err = PTR_ERR(vip);
242242
goto err_context_1;
243243
}
244244

drivers/gpu/drm/i915/selftests/mock_request.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mock_request(struct intel_context *ce, unsigned long delay)
3535
/* NB the i915->requests slab cache is enlarged to fit mock_request */
3636
request = intel_context_create_request(ce);
3737
if (IS_ERR(request))
38-
return NULL;
38+
return request;
3939

4040
request->mock.delay = delay;
4141
return request;

0 commit comments

Comments
 (0)