ASoC: sst-haswell-pcm: Alloc state struct in driver probe()
authorLars-Peter Clausen <lars@metafoo.de>
Wed, 20 Aug 2014 11:08:47 +0000 (13:08 +0200)
committerMark Brown <broonie@linaro.org>
Sat, 6 Sep 2014 13:44:33 +0000 (14:44 +0100)
Resource allocations should happen in driver probe callback rather than in
snd_soc_platform probe functions. Especially if the resource is device
managed. The snd_soc_* probe/remove functions are mainly intended to be used
for things that require the component to be already bound to a card.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
sound/soc/intel/sst-haswell-pcm.c

index 61bf6da4bb02211f0c64593e1ba249c38b7701a1..1de0958768578badef0c52a0d5238b5fbc3c9827 100644 (file)
@@ -778,20 +778,11 @@ static const struct snd_soc_dapm_route graph[] = {
 
 static int hsw_pcm_probe(struct snd_soc_platform *platform)
 {
+       struct hsw_priv_data *priv_data = snd_soc_platform_get_drvdata(platform);
        struct sst_pdata *pdata = dev_get_platdata(platform->dev);
-       struct hsw_priv_data *priv_data;
-       struct device *dma_dev;
+       struct device *dma_dev = pdata->dma_dev;
        int i, ret = 0;
 
-       if (!pdata)
-               return -ENODEV;
-
-       dma_dev = pdata->dma_dev;
-
-       priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data), GFP_KERNEL);
-       priv_data->hsw = pdata->dsp;
-       snd_soc_platform_set_drvdata(platform, priv_data);
-
        /* allocate DSP buffer page tables */
        for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
 
@@ -863,12 +854,23 @@ static const struct snd_soc_component_driver hsw_dai_component = {
 static int hsw_pcm_dev_probe(struct platform_device *pdev)
 {
        struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
+       struct hsw_priv_data *priv_data;
        int ret;
 
+       if (!sst_pdata)
+               return -EINVAL;
+
+       priv_data = devm_kzalloc(&pdev->dev, sizeof(*priv_data), GFP_KERNEL);
+       if (!priv_data)
+               return -ENOMEM;
+
        ret = sst_hsw_dsp_init(&pdev->dev, sst_pdata);
        if (ret < 0)
                return -ENODEV;
 
+       priv_data->hsw = sst_pdata->dsp;
+       platform_set_drvdata(pdev, priv_data);
+
        ret = snd_soc_register_platform(&pdev->dev, &hsw_soc_platform);
        if (ret < 0)
                goto err_plat;