linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marco Pagani <marpagan@redhat.com>
To: Moritz Fischer <mdf@kernel.org>, Wu Hao <hao.wu@intel.com>,
	Xu Yilun <yilun.xu@intel.com>, Tom Rix <trix@redhat.com>
Cc: Marco Pagani <marpagan@redhat.com>,
	linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org,
	Jinjie Ruan <ruanjinjie@huawei.com>
Subject: [PATCH v2 4/4] fpga: add a platform driver to the FPGA Region test suite
Date: Fri, 29 Sep 2023 17:20:57 +0200	[thread overview]
Message-ID: <20230929152057.85047-5-marpagan@redhat.com> (raw)
In-Reply-To: <20230929152057.85047-1-marpagan@redhat.com>

Register a minimal platform driver associated with the parent platform
device used for testing to prevent a null-ptr-deref when try_module_get()
is called by fpga_region_get(). Also, fix a typo in the suite's name.

Fixes: 64a5f972c93d ("fpga: add an initial KUnit suite for the FPGA Region")
Reported-by: Jinjie Ruan <ruanjinjie@huawei.com>
Signed-off-by: Marco Pagani <marpagan@redhat.com>
---
 drivers/fpga/tests/fpga-region-test.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/fpga/tests/fpga-region-test.c b/drivers/fpga/tests/fpga-region-test.c
index 9f9d50ee7871..5ff688b394f9 100644
--- a/drivers/fpga/tests/fpga-region-test.c
+++ b/drivers/fpga/tests/fpga-region-test.c
@@ -15,6 +15,8 @@
 #include <linux/platform_device.h>
 #include <linux/types.h>
 
+#include "fpga-test-helpers.h"
+
 struct mgr_stats {
 	u32 write_count;
 };
@@ -132,6 +134,18 @@ static void fpga_region_test_program_fpga(struct kunit *test)
 	fpga_image_info_free(img_info);
 }
 
+TEST_PLATFORM_DRIVER(test_platform_driver);
+
+static int fpga_region_test_suite_init(struct kunit_suite *suite)
+{
+	return platform_driver_register(&test_platform_driver);
+}
+
+static void fpga_region_test_suite_exit(struct kunit_suite *suite)
+{
+	platform_driver_unregister(&test_platform_driver);
+}
+
 /*
  * The configuration used in this test suite uses a single bridge to
  * limit the code under test to a single unit. The functions used by the
@@ -146,14 +160,15 @@ static int fpga_region_test_init(struct kunit *test)
 	ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
 
-	ctx->mgr_pdev = platform_device_register_simple("mgr_pdev", PLATFORM_DEVID_AUTO, NULL, 0);
+	ctx->mgr_pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO,
+							NULL, 0);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->mgr_pdev);
 
 	ctx->mgr = devm_fpga_mgr_register(&ctx->mgr_pdev->dev, "Fake FPGA Manager", &fake_mgr_ops,
 					  &ctx->mgr_stats);
 	KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->mgr));
 
-	ctx->bridge_pdev = platform_device_register_simple("bridge_pdev", PLATFORM_DEVID_AUTO,
+	ctx->bridge_pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO,
 							   NULL, 0);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->bridge_pdev);
 
@@ -163,7 +178,7 @@ static int fpga_region_test_init(struct kunit *test)
 
 	ctx->bridge_stats.enable = true;
 
-	ctx->region_pdev = platform_device_register_simple("region_pdev", PLATFORM_DEVID_AUTO,
+	ctx->region_pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO,
 							   NULL, 0);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->region_pdev);
 
@@ -195,12 +210,13 @@ static void fpga_region_test_exit(struct kunit *test)
 static struct kunit_case fpga_region_test_cases[] = {
 	KUNIT_CASE(fpga_region_test_class_find),
 	KUNIT_CASE(fpga_region_test_program_fpga),
-
 	{}
 };
 
 static struct kunit_suite fpga_region_suite = {
-	.name = "fpga_mgr",
+	.name = "fpga_region",
+	.suite_init = fpga_region_test_suite_init,
+	.suite_exit = fpga_region_test_suite_exit,
 	.init = fpga_region_test_init,
 	.exit = fpga_region_test_exit,
 	.test_cases = fpga_region_test_cases,
-- 
2.41.0


  parent reply	other threads:[~2023-09-29 15:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-29 15:20 [PATCH v2 0/4] fpga: add platform drivers to the FPGA KUnit test suites Marco Pagani
2023-09-29 15:20 ` [PATCH v2 1/4] fpga: add helpers for " Marco Pagani
2023-09-29 15:20 ` [PATCH v2 2/4] fpga: add a platform driver to the FPGA Manager test suite Marco Pagani
2023-09-29 15:20 ` [PATCH v2 3/4] fpga: add a platform driver to the FPGA Bridge " Marco Pagani
2023-09-29 15:20 ` Marco Pagani [this message]
2023-10-07  6:35 ` [PATCH v2 0/4] fpga: add platform drivers to the FPGA KUnit test suites Xu Yilun

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=20230929152057.85047-5-marpagan@redhat.com \
    --to=marpagan@redhat.com \
    --cc=hao.wu@intel.com \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mdf@kernel.org \
    --cc=ruanjinjie@huawei.com \
    --cc=trix@redhat.com \
    --cc=yilun.xu@intel.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;
as well as URLs for NNTP newsgroup(s).