Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: soc-card: soc-card-test: Fix some error handling in init()

There are two issues here:
1) The get_device() needs a matching put_device() on error paths.
2) The "if (!ret)" was supposed to be "if (ret)".

I re-arranged the code a bit to do the allocation before the
get_device().

Fixes: ef7784e41db7 ("ASoC: soc-card: Add KUnit test case for snd_soc_card_get_kcontrol")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://lore.kernel.org/r/450dd21a-b24b-48ba-9aa4-c02e4617852f@moroto.mountain
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Dan Carpenter and committed by
Mark Brown
a8cad4a4 4be7bc27

+7 -5
+7 -5
sound/soc/soc-card-test.c
··· 134 134 135 135 test->priv = priv; 136 136 137 + priv->card = kunit_kzalloc(test, sizeof(*priv->card), GFP_KERNEL); 138 + if (!priv->card) 139 + return -ENOMEM; 140 + 137 141 priv->card_dev = kunit_device_register(test, "sound-soc-card-test"); 138 142 priv->card_dev = get_device(priv->card_dev); 139 143 if (!priv->card_dev) 140 144 return -ENODEV; 141 - 142 - priv->card = kunit_kzalloc(test, sizeof(*priv->card), GFP_KERNEL); 143 - if (!priv->card) 144 - return -ENOMEM; 145 145 146 146 priv->card->name = "soc-card-test"; 147 147 priv->card->dev = priv->card_dev; 148 148 priv->card->owner = THIS_MODULE; 149 149 150 150 ret = snd_soc_register_card(priv->card); 151 - if (!ret) 151 + if (ret) { 152 + put_device(priv->card_dev); 152 153 return ret; 154 + } 153 155 154 156 return 0; 155 157 }