ASoC: intel: sof_sdw: Make find_codec_info_dai() return a pointer
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Tue, 26 Mar 2024 16:03:58 +0000 (11:03 -0500)
committerMark Brown <broonie@kernel.org>
Tue, 26 Mar 2024 16:13:22 +0000 (16:13 +0000)
Rather than returning an index simply return a pointer to the
located codec info, this simplifies all the callers which only
want to access the codec info structure. Also remove the inline
specifier the function is fairly large for an inline function,
let the compiler decide. And move the function such that it is
located with the other find_codec_info_*() functions.

Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://msgid.link/r/20240326160429.13560-4-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/boards/sof_sdw.c

index 517ff44de1f0f82fecf19ecb20c73f5aa90d99ef..4bd9f62c48fcc64645f5107a3ef572b16dc7f1b3 100644 (file)
@@ -1090,6 +1090,23 @@ static struct sof_sdw_codec_info *find_codec_info_acpi(const u8 *acpi_id)
        return NULL;
 }
 
+static struct sof_sdw_codec_info *find_codec_info_dai(const char *dai_name,
+                                                     int *dai_index)
+{
+       int i, j;
+
+       for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) {
+               for (j = 0; j < codec_info_list[i].dai_num; j++) {
+                       if (!strcmp(codec_info_list[i].dais[j].dai_name, dai_name)) {
+                               *dai_index = j;
+                               return &codec_info_list[i];
+                       }
+               }
+       }
+
+       return NULL;
+}
+
 /*
  * get BE dailink number and CPU DAI number based on sdw link adr.
  * Since some sdw slaves may be aggregated, the CPU DAI number
@@ -1403,37 +1420,19 @@ static void set_dailink_map(struct snd_soc_dai_link_ch_map *sdw_codec_ch_maps,
        }
 }
 
-static inline int find_codec_info_dai(const char *dai_name, int *dai_index)
-{
-       int i, j;
-
-       for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) {
-               for (j = 0; j < codec_info_list[i].dai_num; j++) {
-                       if (!strcmp(codec_info_list[i].dais[j].dai_name, dai_name)) {
-                               *dai_index = j;
-                               return i;
-                       }
-               }
-       }
-
-       return -EINVAL;
-}
-
 static int sof_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct sof_sdw_codec_info *codec_info;
        struct snd_soc_dai *dai;
-       int codec_index;
        int dai_index;
        int ret;
        int i;
 
        for_each_rtd_codec_dais(rtd, i, dai) {
-               codec_index = find_codec_info_dai(dai->name, &dai_index);
-               if (codec_index < 0)
+               codec_info = find_codec_info_dai(dai->name, &dai_index);
+               if (!codec_info)
                        return -EINVAL;
 
-               codec_info = &codec_info_list[codec_index];
                /*
                 * A codec dai can be connected to different dai links for capture and playback,
                 * but we only need to call the rtd_init function once.