jbd2: remove NULL check before calling kmem_cache_destroy()
authorWang Long <wanglong19@meituan.com>
Mon, 21 May 2018 02:38:26 +0000 (22:38 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 21 May 2018 02:38:26 +0000 (22:38 -0400)
The kmem_cache_destroy() function already checks for null pointers, so
we can remove the check at the call site.

This patch also sets jbd2_handle_cache and jbd2_inode_cache to be NULL
after freeing them in jbd2_journal_destroy_handle_cache().

Signed-off-by: Wang Long <wanglong19@meituan.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
fs/jbd2/journal.c
fs/jbd2/revoke.c
fs/jbd2/transaction.c

index e94270192cadc45bf5bc3ddd8ec58bc6e1650728..8ef6b6daaa7a641bc39f507b42ad89db488f98ce 100644 (file)
@@ -2302,8 +2302,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;
        }
 }
@@ -2404,10 +2403,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;
 }
 
 /*
@@ -2665,11 +2662,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;
 }
 
 /*
index 696ef15ec9428ab63e025786e7075c180ad6f8ad..240779e4689c53f0705615ee4d39d2096f9854b0 100644 (file)
@@ -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)
index 8aa453784402bbed8d33aa76d025071bf6523c75..51dd68e67b0f3abfcd115196724079e226467d09 100644 (file)
@@ -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)