Skip to content

Commit a8cad4a

Browse files
Dan Carpenterbroonie
authored andcommitted
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: ef7784e ("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>
1 parent 4be7bc2 commit a8cad4a

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

sound/soc/soc-card-test.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,24 @@ static int soc_card_test_case_init(struct kunit *test)
134134

135135
test->priv = priv;
136136

137+
priv->card = kunit_kzalloc(test, sizeof(*priv->card), GFP_KERNEL);
138+
if (!priv->card)
139+
return -ENOMEM;
140+
137141
priv->card_dev = kunit_device_register(test, "sound-soc-card-test");
138142
priv->card_dev = get_device(priv->card_dev);
139143
if (!priv->card_dev)
140144
return -ENODEV;
141145

142-
priv->card = kunit_kzalloc(test, sizeof(*priv->card), GFP_KERNEL);
143-
if (!priv->card)
144-
return -ENOMEM;
145-
146146
priv->card->name = "soc-card-test";
147147
priv->card->dev = priv->card_dev;
148148
priv->card->owner = THIS_MODULE;
149149

150150
ret = snd_soc_register_card(priv->card);
151-
if (!ret)
151+
if (ret) {
152+
put_device(priv->card_dev);
152153
return ret;
154+
}
153155

154156
return 0;
155157
}

0 commit comments

Comments
 (0)