Skip to content

Commit

Permalink
ASoC: qcom: Use devm for resource management
Browse files Browse the repository at this point in the history
Simplify the machine drivers for newer SoCs a bit by using the
devm_* function calls that automatically release the resources
when the driver is removed or when probing fails.

Signed-off-by: Stephan Gerhold <[email protected]>
Tested-by: Srinivas Kandagatla <[email protected]>
Reviewed-by: Srinivas Kandagatla <[email protected]>
Cc: Srinivas Kandagatla <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
stephan-gh authored and broonie committed Jul 24, 2020
1 parent d1e2a97 commit ed3b53e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 61 deletions.
28 changes: 3 additions & 25 deletions sound/soc/qcom/apq8096.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,39 +109,18 @@ static int apq8096_platform_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
int ret;

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

card->dev = dev;
dev_set_drvdata(dev, card);
ret = qcom_snd_parse_of(card);
if (ret)
goto err;
return ret;

apq8096_add_be_ops(card);
ret = snd_soc_register_card(card);
if (ret)
goto err_card_register;

return 0;

err_card_register:
kfree(card->dai_link);
err:
kfree(card);
return ret;
}

static int apq8096_platform_remove(struct platform_device *pdev)
{
struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);

snd_soc_unregister_card(card);
kfree(card->dai_link);
kfree(card);

return 0;
return devm_snd_soc_register_card(dev, card);
}

static const struct of_device_id msm_snd_apq8096_dt_match[] = {
Expand All @@ -153,7 +132,6 @@ MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match);

static struct platform_driver msm_snd_apq8096_driver = {
.probe = apq8096_platform_probe,
.remove = apq8096_platform_remove,
.driver = {
.name = "msm-snd-apq8096",
.of_match_table = msm_snd_apq8096_dt_match,
Expand Down
3 changes: 1 addition & 2 deletions sound/soc/qcom/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
num_links = of_get_child_count(dev->of_node);

/* Allocate the DAI link array */
card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL);
if (!card->dai_link)
return -ENOMEM;

Expand Down Expand Up @@ -143,7 +143,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
of_node_put(cpu);
of_node_put(codec);
of_node_put(platform);
kfree(card->dai_link);
return ret;
}
EXPORT_SYMBOL(qcom_snd_parse_of);
Expand Down
40 changes: 6 additions & 34 deletions sound/soc/qcom/sdm845.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,55 +543,28 @@ static int sdm845_snd_platform_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
int ret;

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

/* Allocate the private data */
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) {
ret = -ENOMEM;
goto data_alloc_fail;
}
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

card->dapm_widgets = sdm845_snd_widgets;
card->num_dapm_widgets = ARRAY_SIZE(sdm845_snd_widgets);
card->dev = dev;
dev_set_drvdata(dev, card);
ret = qcom_snd_parse_of(card);
if (ret)
goto parse_dt_fail;
return ret;

data->card = card;
snd_soc_card_set_drvdata(card, data);

sdm845_add_ops(card);
ret = snd_soc_register_card(card);
if (ret) {
dev_err(dev, "Sound card registration failed\n");
goto register_card_fail;
}
return ret;

register_card_fail:
kfree(card->dai_link);
parse_dt_fail:
kfree(data);
data_alloc_fail:
kfree(card);
return ret;
}

static int sdm845_snd_platform_remove(struct platform_device *pdev)
{
struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);
struct sdm845_snd_data *data = snd_soc_card_get_drvdata(card);

snd_soc_unregister_card(card);
kfree(card->dai_link);
kfree(data);
kfree(card);
return 0;
return devm_snd_soc_register_card(dev, card);
}

static const struct of_device_id sdm845_snd_device_id[] = {
Expand All @@ -604,7 +577,6 @@ MODULE_DEVICE_TABLE(of, sdm845_snd_device_id);

static struct platform_driver sdm845_snd_driver = {
.probe = sdm845_snd_platform_probe,
.remove = sdm845_snd_platform_remove,
.driver = {
.name = "msm-snd-sdm845",
.of_match_table = sdm845_snd_device_id,
Expand Down

0 comments on commit ed3b53e

Please sign in to comment.