]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ASoC: Intel: consistent HDMI codec probing code
authorGuennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Fri, 24 Jan 2020 21:36:25 +0000 (15:36 -0600)
committerMark Brown <broonie@kernel.org>
Mon, 27 Jan 2020 17:52:11 +0000 (17:52 +0000)
Multiple Intel ASoC machine drivers repeat the same pattern in their
.late_probe() methods: they first check whether the common HDMI codec
driver is used, if not, they proceed by linking the legacy HDMI
driver to each HDMI port. While doing that they use some
inconsistent code:

1. after the loop they check, whether the list contained at least one
   element and if not, they return an error. However, the earlier
   code to use the common HDMI driver uses the first element of the
   same list without checking. To fix this we move the check to the
   top of the function.

2. some of those .late_probe() implementations execute code, only
   needed for the common HDMI driver, before checking, whether the
   driver is used. Move the code to after the check.

3. Some of those functions also perform a redundant initialisation of
   the "err" variable.

This patch fixes those issues.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20200124213625.30186-8-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/boards/bxt_da7219_max98357a.c
sound/soc/intel/boards/bxt_rt298.c
sound/soc/intel/boards/cml_rt1011_rt5682.c
sound/soc/intel/boards/glk_rt5682_max98357a.c
sound/soc/intel/boards/sof_rt5682.c

index 33b13f3ca1525863e0776f493926c3fd8a4dd2c0..9177401c37a53db60e0d68454c5904334280da7c 100644 (file)
@@ -617,12 +617,15 @@ static int bxt_card_late_probe(struct snd_soc_card *card)
                snd_soc_dapm_add_routes(&card->dapm, broxton_map,
                                        ARRAY_SIZE(broxton_map));
 
-       pcm = list_first_entry(&ctx->hdmi_pcm_list, struct bxt_hdmi_pcm,
-                              head);
-       component = pcm->codec_dai->component;
+       if (list_empty(&ctx->hdmi_pcm_list))
+               return -EINVAL;
 
-       if (ctx->common_hdmi_codec_drv)
+       if (ctx->common_hdmi_codec_drv) {
+               pcm = list_first_entry(&ctx->hdmi_pcm_list, struct bxt_hdmi_pcm,
+                                      head);
+               component = pcm->codec_dai->component;
                return hda_dsp_hdmi_build_controls(card, component);
+       }
 
        list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
                component = pcm->codec_dai->component;
@@ -643,9 +646,6 @@ static int bxt_card_late_probe(struct snd_soc_card *card)
                i++;
        }
 
-       if (!component)
-               return -EINVAL;
-
        return hdac_hdmi_jack_port_init(component, &card->dapm);
 }
 
index 067a97e7e6a8c23f61f3c42f62f0285a3cc6d689..4b67f261377c25ef4fd89abcfc8707772b3b5f1e 100644 (file)
@@ -529,12 +529,15 @@ static int bxt_card_late_probe(struct snd_soc_card *card)
        int err, i = 0;
        char jack_name[NAME_SIZE];
 
-       pcm = list_first_entry(&ctx->hdmi_pcm_list, struct bxt_hdmi_pcm,
-                              head);
-       component = pcm->codec_dai->component;
+       if (list_empty(&ctx->hdmi_pcm_list))
+               return -EINVAL;
 
-       if (ctx->common_hdmi_codec_drv)
+       if (ctx->common_hdmi_codec_drv) {
+               pcm = list_first_entry(&ctx->hdmi_pcm_list, struct bxt_hdmi_pcm,
+                                      head);
+               component = pcm->codec_dai->component;
                return hda_dsp_hdmi_build_controls(card, component);
+       }
 
        list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
                component = pcm->codec_dai->component;
@@ -555,9 +558,6 @@ static int bxt_card_late_probe(struct snd_soc_card *card)
                i++;
        }
 
-       if (!component)
-               return -EINVAL;
-
        return hdac_hdmi_jack_port_init(component, &card->dapm);
 }
 
