From: Michal Wajdeczko Date: Mon, 18 Dec 2023 19:06:25 +0000 (+0100) Subject: drm/xe/kunit: Restore test->priv when done with fake xe device X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=0b75475723b182400a4bfa5aaff9a969afdfdb76;p=linux.git drm/xe/kunit: Restore test->priv when done with fake xe device Current KUnit implementation does not reset test->priv in case of parametrized tests and that may lead to wrongly treat our output pointer to fake xe_device from first call as input pointer with xe_pci_fake_data on subsequent calls. Restore test->priv to original value to avoid invalid access. Acked-by: Lucas De Marchi Link: https://lore.kernel.org/r/20231218190629.502-7-michal.wajdeczko@intel.com Signed-off-by: Michal Wajdeczko --- diff --git a/drivers/gpu/drm/xe/tests/xe_kunit_helpers.c b/drivers/gpu/drm/xe/tests/xe_kunit_helpers.c index 6d72dbf061393..fefe79b3b75a4 100644 --- a/drivers/gpu/drm/xe/tests/xe_kunit_helpers.c +++ b/drivers/gpu/drm/xe/tests/xe_kunit_helpers.c @@ -41,6 +41,13 @@ struct xe_device *xe_kunit_helper_alloc_xe_device(struct kunit *test, } EXPORT_SYMBOL_IF_KUNIT(xe_kunit_helper_alloc_xe_device); +static void kunit_action_restore_priv(void *priv) +{ + struct kunit *test = kunit_get_current_test(); + + test->priv = priv; +} + /** * xe_kunit_helper_xe_device_test_init - Prepare a &xe_device for a KUnit test. * @test: the &kunit where this fake &xe_device will be used @@ -74,6 +81,9 @@ int xe_kunit_helper_xe_device_test_init(struct kunit *test) err = xe_pci_fake_device_init(xe); KUNIT_ASSERT_EQ(test, err, 0); + err = kunit_add_action_or_reset(test, kunit_action_restore_priv, test->priv); + KUNIT_ASSERT_EQ(test, err, 0); + test->priv = xe; return 0; }