OSDN Git Service

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 33b13f3..9177401 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 067a97e..4b67f26 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 d6efc55..dd80d01 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 4a6d117..8e947ba 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 8a13231..5d87887 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);
 }