drm/ttm/tests: fix potential null pointer dereference in ttm_bo_unreserve_bulk()
Quoted 18 lines · Christian König
Am 11.03.25 um 20:01 schrieb Qasim Ijaz:
Quoted 5 lines
In the
ttm_bo_unreserve_bulk()test function, resv is allocated usingkunit_kzalloc(), but the subsequent assertion mistakenly verifies thettm_devpointer instead of checking the resv pointer. This mistake means that if allocation for resv fails, the error will go undetected, resv will be NULL and a call todma_resv_init(resv)The description here is correct, but the subject line is a bit misleading.
Please use something like this instead "drm/ttm/tests: incorrect assert in
ttm_bo_unreserve_bulk()".Quoted 1 line
will dereference a NULL pointer.
That irrelevant, an allocation failure will result in a NULL pointer deref anyway. This is just an unit test.
Quoted 3 lines
Fix the assertion to properly verify the resv pointer.
Quoted 8 lines
Quoted 2 lines
Fixes 588c4c8d58c4 ("drm/ttm/tests: Fix a warning in ttm_bo_unreserve_bulk")Please drop those tags. This is just an unit test, not relevant for stability and therefore shouldn't be backported.
Regards,
Christian.
Thank you for the feedback Christian, I will resend a new patch with the changes you described.
Thanks,
Qasim.
Quoted 19 lines
Quoted 18 lines
Signed-off-by Qasim Ijaz <[email protected]>--- drivers/gpu/drm/ttm/tests/ttm_bo_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/ttm/tests/ttm_bo_test.c +1
-1@@ -340,7 +340,7 @@ static void ttm_bo_unreserve_bulk(struct kunit *test)KUNIT_ASSERT_NOT_NULL (test, ttm_dev); resv =kunit_kzalloc (test,sizeof (*resv),GFP_KERNEL ); -KUNIT_ASSERT_NOT_NULL (test, ttm_dev); +KUNIT_ASSERT_NOT_NULL (test, resv); err =ttm_device_kunit_init (priv, ttm_dev, false, false);KUNIT_ASSERT_EQ (test, err,0 );