Merge tag 'for-4.17-part2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave...
[sfrench/cifs-2.6.git] / sound / soc / soc-core.c
index 96c44f6576c95f4dfae19547414040e2d2153235..bf7ca32ab31fca97758ac25e2607fa57619c1976 100644 (file)
@@ -221,14 +221,14 @@ static const struct attribute_group soc_dapm_dev_group = {
        .is_visible = soc_dev_attr_is_visible,
 };
 
-static const struct attribute_group soc_dev_roup = {
+static const struct attribute_group soc_dev_group = {
        .attrs = soc_dev_attrs,
        .is_visible = soc_dev_attr_is_visible,
 };
 
 static const struct attribute_group *soc_dev_attr_groups[] = {
        &soc_dapm_dev_group,
-       &soc_dev_roup,
+       &soc_dev_group,
        NULL
 };
 
@@ -349,7 +349,7 @@ static void soc_init_codec_debugfs(struct snd_soc_component *component)
                        "ASoC: Failed to create codec register debugfs file\n");
 }
 
-static int codec_list_seq_show(struct seq_file *m, void *v)
+static int codec_list_show(struct seq_file *m, void *v)
 {
        struct snd_soc_codec *codec;
 
@@ -362,20 +362,9 @@ static int codec_list_seq_show(struct seq_file *m, void *v)
 
        return 0;
 }
+DEFINE_SHOW_ATTRIBUTE(codec_list);
 
-static int codec_list_seq_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, codec_list_seq_show, NULL);
-}
-
-static const struct file_operations codec_list_fops = {
-       .open = codec_list_seq_open,
-       .read = seq_read,
-       .llseek = seq_lseek,
-       .release = single_release,
-};
-
-static int dai_list_seq_show(struct seq_file *m, void *v)
+static int dai_list_show(struct seq_file *m, void *v)
 {
        struct snd_soc_component *component;
        struct snd_soc_dai *dai;
@@ -390,20 +379,9 @@ static int dai_list_seq_show(struct seq_file *m, void *v)
 
        return 0;
 }
+DEFINE_SHOW_ATTRIBUTE(dai_list);
 
-static int dai_list_seq_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, dai_list_seq_show, NULL);
-}
-
-static const struct file_operations dai_list_fops = {
-       .open = dai_list_seq_open,
-       .read = seq_read,
-       .llseek = seq_lseek,
-       .release = single_release,
-};
-
-static int platform_list_seq_show(struct seq_file *m, void *v)
+static int platform_list_show(struct seq_file *m, void *v)
 {
        struct snd_soc_platform *platform;
 
@@ -416,18 +394,7 @@ static int platform_list_seq_show(struct seq_file *m, void *v)
 
        return 0;
 }
-
-static int platform_list_seq_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, platform_list_seq_show, NULL);
-}
-
-static const struct file_operations platform_list_fops = {
-       .open = platform_list_seq_open,
-       .read = seq_read,
-       .llseek = seq_lseek,
-       .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(platform_list);
 
 static void soc_init_card_debugfs(struct snd_soc_card *card)
 {
@@ -1100,8 +1067,8 @@ static int soc_bind_dai_link(struct snd_soc_card *card,
        cpu_dai_component.dai_name = dai_link->cpu_dai_name;
        rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component);
        if (!rtd->cpu_dai) {
-               dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
-                       dai_link->cpu_dai_name);
+               dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
+                        dai_link->cpu_dai_name);
                goto _err_defer;
        }
        snd_soc_rtdcom_add(rtd, rtd->cpu_dai->component);
@@ -1162,11 +1129,6 @@ static int soc_bind_dai_link(struct snd_soc_card *card,
 
                rtd->platform = platform;
        }
-       if (!rtd->platform) {
-               dev_err(card->dev, "ASoC: platform %s not registered\n",
-                       dai_link->platform_name);
-               goto _err_defer;
-       }
 
        soc_add_pcm_runtime(card, rtd);
        return 0;
@@ -1624,22 +1586,21 @@ static int soc_probe_link_components(struct snd_soc_card *card,
 
 static int soc_probe_dai(struct snd_soc_dai *dai, int order)
 {
-       int ret;
+       if (dai->probed ||
+           dai->driver->probe_order != order)
+               return 0;
 
-       if (!dai->probed && dai->driver->probe_order == order) {
-               if (dai->driver->probe) {
-                       ret = dai->driver->probe(dai);
-                       if (ret < 0) {
-                               dev_err(dai->dev,
-                                       "ASoC: failed to probe DAI %s: %d\n",
-                                       dai->name, ret);
-                               return ret;
-                       }
+       if (dai->driver->probe) {
+               int ret = dai->driver->probe(dai);
+               if (ret < 0) {
+                       dev_err(dai->dev, "ASoC: failed to probe DAI %s: %d\n",
+                               dai->name, ret);
+                       return ret;
                }
-
-               dai->probed = 1;
        }
 
+       dai->probed = 1;
+
        return 0;
 }
 
@@ -3459,7 +3420,6 @@ int snd_soc_add_component(struct device *dev,
 err_cleanup:
        snd_soc_component_cleanup(component);
 err_free:
-       kfree(component);
        return ret;
 }
 EXPORT_SYMBOL_GPL(snd_soc_add_component);
@@ -3471,7 +3431,7 @@ int snd_soc_register_component(struct device *dev,
 {
        struct snd_soc_component *component;
 
-       component = kzalloc(sizeof(*component), GFP_KERNEL);
+       component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
        if (!component)
                return -ENOMEM;
 
@@ -3506,7 +3466,6 @@ static int __snd_soc_unregister_component(struct device *dev)
 
        if (found) {
                snd_soc_component_cleanup(component);
-               kfree(component);
        }
 
        return found;
@@ -4397,6 +4356,26 @@ int snd_soc_of_get_dai_name(struct device_node *of_node,
 }
 EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
 
+/*
+ * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
+ * @dai_link: DAI link
+ *
+ * Dereference device nodes acquired by snd_soc_of_get_dai_link_codecs().
+ */
+void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
+{
+       struct snd_soc_dai_link_component *component = dai_link->codecs;
+       int index;
+
+       for (index = 0; index < dai_link->num_codecs; index++, component++) {
+               if (!component->of_node)
+                       break;
+               of_node_put(component->of_node);
+               component->of_node = NULL;
+       }
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs);
+
 /*
  * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
  * @dev: Card device
@@ -4406,7 +4385,8 @@ EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
  * Builds an array of CODEC DAI components from the DAI link property
  * 'sound-dai'.
  * The array is set in the DAI link and the number of DAIs is set accordingly.
- * The device nodes in the array (of_node) must be dereferenced by the caller.
+ * The device nodes in the array (of_node) must be dereferenced by calling
+ * snd_soc_of_put_dai_link_codecs() on @dai_link.
  *
  * Returns 0 for success
  */
@@ -4454,14 +4434,7 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,
        }
        return 0;
 err:
-       for (index = 0, component = dai_link->codecs;
-            index < dai_link->num_codecs;
-            index++, component++) {
-               if (!component->of_node)
-                       break;
-               of_node_put(component->of_node);
-               component->of_node = NULL;
-       }
+       snd_soc_of_put_dai_link_codecs(dai_link);
        dai_link->codecs = NULL;
        dai_link->num_codecs = 0;
        return ret;