lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250520082435.2255639-6-tzungbi@kernel.org>
Date: Tue, 20 May 2025 08:24:32 +0000
From: Tzung-Bi Shih <tzungbi@...nel.org>
To: bleung@...omium.org,
	brendan.higgins@...ux.dev,
	davidgow@...gle.com
Cc: tzungbi@...nel.org,
	rmoar@...gle.com,
	rostedt@...dmis.org,
	mhiramat@...nel.org,
	naveen@...nel.org,
	anil.s.keshavamurthy@...el.com,
	davem@...emloft.net,
	chrome-platform@...ts.linux.dev,
	linux-kselftest@...r.kernel.org,
	kunit-dev@...glegroups.com,
	linux-trace-kernel@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [RFC PATCH 5/7] platform/chrome: kunit: cros_ec_spi: Call .probe() directly

Get the spi_driver and call .probe() directly.

For running the tests:

$ ./tools/testing/kunit/kunit.py run \
	--arch=x86_64 \
	--kconfig_add CONFIG_FTRACE=y \
	--kconfig_add CONFIG_FUNCTION_TRACER=y \
	--kconfig_add CONFIG_MODULES=y \
	--kconfig_add CONFIG_DEBUG_KERNEL=y \
	--kconfig_add CONFIG_KALLSYMS_ALL=y \
	--kconfig_add CONFIG_LIVEPATCH=y \
	--kconfig_add CONFIG_KUNIT_FTRACE_STUBS=y \
	--kconfig_add CONFIG_CHROME_PLATFORMS=y \
	--kconfig_add CONFIG_CROS_EC=y \
	--kconfig_add CONFIG_SPI=y \
	--kconfig_add CONFIG_CROS_EC_SPI=y \
	--kconfig_add CONFIG_CROS_KUNIT_EC_SPI_TEST=y \
	cros_ec_spi*

Signed-off-by: Tzung-Bi Shih <tzungbi@...nel.org>
---
 drivers/platform/chrome/cros_ec_spi_test.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_spi_test.c b/drivers/platform/chrome/cros_ec_spi_test.c
index 2a021569a726..52dea75ecabf 100644
--- a/drivers/platform/chrome/cros_ec_spi_test.c
+++ b/drivers/platform/chrome/cros_ec_spi_test.c
@@ -27,6 +27,7 @@ struct cros_ec_spi_test_priv {
 	struct device dev;
 	struct spi_controller *fake_ctlr;
 	struct spi_device *fake_spi_device;
+	struct spi_driver *spi_drv;
 
 	int fake_cros_ec_register_called;
 	struct cros_ec_device *ec_dev;
@@ -117,16 +118,12 @@ static int find_target_driver(struct device_driver *drv, void *data)
 static int cros_ec_spi_test_init(struct kunit *test)
 {
 	struct cros_ec_spi_test_priv *priv;
-	struct spi_board_info board_info = {};
 	int ret;
 	struct device_driver *drv;
-	enum probe_type orig;
 
 	kunit_activate_ftrace_stub(test, cros_ec_register, fake_cros_ec_register);
 	kunit_activate_ftrace_stub(test, cros_ec_unregister, fake_cros_ec_unregister);
 
-	sized_strscpy(board_info.modalias, "cros-ec-spi", SPI_NAME_SIZE);
-
 	priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_NULL(test, priv);
 	test->priv = priv;
@@ -151,21 +148,17 @@ static int cros_ec_spi_test_init(struct kunit *test)
 	ret = spi_register_controller(priv->fake_ctlr);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 
-	/*
-	 * Force to use synchronous probe so that the upcoming SPI device gets
-	 * probed correctly and synchronously.
-	 */
 	ret = bus_for_each_drv(&spi_bus_type, NULL, &drv, find_target_driver);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 	KUNIT_ASSERT_NOT_NULL(test, drv);
-	orig = drv->probe_type;
-	drv->probe_type = PROBE_FORCE_SYNCHRONOUS;
 
-	priv->fake_spi_device = spi_new_device(priv->fake_ctlr, &board_info);
-	/* Restore to original probe type. */
-	drv->probe_type = orig;
+	priv->fake_spi_device = spi_alloc_device(priv->fake_ctlr);
 	KUNIT_ASSERT_NOT_NULL(test, priv->fake_spi_device);
 
+	priv->spi_drv = container_of(drv, struct spi_driver, driver);
+	ret = priv->spi_drv->probe(priv->fake_spi_device);
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
 	KUNIT_EXPECT_EQ(test, priv->fake_cros_ec_register_called, 1);
 	KUNIT_ASSERT_NOT_NULL(test, priv->ec_dev);
 	KUNIT_EXPECT_EQ(test, priv->fake_cros_ec_unregister_called, 0);
@@ -180,9 +173,10 @@ static void cros_ec_spi_test_exit(struct kunit *test)
 {
 	struct cros_ec_spi_test_priv *priv = test->priv;
 
-	spi_unregister_device(priv->fake_spi_device);
+	priv->spi_drv->remove(priv->fake_spi_device);
 	KUNIT_EXPECT_EQ(test, priv->fake_cros_ec_unregister_called, 1);
 
+	spi_dev_put(priv->fake_spi_device);
 	spi_unregister_controller(priv->fake_ctlr);
 	device_del(&priv->dev);
 	class_destroy(priv->fake_class);
-- 
2.49.0.1101.gccaa498523-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