]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
usb: typec: tcpm: remove tcpm dir if no children
authorLi Jun <jun.li@nxp.com>
Wed, 17 Jul 2019 08:06:46 +0000 (16:06 +0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 17 Sep 2019 16:02:18 +0000 (18:02 +0200)
BugLink: https://bugs.launchpad.net/bugs/1840520
commit 12ca7297b8855c0af1848503d37196159b24e6b9 upstream.

If config tcpm as module, module unload will not remove tcpm dir,
then the next module load will have problem: the rootdir is NULL
but tcpm dir is still there, so tcpm_debugfs_init() will create
tcpm dir again with failure, fix it by remove the tcpm dir if no
children.

Cc: stable@vger.kernel.org # v4.15+
Fixes: 4b4e02c83167 ("typec: tcpm: Move out of staging")
Signed-off-by: Li Jun <jun.li@nxp.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20190717080646.30421-2-jun.li@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/usb/typec/tcpm.c

index 94bcbbde5fc29ce1e8e8ef4aba22b8898065f78a..e9810bed5be2fd9a336eb70e56dcae3da36f2d14 100644 (file)
@@ -565,6 +565,10 @@ static void tcpm_debugfs_exit(struct tcpm_port *port)
        mutex_unlock(&port->logbuffer_lock);
 
        debugfs_remove(port->dentry);
+       if (list_empty(&rootdir->d_subdirs)) {
+               debugfs_remove(rootdir);
+               rootdir = NULL;
+       }
 }
 
 #else