ASoC: tegra-alt: cleanup dai link machine utility
Dara Ramesh [Wed, 6 Aug 2014 14:02:02 +0000 (19:02 +0530)]
1. kfree is not required for devm_kzalloc
2. Use devm_kzalloc instead of kzalloc to free
   automatically

Change-Id: I90d9de16b829513a9016992dcfddb4b833e96b78
Signed-off-by: Arun Shamanna Lakshmi <aruns@nvidia.com>
Signed-off-by: Dara Ramesh <dramesh@nvidia.com>
Reviewed-on: http://git-master/r/454038
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Justin Kim (SW-TEGRA) <juskim@nvidia.com>

sound/soc/tegra-alt/tegra_asoc_machine_alt.c
sound/soc/tegra-alt/tegra_asoc_machine_alt.h
sound/soc/tegra-alt/tegra_grenada_alt.c
sound/soc/tegra-alt/tegra_t210ref_mobile_alt.c
sound/soc/tegra-alt/tegra_vcm30t124_alt.c

index a7992cc..25c8db3 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "tegra_asoc_machine_alt.h"
 
+#define MAX_STR_SIZE           20
+
 static struct snd_soc_dai_link *tegra_asoc_machine_links;
 static struct snd_soc_codec_conf *tegra_asoc_codec_conf;
 static const unsigned int *bclk_ratio;
@@ -43,10 +45,6 @@ static const struct snd_soc_pcm_stream tdm_link_params = {
        .channels_max = 8,
 };
 
