]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ASoC: Don't try to register debugfs entries if the parent does not exist
authorLars-Peter Clausen <lars@metafoo.de>
Thu, 9 Apr 2015 08:52:38 +0000 (10:52 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 9 Apr 2015 11:23:14 +0000 (12:23 +0100)
If the registration of a debugfs directory fails this is treated as a
non-fatal error in ASoC and operation continues as normal. This means we
need to be careful and check if the parent debugfs directory exists if we
try to register a debugfs file or sub-directory. Otherwise we might end up
passing NULL for the parent and the file or directory will be registered in
the top-level debugfs directory.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-core.c
sound/soc/soc-dapm.c
sound/soc/soc-pcm.c

index d29c68ad83c7284e3d064e75d63e29f353eaac45..9dfa2e2418650e346101e88d719ddcb9086ca41c 100644 (file)
@@ -292,6 +292,9 @@ static const struct file_operations codec_reg_fops = {
 
 static void soc_init_component_debugfs(struct snd_soc_component *component)
 {
+       if (!component->card->debugfs_card_root)
+               return;
+
        if (component->debugfs_prefix) {
                char *name;
 
@@ -455,6 +458,9 @@ static const struct file_operations platform_list_fops = {
 
 static void soc_init_card_debugfs(struct snd_soc_card *card)
 {
+       if (!snd_soc_debugfs_root)
+               return;
+
        card->debugfs_card_root = debugfs_create_dir(card->name,
                                                     snd_soc_debugfs_root);
        if (!card->debugfs_card_root) {
@@ -476,6 +482,34 @@ static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
        debugfs_remove_recursive(card->debugfs_card_root);
 }
 
+
+static void snd_soc_debugfs_init(void)
+{
+       snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
+       if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
+               pr_warn("ASoC: Failed to create debugfs directory\n");
+               snd_soc_debugfs_root = NULL;
+               return;
+       }
+
+       if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
+                                &codec_list_fops))
+               pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
+
+       if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
+                                &dai_list_fops))
+               pr_warn("ASoC: Failed to create DAI list debugfs file\n");
+
+       if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
+                                &platform_list_fops))
+               pr_warn("ASoC: Failed to create platform list debugfs file\n");
+}
+
+static void snd_soc_debugfs_exit(void)
+{
+       debugfs_remove_recursive(snd_soc_debugfs_root);
+}
+
 #else
 
 #define soc_init_codec_debugfs NULL
@@ -497,6 +531,15 @@ static inline void soc_init_card_debugfs(struct snd_soc_card *card)
 static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
 {
 }
+
+static inline void snd_soc_debugfs_init(void)
+{
+}
+
+static inline void snd_soc_debugfs_exit(void)
+{
+}
+
 #endif
 
 struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
@@ -3580,26 +3623,7 @@ EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
 
 static int __init snd_soc_init(void)
 {
-#ifdef CONFIG_DEBUG_FS
-       snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
-       if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
-               pr_warn("ASoC: Failed to create debugfs directory\n");
-               snd_soc_debugfs_root = NULL;
-       }
-
-       if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
-                                &codec_list_fops))
-               pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
-
-       if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
-                                &dai_list_fops))
-               pr_warn("ASoC: Failed to create DAI list debugfs file\n");
-
-       if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
-                                &platform_list_fops))
-               pr_warn("ASoC: Failed to create platform list debugfs file\n");
-#endif
-
+       snd_soc_debugfs_init();
        snd_soc_util_init();
 
        return platform_driver_register(&soc_driver);
@@ -3609,9 +3633,9 @@ module_init(snd_soc_init);
 static void __exit snd_soc_exit(void)
 {
        snd_soc_util_exit();
+       snd_soc_debugfs_exit();
 
 #ifdef CONFIG_DEBUG_FS
-       debugfs_remove_recursive(snd_soc_debugfs_root);
 #endif
        platform_driver_unregister(&soc_driver);
 }
index b6f88202b8c99a41c3e941bb8a8a2603e45985a8..1fd2d458824edd1e814d0b91f718ec231667efab 100644 (file)
@@ -1898,6 +1898,9 @@ void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
 {
        struct dentry *d;
 
+       if (!parent)
+               return;
+
        dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
 
        if (!dapm->debugfs_dapm) {
index 9c514fde71542f7bd44809a8c7d1c019013c8123..b0d61e6531e615fb574dd2012f767437af1f3367 100644 (file)
@@ -1097,8 +1097,9 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
                        stream ? "<-" : "->", be->dai_link->name);
 
 #ifdef CONFIG_DEBUG_FS
-       dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644,
-                       fe->debugfs_dpcm_root, &dpcm->state);
+       if (fe->debugfs_dpcm_root)
+               dpcm->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644,
+                               fe->debugfs_dpcm_root, &dpcm->state);
 #endif
        return 1;
 }
@@ -2807,6 +2808,9 @@ void soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
        if (!rtd->dai_link)
                return;
 
+       if (!rtd->card->debugfs_card_root)
+               return;
+
        rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name,
                        rtd->card->debugfs_card_root);
        if (!rtd->debugfs_dpcm_root) {