[2] crypto: ccp - Provide a roll-back method for debugfs setup
diff mbox

Message ID 149857183214.26572.8412877312728402721.stgit@sosxen.amd.com
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Gary R Hook June 27, 2017, 1:57 p.m. UTC
Changes since v1:
 - Remove unneeded local variable

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/ccp-debugfs.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Comments

Gary R Hook June 27, 2017, 2 p.m. UTC | #1
On 06/27/2017 08:57 AM, Hook, Gary wrote:
> Changes since v1:
>  - Remove unneeded local variable

My apologies for this patch... Pretty sure that the first version won't pass
review anyway because of this.

>
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  drivers/crypto/ccp/ccp-debugfs.c |   17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/crypto/ccp/ccp-debugfs.c
> b/drivers/crypto/ccp/ccp-debugfs.c
> index 3cd6c83754e0..88191c45ca7d 100644
> --- a/drivers/crypto/ccp/ccp-debugfs.c
> +++ b/drivers/crypto/ccp/ccp-debugfs.c
> @@ -305,19 +305,19 @@ void ccp5_debugfs_setup(struct ccp_device *ccp)
>
>          ccp->debugfs_instance = debugfs_create_dir(ccp->name,
> ccp_debugfs_dir);
>          if (!ccp->debugfs_instance)
> -               return;
> +               goto err;
>
>          debugfs_info = debugfs_create_file("info", 0400,
>                                             ccp->debugfs_instance, ccp,
>                                             &ccp_debugfs_info_ops);
>          if (!debugfs_info)
> -               return;
> +               goto err;
>
>          debugfs_stats = debugfs_create_file("stats", 0600,
>                                              ccp->debugfs_instance, ccp,
>                                              &ccp_debugfs_stats_ops);
>          if (!debugfs_stats)
> -               return;
> +               goto err;
>
>          for (i = 0; i < ccp->cmd_q_count; i++) {
>                  cmd_q = &ccp->cmd_q[i];
> @@ -327,15 +327,22 @@ void ccp5_debugfs_setup(struct ccp_device *ccp)
>                  debugfs_q_instance =
>                          debugfs_create_dir(name, ccp->debugfs_instance);
>                  if (!debugfs_q_instance)
> -                       return;
> +                       goto err;
>
>                  debugfs_q_stats =
>                          debugfs_create_file("stats", 0600,
>                                              debugfs_q_instance, cmd_q,
>                                              &ccp_debugfs_queue_ops);
>                  if (!debugfs_q_stats)
> -                       return;
> +                       goto err;
>          }
> +       return;
> +
> +err:
> +       write_lock_irqsave(&ccp_debugfs_lock, flags);
> +       debugfs_remove_recursive(ccp_debugfs_dir);
> +       ccp_debugfs_dir = NULL;
> +       write_unlock_irqrestore(&ccp_debugfs_lock, flags);
>  }
>
>  void ccp5_debugfs_destroy(void)
>
Tom Lendacky June 27, 2017, 2:47 p.m. UTC | #2
On 6/27/2017 8:57 AM, Gary R Hook wrote:
> Changes since v1:
>   - Remove unneeded local variable
> 
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>   drivers/crypto/ccp/ccp-debugfs.c |   17 ++++++++++++-----
>   1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/ccp-debugfs.c b/drivers/crypto/ccp/ccp-debugfs.c
> index 3cd6c83754e0..88191c45ca7d 100644
> --- a/drivers/crypto/ccp/ccp-debugfs.c
> +++ b/drivers/crypto/ccp/ccp-debugfs.c
> @@ -305,19 +305,19 @@ void ccp5_debugfs_setup(struct ccp_device *ccp)
>   
>   	ccp->debugfs_instance = debugfs_create_dir(ccp->name, ccp_debugfs_dir);
>   	if (!ccp->debugfs_instance)
> -		return;
> +		goto err;
>   
>   	debugfs_info = debugfs_create_file("info", 0400,
>   					   ccp->debugfs_instance, ccp,
>   					   &ccp_debugfs_info_ops);
>   	if (!debugfs_info)
> -		return;
> +		goto err;
>   
>   	debugfs_stats = debugfs_create_file("stats", 0600,
>   					    ccp->debugfs_instance, ccp,
>   					    &ccp_debugfs_stats_ops);
>   	if (!debugfs_stats)
> -		return;
> +		goto err;
>   
>   	for (i = 0; i < ccp->cmd_q_count; i++) {
>   		cmd_q = &ccp->cmd_q[i];
> @@ -327,15 +327,22 @@ void ccp5_debugfs_setup(struct ccp_device *ccp)
>   		debugfs_q_instance =
>   			debugfs_create_dir(name, ccp->debugfs_instance);
>   		if (!debugfs_q_instance)
> -			return;
> +			goto err;
>   
>   		debugfs_q_stats =
>   			debugfs_create_file("stats", 0600,
>   					    debugfs_q_instance, cmd_q,
>   					    &ccp_debugfs_queue_ops);
>   		if (!debugfs_q_stats)
> -			return;
> +			goto err;
>   	}
> +	return;
> +
> +err:
> +	write_lock_irqsave(&ccp_debugfs_lock, flags);
> +	debugfs_remove_recursive(ccp_debugfs_dir);

