usb: typec: tcpm: free log buf memory when remove debug file
Subsystems (3)
PATCH 1/2 usb: typec: tcpm: free log buf memory when remove debug file
From: Li Jun <[email protected]>
The logbuffer memory should be freed when remove debug file.
--- drivers/usb/typec/tcpm/tcpm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +9 -0
@@ -586,6 +586,15 @@ static void tcpm_debugfs_init(struct tcpm_port *port)static void tcpm_debugfs_exit (struct tcpm_port *port) { +int i; + +mutex_lock (&port->logbuffer_lock); +for (i =0 ; i <LOG_BUFFER_ENTRIES ; i++) { +kfree (port->logbuffer[i]); + port->logbuffer[i] =NULL ; + } +mutex_unlock (&port->logbuffer_lock); +debugfs_remove (port->dentry); }
Signature · 1 line
2.7.4
PATCH 2/2 usb: typec: tcpm: remove tcpm dir if no children
From: Li Jun <[email protected]>
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.
--- drivers/usb/typec/tcpm/tcpm.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +4 -0
@@ -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
Signature · 1 line
2.7.4
Re: [PATCH 2/2] usb: typec: tcpm: remove tcpm dir if no children
Quoted 11 lines · On 7/17/19 1:06 AM, [email protected] wrote:
From: Li Jun <[email protected]>
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 [email protected] # v4.15+Fixes 4b4e02c83167 ("typec: tcpm: Move out of staging")Signed-off-by Li Jun <[email protected]>
Quoted 20 lines
--- drivers/usb/typec/tcpm/tcpm.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/typec/tcpm/tcpm.c +4
-0@@ -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
Quoted 7 lines · On 7/17/19 1:06 AM, [email protected] wrote:
From: Li Jun <[email protected]>
The logbuffer memory should be freed when remove debug file.
Cc [email protected] # v4.15+Fixes 4b4e02c83167 ("typec: tcpm: Move out of staging")Signed-off-by Li Jun <[email protected]>
Quoted 25 lines
--- drivers/usb/typec/tcpm/tcpm.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/usb/typec/tcpm/tcpm.c +9
-0@@ -586,6 +586,15 @@ static void tcpm_debugfs_init(struct tcpm_port *port)static void tcpm_debugfs_exit (struct tcpm_port *port) { +int i; + +mutex_lock (&port->logbuffer_lock); +for (i =0 ; i <LOG_BUFFER_ENTRIES ; i++) { +kfree (port->logbuffer[i]); + port->logbuffer[i] =NULL ; + } +mutex_unlock (&port->logbuffer_lock); +debugfs_remove (port->dentry); }