2023-09-30 05:35:58

by Marco Pagani

[permalink] [raw]
Subject: [PATCH v2 0/4] fpga: add platform drivers to the FPGA KUnit test suites

Add and register minimal platform drivers associated with parent
platform devices used for testing to prevent a null-ptr-deref when
try_module_get() is called.

v2:
- Renamed include guard symbol in fpga-test-helpers.h

Marco Pagani (4):
fpga: add helpers for the FPGA KUnit test suites.
fpga: add a platform driver to the FPGA Manager test suite
fpga: add a platform driver to the FPGA Bridge test suite
fpga: add a platform driver to the FPGA Region test suite

drivers/fpga/tests/fpga-bridge-test.c | 18 +++++++++++++++-
drivers/fpga/tests/fpga-mgr-test.c | 18 +++++++++++++++-
drivers/fpga/tests/fpga-region-test.c | 26 ++++++++++++++++++-----
drivers/fpga/tests/fpga-test-helpers.h | 29 ++++++++++++++++++++++++++
4 files changed, 84 insertions(+), 7 deletions(-)
create mode 100644 drivers/fpga/tests/fpga-test-helpers.h


base-commit: 6465e260f48790807eef06b583b38ca9789b6072
--
2.41.0


2023-10-05 17:05:15

by Marco Pagani

[permalink] [raw]
Subject: [PATCH v2 2/4] fpga: add a platform driver to the FPGA Manager test suite

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_mgr_get().

Fixes: ccbc1c302115 ("fpga: add an initial KUnit suite for the FPGA Manager")
Reported-by: Jinjie Ruan <[email protected]>
Signed-off-by: Marco Pagani <[email protected]>
---
drivers/fpga/tests/fpga-mgr-test.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/fpga/tests/fpga-mgr-test.c b/drivers/fpga/tests/fpga-mgr-test.c
index 6acec55b60ce..30de474d7def 100644
--- a/drivers/fpga/tests/fpga-mgr-test.c
+++ b/drivers/fpga/tests/fpga-mgr-test.c
@@ -14,6 +14,8 @@
#include <linux/scatterlist.h>
#include <linux/types.h>

+#include "fpga-test-helpers.h"
+
#define HEADER_FILL 'H'
#define IMAGE_FILL 'P'
#define IMAGE_BLOCK 1024
@@ -277,6 +279,18 @@ static void fpga_mgr_test_img_load_sgt(struct kunit *test)
sg_free_table(ctx->img_info->sgt);
}

+TEST_PLATFORM_DRIVER(test_platform_driver);
+
+static int fpga_mgr_test_suite_init(struct kunit_suite *suite)
+{
+ return platform_driver_register(&test_platform_driver);
+}
+
+static void fpga_mgr_test_suite_exit(struct kunit_suite *suite)
+{
+ platform_driver_unregister(&test_platform_driver);
+}
+
static int fpga_mgr_test_init(struct kunit *test)
{
struct mgr_ctx *ctx;
@@ -284,7 +298,7 @@ static int fpga_mgr_test_init(struct kunit *test)
ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);

- ctx->pdev = platform_device_register_simple("mgr_pdev", PLATFORM_DEVID_AUTO, NULL, 0);
+ ctx->pdev = platform_device_register_simple(TEST_PDEV_NAME, PLATFORM_DEVID_AUTO, NULL, 0);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev);

ctx->mgr = devm_fpga_mgr_register(&ctx->pdev->dev, "Fake FPGA Manager", &fake_mgr_ops,
@@ -317,6 +331,8 @@ static struct kunit_case fpga_mgr_test_cases[] = {

static struct kunit_suite fpga_mgr_suite = {
.name = "fpga_mgr",
+ .suite_init = fpga_mgr_test_suite_init,
+ .suite_exit = fpga_mgr_test_suite_exit,
.init = fpga_mgr_test_init,
.exit = fpga_mgr_test_exit,
.test_cases = fpga_mgr_test_cases,
--
2.41.0

2023-10-07 06:36:34

by Xu Yilun

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] fpga: add platform drivers to the FPGA KUnit test suites

On Fri, Sep 29, 2023 at 05:20:53PM +0200, Marco Pagani wrote:
> Add and register minimal platform drivers associated with parent
> platform devices used for testing to prevent a null-ptr-deref when
> try_module_get() is called.
>
> v2:
> - Renamed include guard symbol in fpga-test-helpers.h
>
> Marco Pagani (4):
> fpga: add helpers for the FPGA KUnit test suites.
> fpga: add a platform driver to the FPGA Manager test suite

I added the Closes tag and applied the series.

Thanks,
Yilun

> fpga: add a platform driver to the FPGA Bridge test suite
> fpga: add a platform driver to the FPGA Region test suite
>
> drivers/fpga/tests/fpga-bridge-test.c | 18 +++++++++++++++-
> drivers/fpga/tests/fpga-mgr-test.c | 18 +++++++++++++++-
> drivers/fpga/tests/fpga-region-test.c | 26 ++++++++++++++++++-----
> drivers/fpga/tests/fpga-test-helpers.h | 29 ++++++++++++++++++++++++++
> 4 files changed, 84 insertions(+), 7 deletions(-)
> create mode 100644 drivers/fpga/tests/fpga-test-helpers.h
>
>
> base-commit: 6465e260f48790807eef06b583b38ca9789b6072
> --
> 2.41.0
>