Skip to contentSkip to conversation

usb: typec: tcpm: free log buf memory when remove debug file

PATCH In review [email protected] 2 participants 4 messages Jul 17, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Cc [email protected] # v4.15+
Fixes 4b4e02c83167 ("typec: tcpm: Move out of staging")
---
 drivers/usb/typec/tcpm/tcpm.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +9 -0
index fba32d8..1249d8e 100644
@@ -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
#1 lore raw

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.

Cc [email protected] # v4.15+
Fixes 4b4e02c83167 ("typec: tcpm: Move out of staging")
---
 drivers/usb/typec/tcpm/tcpm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +4 -0
index 1249d8e..86e4552 100644
@@ -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
Reviewed-by on v1 2/2
#2 lore raw

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")
Quoted 20 lines
---
  drivers/usb/typec/tcpm/tcpm.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +4 -0
index 1249d8e..86e4552 100644
@@ -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
Reviewed-by on v1 1/2
#3 lore raw
In reply to [email protected]
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")
Quoted 25 lines
---
  drivers/usb/typec/tcpm/tcpm.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +9 -0
index fba32d8..1249d8e 100644
@@ -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);
  }