kernel: bump 6.1 to 6.1.81
[openwrt/staging/981213.git] / target / linux / bcm27xx / patches-6.1 / 950-0495-drm-tests-helpers-Make-sure-the-device-is-bound.patch
1 From 51e89f803856386ebecef22453ab34907a393954 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Mon, 21 Nov 2022 13:18:29 +0100
4 Subject: [PATCH] drm/tests: helpers: Make sure the device is bound
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The device managed resources are freed when the device is detached, so
10 it has to be bound in the first place.
11
12 Let's create a fake driver that we will bind to our fake device to
13 benefit from the device managed cleanups in our tests.
14
15 Reviewed-by: MaĆ­ra Canal <mcanal@igalia.com>
16 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
17 ---
18 drivers/gpu/drm/tests/drm_kunit_helpers.c | 26 ++++++++++++++++++++++-
19 1 file changed, 25 insertions(+), 1 deletion(-)
20
21 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c
22 +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c
23 @@ -18,12 +18,32 @@ struct kunit_dev {
24 static const struct drm_mode_config_funcs drm_mode_config_funcs = {
25 };
26
27 +static int fake_probe(struct platform_device *pdev)
28 +{
29 + return 0;
30 +}
31 +
32 +static int fake_remove(struct platform_device *pdev)
33 +{
34 + return 0;
35 +}
36 +
37 +static struct platform_driver fake_platform_driver = {
38 + .probe = fake_probe,
39 + .remove = fake_remove,
40 + .driver = {
41 + .name = KUNIT_DEVICE_NAME,
42 + },
43 +};
44 +
45 /**
46 * drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test
47 * @test: The test context object
48 *
49 * This allocates a fake struct &device to create a mock for a KUnit
50 - * test.
51 + * test. The device will also be bound to a fake driver. It will thus be
52 + * able to leverage the usual infrastructure and most notably the
53 + * device-managed resources just like a "real" device.
54 *
55 * Callers need to make sure drm_kunit_helper_free_device() on the
56 * device when done.
57 @@ -36,6 +56,9 @@ struct device *drm_kunit_helper_alloc_de
58 struct platform_device *pdev;
59 int ret;
60
61 + ret = platform_driver_register(&fake_platform_driver);
62 + KUNIT_ASSERT_EQ(test, ret, 0);
63 +
64 pdev = platform_device_alloc(KUNIT_DEVICE_NAME, PLATFORM_DEVID_NONE);
65 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
66
67 @@ -58,6 +81,7 @@ void drm_kunit_helper_free_device(struct
68 struct platform_device *pdev = to_platform_device(dev);
69
70 platform_device_unregister(pdev);
71 + platform_driver_unregister(&fake_platform_driver);
72 }
73 EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device);
74