[PATCH 3/8] ASoC: soc-topology-test: Check return value of kunit_device_register()
From: Amadeusz Sławiński
Date: Wed Oct 14 2026 - 16:06:58 EST
Call to kunit_device_register() can fail. Check return result of
register call. While at it introduce helper variable so that if it fails
put_device is called on properly initialized variable.
Fixes: e57cdff0ddc4 ("ASoC: topology: Replace fake root_device with kunit_device in tests")
Signed-off-by: Amadeusz Sławiński <amade@xxxxxxxxxx>
---
sound/soc/soc-topology-test.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-topology-test.c b/sound/soc/soc-topology-test.c
index bcfb52061133..8df845a196fe 100644
--- a/sound/soc/soc-topology-test.c
+++ b/sound/soc/soc-topology-test.c
@@ -24,8 +24,12 @@ static struct device *test_dev;
static int snd_soc_tplg_test_init(struct kunit *test)
{
- test_dev = kunit_device_register(test, "sound-soc-topology-test");
- test_dev = get_device(test_dev);
+ struct device *dev;
+
+ dev = kunit_device_register(test, "sound-soc-topology-test");
+ if (IS_ERR(dev))
+ return PTR_ERR(dev);
+ test_dev = get_device(dev);
if (!test_dev)
return -ENODEV;
--
2.56.0