diff mbox series

[2/2] usb: typec: tcpm: remove tcpm dir if no children

Message ID 20190717080646.30421-2-jun.li@nxp.com (mailing list archive)
State Mainlined
Commit 12ca7297b8855c0af1848503d37196159b24e6b9
Headers show
Series [1/2] usb: typec: tcpm: free log buf memory when remove debug file | expand

Commit Message

Jun Li July 17, 2019, 8:06 a.m. UTC
From: Li Jun <jun.li@nxp.com>

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>
---
 drivers/usb/typec/tcpm/tcpm.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Guenter Roeck July 17, 2019, 1:33 p.m. UTC | #1
On 7/17/19 1:06 AM, jun.li@nxp.com wrote:
> From: Li Jun <jun.li@nxp.com>
> 
> 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>

> ---
>   drivers/usb/typec/tcpm/tcpm.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 1249d8e..86e4552 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -596,6 +596,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
>
diff mbox series

Patch

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 1249d8e..86e4552 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -596,6 +596,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