linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] jbd2: remove the conditional test
@ 2018-02-05 14:24 Wang Long
  2018-02-06 10:22 ` Jan Kara
  2018-05-21  2:41 ` Theodore Y. Ts'o
  0 siblings, 2 replies; 3+ messages in thread
From: Wang Long @ 2018-02-05 14:24 UTC (permalink / raw)
  To: darrick.wong, tytso, jack; +Cc: linux-ext4, linux-kernel

kmem_cache_destroy already handles null pointers, so we can remove the
conditional test entirely.

This patch also set NULL after the kmem_cache_destroy in function
jbd2_journal_destroy_handle_cache.

Signed-off-by: Wang Long <wanglong19@meituan.com>
---
 fs/jbd2/journal.c     | 18 +++++++-----------
 fs/jbd2/revoke.c      | 12 ++++--------
 fs/jbd2/transaction.c |  6 ++----
 3 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 93016bb..3c27a61a 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2286,8 +2286,7 @@ static void jbd2_journal_destroy_slabs(void)
 	int i;
 
 	for (i = 0; i < JBD2_MAX_SLABS; i++) {
-		if (jbd2_slab[i])
-			kmem_cache_destroy(jbd2_slab[i]);
+		kmem_cache_destroy(jbd2_slab[i]);
 		jbd2_slab[i] = NULL;
 	}
 }
