From: David Gow <davidgow@google.com>
To: Nathan Chancellor <nathan@kernel.org>,
Kees Cook <keescook@chromium.org>,
Brendan Higgins <brendan.higgins@linux.dev>,
Rae Moar <rmoar@google.com>,
dlatypov@google.com
Cc: David Gow <davidgow@google.com>,
Benjamin Berg <benjamin.berg@intel.com>,
Maxime Ripard <mripard@kernel.org>,
Richard Fitzgerald <rf@opensource.cirrus.com>,
llvm@lists.linux.dev, linux-kernel@vger.kernel.org,
kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org,
linux-hardening@vger.kernel.org,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>
Subject: [PATCH v2 2/3] drm/tests: Use KUNIT_DEFINE_ACTION_WRAPPER()
Date: Tue, 28 Nov 2023 15:24:06 +0800 [thread overview]
Message-ID: <20231128072410.952662-2-davidgow@google.com> (raw)
In-Reply-To: <20231128072410.952662-1-davidgow@google.com>
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>
---
No changes since v1:
https://lore.kernel.org/linux-kselftest/20231110200830.1832556-2-davidgow@google.com/
---
drivers/gpu/drm/tests/drm_kunit_helpers.c | 30 +++++++----------------
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c
index bccb33b900f3..c251e6b34de0 100644
--- a/drivers/gpu/drm/tests/drm_kunit_helpers.c
+++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c
@@ -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
--
2.43.0.rc1.413.gea7ed67945-goog
next prev parent reply other threads:[~2023-11-28 7:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 7:24 [PATCH v2 1/3] kunit: Add a macro to wrap a deferred action function David Gow
2023-11-28 7:24 ` David Gow [this message]
2023-11-28 7:24 ` [PATCH v2 3/3] drm/vc4: tests: Use KUNIT_DEFINE_ACTION_WRAPPER David Gow
2023-11-28 14:53 ` Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231128072410.952662-2-davidgow@google.com \
--to=davidgow@google.com \
--cc=benjamin.berg@intel.com \
--cc=brendan.higgins@linux.dev \
--cc=dlatypov@google.com \
--cc=keescook@chromium.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mripard@kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=rf@opensource.cirrus.com \
--cc=rmoar@google.com \
--cc=trix@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox