Skip to content

Commit

Permalink
drm/tests: Use KUNIT_DEFINE_ACTION_WRAPPER()
Browse files Browse the repository at this point in the history
In order to pass functions to kunit_add_action(), they need to be of the
kunit_action_t type. While casting the function pointer can work, it
will break control-flow integrity.

drm_kunit_helpers already defines wrappers, but we now have a macro
which does this automatically. Using this greatly reduces the
boilerplate needed.

Acked-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
David Gow authored and Shuah Khan committed Dec 18, 2023
1 parent 56778b4 commit e847934
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions drivers/gpu/drm/tests/drm_kunit_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,15 @@ static struct platform_driver fake_platform_driver = {
},
};

static void kunit_action_platform_driver_unregister(void *ptr)
{
struct platform_driver *drv = ptr;

platform_driver_unregister(drv);

}

static void kunit_action_platform_device_put(void *ptr)
{
struct platform_device *pdev = ptr;

platform_device_put(pdev);
}

static void kunit_action_platform_device_del(void *ptr)
{
struct platform_device *pdev = ptr;

platform_device_del(pdev);
}
KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_driver_unregister,
platform_driver_unregister,
struct platform_driver *);
KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_put,
platform_device_put,
struct platform_device *);
KUNIT_DEFINE_ACTION_WRAPPER(kunit_action_platform_device_del,
platform_device_del,
struct platform_device *);

/**
* drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test
Expand Down

0 comments on commit e847934

Please sign in to comment.