@@ -2388,10 +2387,8 @@ static int jbd2_journal_init_journal_head_cache(void)
 
 static void jbd2_journal_destroy_journal_head_cache(void)
 {
-	if (jbd2_journal_head_cache) {
-		kmem_cache_destroy(jbd2_journal_head_cache);
-		jbd2_journal_head_cache = NULL;
-	}
+	kmem_cache_destroy(jbd2_journal_head_cache);
+	jbd2_journal_head_cache = NULL;
 }
 
 /*
@@ -2649,11 +2646,10 @@ static int __init jbd2_journal_init_handle_cache(void)
 
 static void jbd2_journal_destroy_handle_cache(void)
 {
-	if (jbd2_handle_cache)
-		kmem_cache_destroy(jbd2_handle_cache);
-	if (jbd2_inode_cache)
-		kmem_cache_destroy(jbd2_inode_cache);
-
+	kmem_cache_destroy(jbd2_handle_cache);
+	jbd2_handle_cache = NULL;
+	kmem_cache_destroy(jbd2_inode_cache);
+	jbd2_inode_cache = NULL;
 }
 
 /*
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index 696ef15..240779e 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -180,14 +180,10 @@ static struct jbd2_revoke_record_s *find_revoke_record(journal_t *journal,
 
 void jbd2_journal_destroy_revoke_caches(void)
 {
-	if (jbd2_revoke_record_cache) {
-		kmem_cache_destroy(jbd2_revoke_record_cache);
-		jbd2_revoke_record_cache = NULL;
-	}
-	if (jbd2_revoke_table_cache) {
-		kmem_cache_destroy(jbd2_revoke_table_cache);
-		jbd2_revoke_table_cache = NULL;
-	}
+	kmem_cache_destroy(jbd2_revoke_record_cache);
+	jbd2_revoke_record_cache = NULL;
+	kmem_cache_destroy(jbd2_revoke_table_cache);
+	jbd2_revoke_table_cache = NULL;
 }
 
 int __init jbd2_journal_init_revoke_caches(void)
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index ac31103..3b642e0 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -49,10 +49,8 @@ int __init jbd2_journal_init_transaction_cache(void)
 
 void jbd2_journal_destroy_transaction_cache(void)
 {
-	if (transaction_cache) {
-		kmem_cache_destroy(transaction_cache);
-		transaction_cache = NULL;
-	}
+	kmem_cache_destroy(transaction_cache);
+	transaction_cache = NULL;
 }
 
 void jbd2_journal_free_transaction(transaction_t *transaction)
-- 
1.8.3.1

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

* Re: [PATCH] jbd2: remove the conditional test
  2018-02-05 14:24 [PATCH] jbd2: remove the conditional test Wang Long
@ 2018-02-06 10:22 ` Jan Kara
  2018-05-21  2:41 ` Theodore Y. Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2018-02-06 10:22 UTC (permalink / raw)
  To: Wang Long; +Cc: darrick.wong, tytso, jack, linux-ext4, linux-kernel

On Mon 05-02-18 22:24:39, Wang Long wrote:
> kmem_cache_destroy already handles null pointers, so we can remove the
> conditional test entirely.
> 
> This patch also set NULL after the kmem_cache_destroy in function
> jbd2_journal_destroy_handle_cache.
> 
> Signed-off-by: Wang Long <wanglong19@meituan.com>

Looks good. You can add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/jbd2/journal.c     | 18 +++++++-----------
>  fs/jbd2/revoke.c      | 12 ++++--------
>  fs/jbd2/transaction.c |  6 ++----
>  3 files changed, 13 insertions(+), 23 deletions(-)
> 
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index 93016bb..3c27a61a 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -2286,8 +2286,7 @@ static void jbd2_journal_destroy_slabs(void)
>  	int i;
>  
>  	for (i = 0; i < JBD2_MAX_SLABS; i++) {
> -		if (jbd2_slab[i])
> -			kmem_cache_destroy(jbd2_slab[i]);
> +		kmem_cache_destroy(jbd2_slab[i]);
>  		jbd2_slab[i] = NULL;
>  	}
>  }
> @@ -2388,10 +2387,8 @@ static int jbd2_journal_init_journal_head_cache(void)
>  
>  static void jbd2_journal_destroy_journal_head_cache(void)
>  {
> -	if (jbd2_journal_head_cache) {
> -		kmem_cache_destroy(jbd2_journal_head_cache);
> -		jbd2_journal_head_cache = NULL;
> -	}
> +	kmem_cache_destroy(jbd2_journal_head_cache);
> +	jbd2_journal_head_cache = NULL;
>  }
>  
>  /*
> @@ -2649,11 +2646,10 @@ static int __init jbd2_journal_init_handle_cache(void)
>  
>  static void jbd2_journal_destroy_handle_cache(void)
>  {
> -	if (jbd2_handle_cache)
> -		kmem_cache_destroy(jbd2_handle_cache);
> -	if (jbd2_inode_cache)
> -		kmem_cache_destroy(jbd2_inode_cache);
> -
> +	kmem_cache_destroy(jbd2_handle_cache);
> +	jbd2_handle_cache = NULL;
> +	kmem_cache_destroy(jbd2_inode_cache);
> +	jbd2_inode_cache = NULL;
>  }
>  
>  /*
> diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
> index 696ef15..240779e 100644
> --- a/fs/jbd2/revoke.c
> +++ b/fs/jbd2/revoke.c
> @@ -180,14 +180,10 @@ static struct jbd2_revoke_record_s *find_revoke_record(journal_t *journal,
>  
>  void jbd2_journal_destroy_revoke_caches(void)
>  {
> -	if (jbd2_revoke_record_cache) {
> -		kmem_cache_destroy(jbd2_revoke_record_cache);
> -		jbd2_revoke_record_cache = NULL;
> -	}
> -	if (jbd2_revoke_table_cache) {
> -		kmem_cache_destroy(jbd2_revoke_table_cache);
> -		jbd2_revoke_table_cache = NULL;
> -	}
> +	kmem_cache_destroy(jbd2_revoke_record_cache);
> +	jbd2_revoke_record_cache = NULL;
> +	kmem_cache_destroy(jbd2_revoke_table_cache);
> +	jbd2_revoke_table_cache = NULL;
>  }
>  
>  int __init jbd2_journal_init_revoke_caches(void)
> diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
> index ac31103..3b642e0 100644
> --- a/fs/jbd2/transaction.c
> +++ b/fs/jbd2/transaction.c
> @@ -49,10 +49,8 @@ int __init jbd2_journal_init_transaction_cache(void)
>  
>  void jbd2_journal_destroy_transaction_cache(void)
>  {
> -	if (transaction_cache) {
> -		kmem_cache_destroy(transaction_cache);
> -		transaction_cache = NULL;
> -	}
> +	kmem_cache_destroy(transaction_cache);
> +	transaction_cache = NULL;
>  }
>  
>  void jbd2_journal_free_transaction(transaction_t *transaction)
> -- 
> 1.8.3.1
> 
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] jbd2: remove the conditional test
  2018-02-05 14:24 [PATCH] jbd2: remove the conditional test Wang Long
  2018-02-06 10:22 ` Jan Kara
@ 2018-05-21  2:41 ` Theodore Y. Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Theodore Y. Ts'o @ 2018-05-21  2:41 UTC (permalink / raw)
  To: Wang Long; +Cc: darrick.wong, jack, linux-ext4, linux-kernel

On Mon, Feb 05, 2018 at 10:24:39PM +0800, Wang Long wrote:
> kmem_cache_destroy already handles null pointers, so we can remove the
> conditional test entirely.
> 
> This patch also set NULL after the kmem_cache_destroy in function
> jbd2_journal_destroy_handle_cache.
> 
> Signed-off-by: Wang Long <wanglong19@meituan.com>

Thanks; I clarified the patch summary to be:

    jbd2: remove NULL check before calling kmem_cache_destroy()

and have applied it.  Apologies for not getting to this earlier.

    	 	      		    - Ted

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

end of thread, other threads:[~2018-05-21  2:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-05 14:24 [PATCH] jbd2: remove the conditional test Wang Long
2018-02-06 10:22 ` Jan Kara
2018-05-21  2:41 ` Theodore Y. Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).