diff mbox series

[v2,01/11] drm/tests: helpers: Switch to kunit actions

Message ID 20230720-kms-kunit-actions-rework-v2-1-175017bd56ab@kernel.org (mailing list archive)
State New, archived
Headers show
Series drm: kunit: Switch to kunit actions | expand

Commit Message

Maxime Ripard July 20, 2023, 11:15 a.m. UTC
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/tests/drm_kunit_helpers.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

Comments

kernel test robot July 20, 2023, 5:14 p.m. UTC | #1
Hi Maxime,

kernel test robot noticed the following build warnings:

[auto build test WARNING on c58c49dd89324b18a812762a2bfa5a0458e4f252]

url:    https://github.com/intel-lab-lkp/linux/commits/Maxime-Ripard/drm-tests-helpers-Switch-to-kunit-actions/20230720-191901
base:   c58c49dd89324b18a812762a2bfa5a0458e4f252
patch link:    https://lore.kernel.org/r/20230720-kms-kunit-actions-rework-v2-1-175017bd56ab%40kernel.org
patch subject: [PATCH v2 01/11] drm/tests: helpers: Switch to kunit actions
config: arm64-randconfig-r022-20230720 (https://download.01.org/0day-ci/archive/20230721/202307210148.7gWzLOtn-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce: (https://download.01.org/0day-ci/archive/20230721/202307210148.7gWzLOtn-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307210148.7gWzLOtn-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/tests/drm_kunit_helpers.c:53:6: warning: cast from 'void (*)(struct platform_driver *)' to 'kunit_action_t *' (aka 'void (*)(void *)') converts to incompatible function type [-Wcast-function-type-strict]
      53 |                                         (kunit_action_t *)platform_driver_unregister,
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/gpu/drm/tests/drm_kunit_helpers.c:61:6: warning: cast from 'void (*)(struct platform_device *)' to 'kunit_action_t *' (aka 'void (*)(void *)') converts to incompatible function type [-Wcast-function-type-strict]
      61 |                                         (kunit_action_t *)platform_device_put,
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/tests/drm_kunit_helpers.c:69:6: warning: cast from 'void (*)(struct platform_device *)' to 'kunit_action_t *' (aka 'void (*)(void *)') converts to incompatible function type [-Wcast-function-type-strict]
      69 |                                         (kunit_action_t *)platform_device_del,
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/tests/drm_kunit_helpers.c:89:9: warning: cast from 'void (*)(struct platform_device *)' to 'kunit_action_t *' (aka 'void (*)(void *)') converts to incompatible function type [-Wcast-function-type-strict]
      89 |                              (kunit_action_t *)platform_device_unregister,
         |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/tests/drm_kunit_helpers.c:93:9: warning: cast from 'void (*)(struct platform_driver *)' to 'kunit_action_t *' (aka 'void (*)(void *)') converts to incompatible function type [-Wcast-function-type-strict]
      93 |                              (kunit_action_t *)platform_driver_unregister,
         |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   5 warnings generated.


vim +53 drivers/gpu/drm/tests/drm_kunit_helpers.c

    28	
    29	/**
    30	 * drm_kunit_helper_alloc_device - Allocate a mock device for a KUnit test
    31	 * @test: The test context object
    32	 *
    33	 * This allocates a fake struct &device to create a mock for a KUnit
    34	 * test. The device will also be bound to a fake driver. It will thus be
    35	 * able to leverage the usual infrastructure and most notably the
    36	 * device-managed resources just like a "real" device.
    37	 *
    38	 * Resources will be cleaned up automatically, but the removal can be
    39	 * forced using @drm_kunit_helper_free_device.
    40	 *
    41	 * Returns:
    42	 * A pointer to the new device, or an ERR_PTR() otherwise.
    43	 */
    44	struct device *drm_kunit_helper_alloc_device(struct kunit *test)
    45	{
    46		struct platform_device *pdev;
    47		int ret;
    48	
    49		ret = platform_driver_register(&fake_platform_driver);
    50		KUNIT_ASSERT_EQ(test, ret, 0);
    51	
    52		ret = kunit_add_action_or_reset(test,
  > 53						(kunit_action_t *)platform_driver_unregister,
    54						&fake_platform_driver);
    55		KUNIT_ASSERT_EQ(test, ret, 0);
    56	
    57		pdev = platform_device_alloc(KUNIT_DEVICE_NAME, PLATFORM_DEVID_NONE);
    58		KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
    59	
    60		ret = kunit_add_action_or_reset(test,
  > 61						(kunit_action_t *)platform_device_put,
    62						pdev);
    63		KUNIT_ASSERT_EQ(test, ret, 0);
    64	
    65		ret = platform_device_add(pdev);
    66		KUNIT_ASSERT_EQ(test, ret, 0);
    67	
    68		ret = kunit_add_action_or_reset(test,
    69						(kunit_action_t *)platform_device_del,
    70						pdev);
    71		KUNIT_ASSERT_EQ(test, ret, 0);
    72	
    73		return &pdev->dev;
    74	}
    75	EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device);
    76
