ASoC: soc-topology-test: Check return value of kunit_device_register()

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: e57cdff0dd ("ASoC: topology: Replace fake root_device with kunit_device in tests")
Signed-off-by: Amadeusz Sławiński <amade@asmblr.net>
Link: https://patch.msgid.link/20261014200608.118770-4-amade@asmblr.net
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Amadeusz Sławiński 2026-10-14 22:06:03 +02:00 committed by Mark Brown
parent 223ec2a93b
commit 1641c1ba27
No known key found for this signature in database
GPG Key ID: 2FEF73B0B3D03889

View File

@ -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;