This is removing the whole debugfs directory structure. Did you want to
do that or just the directory entry for this instance?  If you want the
whole directory structure you should probably hold the debugfs lock the
whole time you're creating entries.

Thanks,
Tom

> +	ccp_debugfs_dir = NULL;
> +	write_unlock_irqrestore(&ccp_debugfs_lock, flags);
>   }
>   
>   void ccp5_debugfs_destroy(void)
>

Patch
diff mbox

diff --git a/drivers/crypto/ccp/ccp-debugfs.c b/drivers/crypto/ccp/ccp-debugfs.c
index 3cd6c83754e0..88191c45ca7d 100644
--- a/drivers/crypto/ccp/ccp-debugfs.c
+++ b/drivers/crypto/ccp/ccp-debugfs.c
@@ -305,19 +305,19 @@  void ccp5_debugfs_setup(struct ccp_device *ccp)
 
 	ccp->debugfs_instance = debugfs_create_dir(ccp->name, ccp_debugfs_dir);
 	if (!ccp->debugfs_instance)
-		return;
+		goto err;
 
 	debugfs_info = debugfs_create_file("info", 0400,
 					   ccp->debugfs_instance, ccp,
 					   &ccp_debugfs_info_ops);
 	if (!debugfs_info)
-		return;
+		goto err;
 
 	debugfs_stats = debugfs_create_file("stats", 0600,
 					    ccp->debugfs_instance, ccp,
 					    &ccp_debugfs_stats_ops);
 	if (!debugfs_stats)
-		return;
+		goto err;
 
 	for (i = 0; i < ccp->cmd_q_count; i++) {
 		cmd_q = &ccp->cmd_q[i];
@@ -327,15 +327,22 @@  void ccp5_debugfs_setup(struct ccp_device *ccp)
 		debugfs_q_instance =
 			debugfs_create_dir(name, ccp->debugfs_instance);
 		if (!debugfs_q_instance)
-			return;
+			goto err;
 
 		debugfs_q_stats =
 			debugfs_create_file("stats", 0600,
 					    debugfs_q_instance, cmd_q,
 					    &ccp_debugfs_queue_ops);
 		if (!debugfs_q_stats)
-			return;
+			goto err;
 	}
+	return;
+
+err:
+	write_lock_irqsave(&ccp_debugfs_lock, flags);
+	debugfs_remove_recursive(ccp_debugfs_dir);
+	ccp_debugfs_dir = NULL;
+	write_unlock_irqrestore(&ccp_debugfs_lock, flags);
 }
 
 void ccp5_debugfs_destroy(void)