Skip to content

Commit

Permalink
ASoC: sun4i-codec: return error code instead of NULL when create_card…
Browse files Browse the repository at this point in the history
… fails

When sun4i_codec_create_card fails, we do not assign a proper error
code to the return value. The return value would be 0 from the previous
function call, or we would have bailed out sooner. This would confuse
the driver core into thinking the device probe succeeded, when in fact
it didn't, leaving various devres based resources lingering.

Make the create_card function pass back a meaningful error code, and
assign it to the return value.

Fixes: 45fb6b6 ("ASoC: sunxi: add support for the on-chip codec on
		      early Allwinner SoCs")
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Chen-Yu Tsai authored and Mark Brown committed Oct 31, 2016
1 parent 1001354 commit 85915b6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sound/soc/sunxi/sun4i-codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,11 @@ static struct snd_soc_card *sun4i_codec_create_card(struct device *dev)

card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return NULL;
return ERR_PTR(-ENOMEM);

card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
if (!card->dai_link)
return NULL;
return ERR_PTR(-ENOMEM);

card->dev = dev;
card->name = "sun4i-codec";
Expand Down Expand Up @@ -876,7 +876,8 @@ static int sun4i_codec_probe(struct platform_device *pdev)
}

card = sun4i_codec_create_card(&pdev->dev);
if (!card) {
if (IS_ERR(card)) {
ret = PTR_ERR(card);
dev_err(&pdev->dev, "Failed to create our card\n");
goto err_unregister_codec;
}
Expand Down

0 comments on commit 85915b6

Please sign in to comment.