index d6efc554898c7edbe3205f9d0a00e7f38ac6937a..dd80d0186a6c3c2787a08e5dd1f3886e917cb075 100644 (file)
@@ -241,12 +241,15 @@ static int sof_card_late_probe(struct snd_soc_card *card)
        struct hdmi_pcm *pcm;
        int ret, i = 0;
 
-       pcm = list_first_entry(&ctx->hdmi_pcm_list, struct hdmi_pcm,
-                              head);
-       component = pcm->codec_dai->component;
+       if (list_empty(&ctx->hdmi_pcm_list))
+               return -EINVAL;
 
-       if (ctx->common_hdmi_codec_drv)
+       if (ctx->common_hdmi_codec_drv) {
+               pcm = list_first_entry(&ctx->hdmi_pcm_list, struct hdmi_pcm,
+                                      head);
+               component = pcm->codec_dai->component;
                return hda_dsp_hdmi_build_controls(card, component);
+       }
 
        list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
                component = pcm->codec_dai->component;
@@ -265,8 +268,6 @@ static int sof_card_late_probe(struct snd_soc_card *card)
 
                i++;
        }
-       if (!component)
-               return -EINVAL;
 
        return hdac_hdmi_jack_port_init(component, &card->dapm);
 }
index 4a6d117ea7af766d5dbcf1fb3132a6a3cb5ae507..8e947bad143c86543cc9a941374b814225707054 100644 (file)
@@ -534,15 +534,18 @@ static int glk_card_late_probe(struct snd_soc_card *card)
        struct snd_soc_component *component = NULL;
        char jack_name[NAME_SIZE];
        struct glk_hdmi_pcm *pcm;
-       int err = 0;
+       int err;
        int i = 0;
 
-       pcm = list_first_entry(&ctx->hdmi_pcm_list, struct glk_hdmi_pcm,
-                              head);
-       component = pcm->codec_dai->component;
+       if (list_empty(&ctx->hdmi_pcm_list))
+               return -EINVAL;
 
-       if (ctx->common_hdmi_codec_drv)
+       if (ctx->common_hdmi_codec_drv) {
+               pcm = list_first_entry(&ctx->hdmi_pcm_list, struct glk_hdmi_pcm,
+                                      head);
+               component = pcm->codec_dai->component;
                return hda_dsp_hdmi_build_controls(card, component);
+       }
 
        list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
                component = pcm->codec_dai->component;
@@ -563,9 +566,6 @@ static int glk_card_late_probe(struct snd_soc_card *card)
                i++;
        }
 
-       if (!component)
-               return -EINVAL;
-
        return hdac_hdmi_jack_port_init(component, &card->dapm);
 }
 
index 8a13231dee15d494e6173902fce72ac1efe81c99..5d878873a8e08535f7af1f97ed40b25fe5b64540 100644 (file)
@@ -273,19 +273,22 @@ static int sof_card_late_probe(struct snd_soc_card *card)
        struct snd_soc_component *component = NULL;
        char jack_name[NAME_SIZE];
        struct sof_hdmi_pcm *pcm;
-       int err = 0;
+       int err;
        int i = 0;
 
        /* HDMI is not supported by SOF on Baytrail/CherryTrail */
        if (is_legacy_cpu)
                return 0;
 
-       pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm,
-                              head);
-       component = pcm->codec_dai->component;
+       if (list_empty(&ctx->hdmi_pcm_list))
+               return -EINVAL;
 
-       if (ctx->common_hdmi_codec_drv)
+       if (ctx->common_hdmi_codec_drv) {
+               pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm,
+                                      head);
+               component = pcm->codec_dai->component;
                return hda_dsp_hdmi_build_controls(card, component);
+       }
 
        list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
                component = pcm->codec_dai->component;
@@ -305,8 +308,6 @@ static int sof_card_late_probe(struct snd_soc_card *card)
 
                i++;
        }
-       if (!component)
-               return -EINVAL;
 
        return hdac_hdmi_jack_port_init(component, &card->dapm);
 }