-static const char * const dai_link_name[] = {"nvidia,dai-link-1",
-       "nvidia,dai-link-2", "nvidia,dai-link-3",
-       "nvidia,dai-link-4", "nvidia,dai-link-5"};
-
 static const char * const bit_format[] = {
        "s8", "u8", "s16_le", "s16_be",
        "u16_le", "u16_be", "s24_le", "s24_be",
@@ -1755,6 +1753,7 @@ struct snd_soc_dai_link *tegra_machine_new_codec_links(
        unsigned int i, j, num_codec_links;
        struct device_node *np = pdev->dev.of_node, *subnp;
        struct snd_soc_pcm_stream *params;
+       char dai_link_name[MAX_STR_SIZE];
        char *str;
        const char *prefix;
 
@@ -1789,14 +1788,16 @@ struct snd_soc_dai_link *tegra_machine_new_codec_links(
 
        /* i is for DAP and j is for CIF */
        for (i = 0, j = num_codec_links; i < num_codec_links; i++, j++) {
-               subnp = of_get_child_by_name(np, dai_link_name[i]);
+               memset((void *)dai_link_name, '\0', MAX_STR_SIZE);
+               sprintf(dai_link_name, "nvidia,dai-link-%d", i+1);
+               subnp = of_get_child_by_name(np, dai_link_name);
                if (subnp) {
                        tegra_codec_links[i].codec_of_node =
                                of_parse_phandle(subnp, "codec-dai", 0);
                        if (!tegra_codec_links[i].codec_of_node) {
                                dev_err(&pdev->dev,
                                        "Property '%s.codec-dai' missing or invalid\n",
-                                       dai_link_name[i]);
+                                       dai_link_name);
                                goto err;
                        }
 
@@ -1805,7 +1806,7 @@ struct snd_soc_dai_link *tegra_machine_new_codec_links(
                        if (!tegra_codec_links[i].cpu_of_node) {
                                dev_err(&pdev->dev,
                                        "Property '%s.cpu-dai' missing or invalid\n",
-                                       dai_link_name[i]);
+                                       dai_link_name);
                                goto err;
                        }
 
@@ -1910,7 +1911,7 @@ struct snd_soc_dai_link *tegra_machine_new_codec_links(
                } else {
                        dev_err(&pdev->dev,
                                "Property '%s' missing or invalid\n",
-                               dai_link_name[i]);
+                               dai_link_name);
                        goto err;
                }
        }
@@ -1923,12 +1924,6 @@ err:
 }
 EXPORT_SYMBOL_GPL(tegra_machine_new_codec_links);
 
-void tegra_machine_remove_new_codec_links(
-       struct snd_soc_dai_link *tegra_codec_links)
-{
-       kfree(tegra_codec_links);
-}
-EXPORT_SYMBOL_GPL(tegra_machine_remove_new_codec_links);
 
 struct snd_soc_codec_conf *tegra_machine_new_codec_conf(
        struct platform_device *pdev,
@@ -1938,6 +1933,7 @@ struct snd_soc_codec_conf *tegra_machine_new_codec_conf(
        unsigned int i, num_codec_links;
        struct device_node *np = pdev->dev.of_node, *subnp;
        const struct device_node *of_node;
+       char dai_link_name[MAX_STR_SIZE];
 
        if (tegra_codec_conf)
                return tegra_codec_conf;
@@ -1952,11 +1948,13 @@ struct snd_soc_codec_conf *tegra_machine_new_codec_conf(
                goto err;
        }
 
-       tegra_codec_conf = kzalloc(num_codec_links *
+       tegra_codec_conf =  devm_kzalloc(&pdev->dev, num_codec_links *
                sizeof(struct snd_soc_codec_conf), GFP_KERNEL);
 
        for (i = 0; i < num_codec_links; i++) {
-               subnp = of_get_child_by_name(np, dai_link_name[i]);
+               memset((void *)dai_link_name, '\0', MAX_STR_SIZE);
+               sprintf(dai_link_name, "nvidia,dai-link-%d", i+1);
+               subnp = of_get_child_by_name(np, dai_link_name);
                if (subnp) {
                        of_node = of_parse_phandle(subnp, "codec-dai", 0);
                        tegra_codec_conf[i].dev_name = of_node->name;
@@ -1975,12 +1973,6 @@ err:
 }
 EXPORT_SYMBOL_GPL(tegra_machine_new_codec_conf);
 
-void tegra_machine_remove_new_codec_conf(
-       struct snd_soc_codec_conf *tegra_codec_conf)
-{
-       kfree(tegra_codec_conf);
-}
-EXPORT_SYMBOL_GPL(tegra_machine_remove_new_codec_conf);
 
 /* This function is valid when dai_link is initiated from the DT */
 unsigned int tegra_machine_get_codec_dai_link_idx(char *of_node_name)
@@ -2041,8 +2033,6 @@ void tegra_machine_remove_extra_mem_alloc(unsigned int num_codec_links)
 {
        int i, j;
 
-       kfree(bclk_ratio);
-
        if (num_dai_links > TEGRA210_XBAR_DAI_LINKS)
                for (i = TEGRA210_XBAR_DAI_LINKS,
                        j = TEGRA210_XBAR_DAI_LINKS+num_codec_links;
index 0bde750..e7f774c 100644 (file)
@@ -247,17 +247,11 @@ struct snd_soc_dai_link *tegra_machine_new_codec_links(
        struct snd_soc_dai_link *tegra_codec_links,
        unsigned int *pnum_codec_links);
 
-void tegra_machine_remove_new_codec_links(
-       struct snd_soc_dai_link *tegra_codec_links);
-
 struct snd_soc_codec_conf *tegra_machine_new_codec_conf(
        struct platform_device *pdev,
        struct snd_soc_codec_conf *tegra_codec_conf,
        unsigned int *pnum_codec_links);
 
-void tegra_machine_remove_new_codec_conf(
-       struct snd_soc_codec_conf *tegra_codec_conf);
-
 unsigned int tegra_machine_get_codec_dai_link_idx(char *of_node_name);
 
 unsigned int tegra_machine_get_bclk_ratio(
index 13dd69e..bef012b 100644 (file)
@@ -394,17 +394,12 @@ static int tegra_grenada_driver_probe(struct platform_device *pdev)
                goto err_alloc_dai_link;
        }
 
-       /* release new codec_links and codec_conf */
-       tegra_machine_remove_new_codec_links(tegra_grenada_codec_links);
-       tegra_machine_remove_new_codec_conf(tegra_grenada_codec_conf);
-
        return 0;
 
 err_alloc_dai_link:
-       tegra_machine_remove_codec_conf();
+       tegra_machine_remove_extra_mem_alloc(machine->num_codec_links);
        tegra_machine_remove_dai_link();
-       tegra_machine_remove_new_codec_links(tegra_grenada_codec_links);
-       tegra_machine_remove_new_codec_conf(tegra_grenada_codec_conf);
+       tegra_machine_remove_codec_conf();
 err:
        return ret;
 }
index cc1d33a..0c6bea6 100644 (file)
@@ -546,8 +546,9 @@ static int tegra_t210ref_driver_probe(struct platform_device *pdev)
                goto err_alloc_dai_link;
 #endif
 
-       pdata = kzalloc(sizeof(struct tegra_asoc_platform_data),
-                       GFP_KERNEL);
+       pdata = devm_kzalloc(&pdev->dev,
+                               sizeof(struct tegra_asoc_platform_data),
+                               GFP_KERNEL);
        if (!pdata) {
                dev_err(&pdev->dev,
                        "Can't allocate tegra_asoc_platform_data struct\n");
@@ -639,17 +640,12 @@ static int tegra_t210ref_driver_probe(struct platform_device *pdev)
                goto err_alloc_dai_link;
        }
 
-       /* release new codec_links and codec_conf */
-       tegra_machine_remove_new_codec_links(tegra_t210ref_codec_links);
-       tegra_machine_remove_new_codec_conf(tegra_t210ref_codec_conf);
-
        return 0;
 
 err_alloc_dai_link:
-       tegra_machine_remove_codec_conf();
+       tegra_machine_remove_extra_mem_alloc(machine->num_codec_links);
        tegra_machine_remove_dai_link();
-       tegra_machine_remove_new_codec_links(tegra_t210ref_codec_links);
-       tegra_machine_remove_new_codec_conf(tegra_t210ref_codec_conf);
+       tegra_machine_remove_codec_conf();
 err:
        return ret;
 }
index 7abdf2d..9e9ae25 100644 (file)
@@ -1030,7 +1030,11 @@ static int tegra_vcm30t124_driver_probe(struct platform_device *pdev)
 
        /* get the xbar dai link/codec conf structure */
        tegra_machine_dai_links = tegra_machine_get_dai_link();
+       if (!tegra_machine_dai_links)
+               goto err_alloc_dai_link;
        tegra_machine_codec_conf = tegra_machine_get_codec_conf();
+       if (!tegra_machine_codec_conf)
+               goto err_alloc_dai_link;
 
        /* set AMX/ADX dai_init */
        tegra_machine_set_dai_init(TEGRA124_DAI_LINK_AMX0,
@@ -1043,26 +1047,56 @@ static int tegra_vcm30t124_driver_probe(struct platform_device *pdev)
                &tegra_vcm30t124_adx1_init);
 
     /* set AMX/ADX params */
-       for (i = 0; i < machine->pdata->num_amx; i++) {
-               tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX0_0,
-                       &machine->pdata->amx_config[i].params[0]);
-               tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX0_1,
-                       &machine->pdata->amx_config[i].params[1]);
-               tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX0_2,
-                       &machine->pdata->amx_config[i].params[2]);
-               tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX0_3,
-                       &machine->pdata->amx_config[i].params[3]);
+       if (machine->pdata->num_amx) {
+               switch (machine->pdata->num_amx) {
+               case 2:
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX1_0,
+                               &machine->pdata->amx_config[1].params[0]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX1_1,
+                               &machine->pdata->amx_config[1].params[1]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX1_2,
+                               &machine->pdata->amx_config[1].params[2]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX1_3,
+                               &machine->pdata->amx_config[1].params[3]);
+               case 1:
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX0_0,
+                               &machine->pdata->amx_config[0].params[0]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX0_1,
+                               &machine->pdata->amx_config[0].params[1]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX0_2,
+                               &machine->pdata->amx_config[0].params[2]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_AMX0_3,
+                               &machine->pdata->amx_config[0].params[3]);
+                       break;
+               default:
+                       break;
+               }
        }
 
