From ec279c75045bf9a729351eebb00e123031d5e52d Mon Sep 17 00:00:00 2001 From: Aditya Bavanari Date: Thu, 22 Nov 2018 15:52:25 +0530 Subject: [PATCH 1/2] asoc: sm6150: Add logic to parse codec_max_aux_devs Add parsing logic for codec_max_aux_devs in init_aux_dev in order to identify whether auxilary codec is supported or not for a target. CRs-Fixed: 2353292 Change-Id: I88a84ab064da50ab243ad3f7d6b61cd03b9bbc77 Signed-off-by: Aditya Bavanari --- asoc/sm6150.c | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/asoc/sm6150.c b/asoc/sm6150.c index 9727dffbbdbf..f71ca2d66ffc 100644 --- a/asoc/sm6150.c +++ b/asoc/sm6150.c @@ -8063,6 +8063,7 @@ static int msm_init_aux_dev(struct platform_device *pdev, struct device_node *aux_codec_of_node; u32 wsa_max_devs; u32 wsa_dev_cnt; + u32 codec_max_aux_devs; u32 codec_aux_dev_cnt = 0; int i; struct msm_wsa881x_dev_info *wsa881x_dev_info = NULL; @@ -8077,14 +8078,14 @@ static int msm_init_aux_dev(struct platform_device *pdev, ret = of_property_read_u32(pdev->dev.of_node, "qcom,wsa-max-devs", &wsa_max_devs); if (ret) { - dev_info(&pdev->dev, + dev_err(&pdev->dev, "%s: wsa-max-devs property missing in DT %s, ret = %d\n", __func__, pdev->dev.of_node->full_name, ret); wsa_max_devs = 0; goto codec_aux_dev; } if (wsa_max_devs == 0) { - dev_warn(&pdev->dev, + dev_dbg(&pdev->dev, "%s: Max WSA devices is 0 for this target?\n", __func__); goto codec_aux_dev; @@ -8179,6 +8180,24 @@ static int msm_init_aux_dev(struct platform_device *pdev, codec_aux_dev: if (strcmp(card->name, "sm6150-tavil-snd-card")) { + /* Get maximum aux codec device count for this platform */ + ret = of_property_read_u32(pdev->dev.of_node, + "qcom,codec-max-aux-devs", + &codec_max_aux_devs); + if (ret) { + dev_err(&pdev->dev, + "%s: codec-max-aux-devs property missing in DT %s, ret = %d\n", + __func__, pdev->dev.of_node->full_name, ret); + codec_max_aux_devs = 0; + goto aux_dev_register; + } + if (codec_max_aux_devs == 0) { + dev_dbg(&pdev->dev, + "%s: Max aux codec devices is 0 for this target?\n", + __func__); + goto aux_dev_register; + } + /* Get count of aux codec device phandles for this platform */ codec_aux_dev_cnt = of_count_phandle_with_args( pdev->dev.of_node, @@ -8195,11 +8214,24 @@ codec_aux_dev: goto err; } + /* + * Expect total phandles count to be NOT less than maximum possible + * AUX device count. However, if it is less, then assign same value to + * max count as well. + */ + if (codec_aux_dev_cnt < codec_max_aux_devs) { + dev_dbg(&pdev->dev, + "%s: codec_max_aux_devs = %d cannot exceed codec_aux_dev_cnt = %d\n", + __func__, codec_max_aux_devs, + codec_aux_dev_cnt); + codec_max_aux_devs = codec_aux_dev_cnt; + } + /* * Alloc mem to store phandle and index info of aux codec * if already registered with ALSA core */ - aux_cdc_dev_info = devm_kcalloc(&pdev->dev, codec_aux_dev_cnt, + aux_cdc_dev_info = devm_kcalloc(&pdev->dev, codec_max_aux_devs, sizeof(struct aux_codec_dev_info), GFP_KERNEL); if (!aux_cdc_dev_info) { @@ -8233,10 +8265,10 @@ codec_aux_dev: } } - if (codecs_found < codec_aux_dev_cnt) { + if (codecs_found < codec_max_aux_devs) { dev_dbg(&pdev->dev, "%s: failed to find %d components. Found only %d\n", - __func__, codec_aux_dev_cnt, codecs_found); + __func__, codec_max_aux_devs, codecs_found); return -EPROBE_DEFER; } dev_info(&pdev->dev, @@ -8245,8 +8277,9 @@ codec_aux_dev: } - card->num_aux_devs = wsa_max_devs + codec_aux_dev_cnt; - card->num_configs = wsa_max_devs + codec_aux_dev_cnt; +aux_dev_register: + card->num_aux_devs = wsa_max_devs + codec_max_aux_devs; + card->num_configs = wsa_max_devs + codec_max_aux_devs; /* Alloc array of AUX devs struct */ msm_aux_dev = devm_kcalloc(&pdev->dev, card->num_aux_devs, @@ -8299,7 +8332,7 @@ codec_aux_dev: } for (i = 0; i < codec_aux_dev_cnt; i++) { - msm_aux_dev[wsa_max_devs + i].name = NULL; + msm_aux_dev[wsa_max_devs + i].name = "aux_codec"; msm_aux_dev[wsa_max_devs + i].codec_name = NULL; msm_aux_dev[wsa_max_devs + i].codec_of_node = aux_cdc_dev_info[i].of_node; From 32b3e5e2d6c057f284ef894cfcb8bf8d4f860732 Mon Sep 17 00:00:00 2001 From: Aditya Bavanari Date: Tue, 4 Dec 2018 17:19:56 +0530 Subject: [PATCH 2/2] asoc: sm6150: Initialize variable in msm_init_aux_dev Initialize codec_max_aux_devs variable in msm_init_aux_dev function to avoid uninitialized variable usage. CRs-Fixed: 2357928 Change-Id: I4806f68dfaa9ea22c244fd6b102d8f0eed5abe0c Signed-off-by: Aditya Bavanari --- asoc/sm6150.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asoc/sm6150.c b/asoc/sm6150.c index f71ca2d66ffc..03b5ba49ccbd 100644 --- a/asoc/sm6150.c +++ b/asoc/sm6150.c @@ -8063,7 +8063,7 @@ static int msm_init_aux_dev(struct platform_device *pdev, struct device_node *aux_codec_of_node; u32 wsa_max_devs; u32 wsa_dev_cnt; - u32 codec_max_aux_devs; + u32 codec_max_aux_devs = 0; u32 codec_aux_dev_cnt = 0; int i; struct msm_wsa881x_dev_info *wsa881x_dev_info = NULL;