workflows.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Documentation: kunit: Fix kunit_device_register() example
@ 2025-10-15 13:46 Robin Murphy
  2025-10-16 17:44 ` Robin Murphy
  0 siblings, 1 reply; 3+ messages in thread
From: Robin Murphy @ 2025-10-15 13:46 UTC (permalink / raw)
  To: brendan.higgins, davidgow, corbet
  Cc: rmoar, linux-kselftest, kunit-dev, linux-doc, workflows

kunit_device_register() only returns error pointers, not NULL.
Furthermore for regular users who aren't testing the KUnit API
itself, errors most likely represent major system failure (e.g. OOM
or sysfs collision) beyond the scope of their own test conditions.
Replace the assert with straightforward error handling for clarity.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
This seemed the logical conclusion by inspection, but please do correct
me if I've misunderstood the intent...
---
 Documentation/dev-tools/kunit/usage.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
index 038f480074fd..3452c739dd44 100644
--- a/Documentation/dev-tools/kunit/usage.rst
+++ b/Documentation/dev-tools/kunit/usage.rst
@@ -873,7 +873,8 @@ For example:
 
 		// Create a fake device.
 		fake_device = kunit_device_register(test, "my_device");
-		KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fake_device)
+		if (IS_ERR(fake_device))
+			return;
 
 		// Pass it to functions which need a device.
 		dev_managed_string = devm_kstrdup(fake_device, "Hello, World!");
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-17  5:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-15 13:46 [PATCH] Documentation: kunit: Fix kunit_device_register() example Robin Murphy
2025-10-16 17:44 ` Robin Murphy
2025-10-17  5:28   ` David Gow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox