.../coresight/coresight-kunit-tests.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
kunit_device_register() returns an error pointer when device setup fails,
and the devm allocations can return NULL. test_default_sink() currently
uses all three results unconditionally, so setup failures are reported as
unrelated crashes.
Assert that device registration and both allocations succeeded before
constructing the test topology. Fatal KUnit assertions stop the test while
the managed resources are released during cleanup.
Fixes: b104a941a94e ("coresight: Add a KUnit test for coresight_find_default_sink()")
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
.../coresight/coresight-kunit-tests.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-kunit-tests.c b/drivers/hwtracing/coresight/coresight-kunit-tests.c
index c8f361767c45..a4e55bc9dc4c 100644
--- a/drivers/hwtracing/coresight/coresight-kunit-tests.c
+++ b/drivers/hwtracing/coresight/coresight-kunit-tests.c
@@ -6,14 +6,18 @@
#include "coresight-priv.h"
-static struct coresight_device *coresight_test_device(struct device *dev)
+static struct coresight_device *coresight_test_device(struct kunit *test,
+ struct device *dev)
{
struct coresight_device *csdev = devm_kcalloc(dev, 1,
sizeof(struct coresight_device),
GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, csdev);
+
csdev->pdata = devm_kcalloc(dev, 1,
sizeof(struct coresight_platform_data),
GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, csdev->pdata);
return csdev;
}
@@ -25,12 +29,16 @@ static void test_default_sink(struct kunit *test)
* | default
*/
struct device *dev = kunit_device_register(test, "coresight_kunit");
- struct coresight_device *src = coresight_test_device(dev),
- *etf = coresight_test_device(dev),
- *etr = coresight_test_device(dev),
- *catu = coresight_test_device(dev);
+ struct coresight_device *src, *etf, *etr, *catu;
struct coresight_connection conn = {};
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+
+ src = coresight_test_device(test, dev);
+ etf = coresight_test_device(test, dev);
+ etr = coresight_test_device(test, dev);
+ catu = coresight_test_device(test, dev);
+
src->type = CORESIGHT_DEV_TYPE_SOURCE;
/*
* Don't use CORESIGHT_DEV_SUBTYPE_SOURCE_PROC, that would always return
--
2.25.1
© 2016 - 2026 Red Hat, Inc.