-       for (i = 0; i < machine->pdata->num_adx; i++) {
-               tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX0_0,
-                       &machine->pdata->adx_config[i].params[0]);
-               tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX0_1,
-                       &machine->pdata->adx_config[i].params[1]);
-               tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX0_2,
-                       &machine->pdata->adx_config[i].params[2]);
-               tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX0_3,
-                       &machine->pdata->adx_config[i].params[3]);
+       if (machine->pdata->num_adx) {
+               switch (machine->pdata->num_adx) {
+               case 2:
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX1_0,
+                               &machine->pdata->adx_config[1].params[0]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX1_1,
+                               &machine->pdata->adx_config[1].params[1]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX1_2,
+                               &machine->pdata->adx_config[1].params[2]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX1_3,
+                               &machine->pdata->adx_config[1].params[3]);
+               case 1:
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX0_0,
+                               &machine->pdata->adx_config[0].params[0]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX0_1,
+                               &machine->pdata->adx_config[0].params[1]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX0_2,
+                               &machine->pdata->adx_config[0].params[2]);
+                       tegra_machine_set_dai_params(TEGRA124_DAI_LINK_ADX0_3,
+                               &machine->pdata->adx_config[0].params[3]);
+                       break;
+               default:
+                       break;
+               }
        }
 
        /* set DAM dai_init */
@@ -1120,6 +1154,10 @@ static int tegra_vcm30t124_driver_probe(struct platform_device *pdev)
        tegra_machine_codec_conf = tegra_machine_get_codec_conf();
        card->codec_conf = tegra_machine_codec_conf;
 
+       /* remove vcm30t124 specific dai links and conf */
+       tegra_vcm30t124_free_codec_links();
+       tegra_vcm30t124_free_codec_conf();
+
        machine->gpio_dap_direction = GPIO_PR0;
        machine->wm_rate_via_kcontrol = 0;
        machine->ad_rate_via_kcontrol = 0;
@@ -1178,6 +1216,9 @@ err_gpio_free:
 err_i2c_unregister:
        if (machine->max9485_client)
                i2c_unregister_device(machine->max9485_client);
+err_alloc_dai_link:
+       tegra_machine_remove_dai_link();
+       tegra_machine_remove_codec_conf();
 err:
        return ret;
 }
@@ -1187,9 +1228,6 @@ static int tegra_vcm30t124_driver_remove(struct platform_device *pdev)
        struct snd_soc_card *card = platform_get_drvdata(pdev);
        struct tegra_vcm30t124 *machine = snd_soc_card_get_drvdata(card);
 
-       tegra_vcm30t124_free_codec_links();
-       tegra_vcm30t124_free_codec_conf();
-
        snd_soc_unregister_card(card);
 
        tegra_machine_remove_dai_link();