All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] usb: typec: tcpm: free log buf memory when remove debug file
@ 2019-07-17  8:06 jun.li
  2019-07-17  8:06 ` [PATCH 2/2] usb: typec: tcpm: remove tcpm dir if no children jun.li
  2019-07-17 13:32 ` [PATCH 1/2] usb: typec: tcpm: free log buf memory when remove debug file Guenter Roeck
  0 siblings, 2 replies; 4+ messages in thread
From: jun.li @ 2019-07-17  8:06 UTC (permalink / raw)
  To: linux, heikki.krogerus; +Cc: gregkh, linux-usb, linux-imx

From: Li Jun <jun.li@nxp.com>

The logbuffer memory should be freed when remove debug file.

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 | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index fba32d8..1249d8e 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -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);
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] usb: typec: tcpm: remove tcpm dir if no children
  2019-07-17  8:06 [PATCH 1/2] usb: typec: tcpm: free log buf memory when remove debug file jun.li
@ 2019-07-17  8:06 ` jun.li
  2019-07-17 13:33   ` Guenter Roeck
  2019-07-17 13:32 ` [PATCH 1/2] usb: typec: tcpm: free log buf memory when remove debug file Guenter Roeck
  1 sibling, 1 reply; 4+ messages in thread
From: jun.li @ 2019-07-17  8:06 UTC (permalink / raw)
  To: linux, heikki.krogerus; +Cc: gregkh, linux-usb, linux-imx

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(+)

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
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] usb: typec: tcpm: free log buf memory when remove debug file
  2019-07-17  8:06 [PATCH 1/2] usb: typec: tcpm: free log buf memory when remove debug file jun.li
  2019-07-17  8:06 ` [PATCH 2/2] usb: typec: tcpm: remove tcpm dir if no children jun.li
@ 2019-07-17 13:32 ` Guenter Roeck
  1 sibling, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2019-07-17 13:32 UTC (permalink / raw)
  To: jun.li, heikki.krogerus; +Cc: gregkh, linux-usb, linux-imx

On 7/17/19 1:06 AM, jun.li@nxp.com wrote:
> From: Li Jun <jun.li@nxp.com>
> 
> The logbuffer memory should be freed when remove debug file.
> 
> 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 | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index fba32d8..1249d8e 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -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);
>   }
>   
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] usb: typec: tcpm: remove tcpm dir if no children
  2019-07-17  8:06 ` [PATCH 2/2] usb: typec: tcpm: remove tcpm dir if no children jun.li
@ 2019-07-17 13:33   ` Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2019-07-17 13:33 UTC (permalink / raw)
  To: jun.li, heikki.krogerus; +Cc: gregkh, linux-usb, linux-imx

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
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-17 13:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17  8:06 [PATCH 1/2] usb: typec: tcpm: free log buf memory when remove debug file jun.li
2019-07-17  8:06 ` [PATCH 2/2] usb: typec: tcpm: remove tcpm dir if no children jun.li
2019-07-17 13:33   ` Guenter Roeck
2019-07-17 13:32 ` [PATCH 1/2] usb: typec: tcpm: free log buf memory when remove debug file Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.