Message ID | 20230920-kunit-kasan-fixes-v1-3-1a0fc261832d@riseup.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Fix a couble of bugs in drm_kunit_helpers.c | expand |
Hi, On Wed, Sep 20, 2023 at 03:11:38AM -0300, Arthur Grillo wrote: > In __drm_kunit_helper_alloc_drm_device_with_driver(), a drm_driver is > allocated with kunit_kzalloc. If the dev argument was allocated by > drm_kunit_helper_alloc_device, its deferred actions would access the > already deallocated drm_driver. We already have a fix for that in drm-misc-fixes, could you give it a try? Thanks! Maxime
On 20/09/23 03:40, Maxime Ripard wrote: > Hi, > > On Wed, Sep 20, 2023 at 03:11:38AM -0300, Arthur Grillo wrote: >> In __drm_kunit_helper_alloc_drm_device_with_driver(), a drm_driver is >> allocated with kunit_kzalloc. If the dev argument was allocated by >> drm_kunit_helper_alloc_device, its deferred actions would access the >> already deallocated drm_driver. > > We already have a fix for that in drm-misc-fixes, could you give it a try? Oh! I didn't see that. I just ran it, it worked! Great fix :) Best Regards, ~Arthur Grillo > > Thanks! > Maxime
diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index 3150dbc647ee..655cedf7ab13 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -129,6 +129,7 @@ __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test, const struct drm_driver *driver) { struct drm_device *drm; + struct platform_device *pdev = to_platform_device(dev); void *container; int ret; @@ -143,6 +144,21 @@ __drm_kunit_helper_alloc_drm_device_with_driver(struct kunit *test, if (ret) return ERR_PTR(ret); + ret = kunit_move_action_to_top_or_reset(test, + kunit_action_platform_driver_unregister, + &fake_platform_driver); + KUNIT_ASSERT_EQ(test, ret, 0); + + ret = kunit_move_action_to_top_or_reset(test, + kunit_action_platform_device_put, + pdev); + KUNIT_ASSERT_EQ(test, ret, 0); + + ret = kunit_move_action_to_top_or_reset(test, + kunit_action_platform_device_del, + pdev); + KUNIT_ASSERT_EQ(test, ret, 0); + return drm; } EXPORT_SYMBOL_GPL(__drm_kunit_helper_alloc_drm_device_with_driver);