Maxime Ripard July 24, 2023, 11:19 a.m. UTC | #2
Hi David, Brendan,

On Fri, Jul 21, 2023 at 01:14:41AM +0800, kernel test robot wrote:
> Hi Maxime,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on c58c49dd89324b18a812762a2bfa5a0458e4f252]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Maxime-Ripard/drm-tests-helpers-Switch-to-kunit-actions/20230720-191901
> base:   c58c49dd89324b18a812762a2bfa5a0458e4f252
> patch link:    https://lore.kernel.org/r/20230720-kms-kunit-actions-rework-v2-1-175017bd56ab%40kernel.org
> patch subject: [PATCH v2 01/11] drm/tests: helpers: Switch to kunit actions
> config: arm64-randconfig-r022-20230720 (https://download.01.org/0day-ci/archive/20230721/202307210148.7gWzLOtn-lkp@intel.com/config)
> compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
> reproduce: (https://download.01.org/0day-ci/archive/20230721/202307210148.7gWzLOtn-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202307210148.7gWzLOtn-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
> >> drivers/gpu/drm/tests/drm_kunit_helpers.c:53:6: warning: cast from 'void (*)(struct platform_driver *)' to 'kunit_action_t *' (aka 'void (*)(void *)') converts to incompatible function type [-Wcast-function-type-strict]
>       53 |                                         (kunit_action_t *)platform_driver_unregister,
>          |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I missed that warning before, and I don't think we can address that
easily. Should we give up on kunit_action_t entirely?

Maxime
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c
index 4df47071dc88..5856beb7f7d7 100644
--- a/drivers/gpu/drm/tests/drm_kunit_helpers.c
+++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c
@@ -35,8 +35,8 @@  static struct platform_driver fake_platform_driver = {
  * able to leverage the usual infrastructure and most notably the
  * device-managed resources just like a "real" device.
  *
- * Callers need to make sure drm_kunit_helper_free_device() on the
- * device when done.
+ * Resources will be cleaned up automatically, but the removal can be
+ * forced using @drm_kunit_helper_free_device.
  *
  * Returns:
  * A pointer to the new device, or an ERR_PTR() otherwise.
@@ -49,12 +49,27 @@  struct device *drm_kunit_helper_alloc_device(struct kunit *test)
 	ret = platform_driver_register(&fake_platform_driver);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 
+	ret = kunit_add_action_or_reset(test,
+					(kunit_action_t *)platform_driver_unregister,
+					&fake_platform_driver);
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
 	pdev = platform_device_alloc(KUNIT_DEVICE_NAME, PLATFORM_DEVID_NONE);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
 
+	ret = kunit_add_action_or_reset(test,
+					(kunit_action_t *)platform_device_put,
+					pdev);
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
 	ret = platform_device_add(pdev);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 
+	ret = kunit_add_action_or_reset(test,
+					(kunit_action_t *)platform_device_del,
+					pdev);
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
 	return &pdev->dev;
 }
 EXPORT_SYMBOL_GPL(drm_kunit_helper_alloc_device);
@@ -70,8 +85,13 @@  void drm_kunit_helper_free_device(struct kunit *test, struct device *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 
-	platform_device_unregister(pdev);
-	platform_driver_unregister(&fake_platform_driver);
+	kunit_release_action(test,
+			     (kunit_action_t *)platform_device_unregister,
+			     pdev);
+
+	kunit_release_action(test,
+			     (kunit_action_t *)platform_driver_unregister,
+			     &fake_platform_driver);
 }
 EXPORT_SYMBOL_GPL(drm_kunit_helper_free_device);