Recent commits to kernel/git/torvalds/linux.git have made the following
functions able to tolerate NULL arguments:
kmem_cache_destroy (commit 3942d29918522)
mempool_destroy (commit 4e3ca3e033d1)
dma_pool_destroy (commit 44d7175da6ea)
These patches remove the associated NULL tests for the files that I found
easy to compile test. If these changes are OK, I will address the
remainder later.
---
arch/x86/kvm/mmu.c | 6 --
block/bio-integrity.c | 7 --
block/bio.c | 7 --
block/blk-core.c | 3 -
block/elevator.c | 3 -
drivers/atm/he.c | 7 --
drivers/block/aoe/aoedev.c | 3 -
drivers/block/drbd/drbd_main.c | 21 ++-----
drivers/block/pktcdvd.c | 3 -
drivers/block/rbd.c | 6 --
drivers/dma/dmaengine.c | 6 --
drivers/firmware/google/gsmi.c | 3 -
drivers/gpu/drm/i915/i915_dma.c | 19 ++----
drivers/iommu/amd_iommu_init.c | 7 --
drivers/md/bcache/bset.c | 3 -
drivers/md/bcache/request.c | 3 -
drivers/md/bcache/super.c | 9 +--
drivers/md/dm-bufio.c | 3 -
drivers/md/dm-cache-target.c | 3 -
drivers/md/dm-crypt.c | 6 --
drivers/md/dm-io.c | 3 -
drivers/md/dm-log-userspace-base.c | 3 -
drivers/md/dm-region-hash.c | 4 -
drivers/md/dm.c | 13 +---
drivers/md/multipath.c | 3 -
drivers/md/raid1.c | 6 --
drivers/md/raid10.c | 9 +--
drivers/md/raid5.c | 3 -
drivers/mtd/nand/nandsim.c | 3 -
drivers/mtd/ubi/attach.c | 4 -
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 3 -
drivers/staging/lustre/lustre/llite/super25.c | 16 +----
drivers/staging/lustre/lustre/obdclass/genops.c | 24 ++------
drivers/staging/lustre/lustre/obdclass/lu_object.c | 6 --
drivers/staging/rdma/hfi1/user_sdma.c | 3 -
drivers/thunderbolt/ctl.c | 3 -
drivers/usb/gadget/udc/bdc/bdc_core.c | 3 -
drivers/usb/gadget/udc/gr_udc.c | 3 -
drivers/usb/gadget/udc/mv_u3d_core.c | 3 -
drivers/usb/gadget/udc/mv_udc_core.c | 3 -
drivers/usb/host/fotg210-hcd.c | 12 +---
drivers/usb/host/fusbh200-hcd.c | 12 +---
drivers/usb/host/whci/init.c | 3 -
drivers/usb/host/xhci-mem.c | 12 +---
fs/btrfs/backref.c | 3 -
fs/btrfs/delayed-inode.c | 3 -
fs/btrfs/delayed-ref.c | 12 +---
fs/btrfs/disk-io.c | 3 -
fs/btrfs/extent_io.c | 6 --
fs/btrfs/extent_map.c | 3 -
fs/btrfs/file.c | 3 -
fs/btrfs/inode.c | 18 ++----
fs/btrfs/ordered-data.c | 3 -
fs/dlm/memory.c | 6 --
fs/ecryptfs/main.c | 3 -
fs/ext4/crypto.c | 9 +--
fs/ext4/extents_status.c | 3 -
fs/ext4/mballoc.c | 3 -
fs/f2fs/crypto.c | 9 +--
fs/gfs2/main.c | 29 ++--------
fs/jbd2/journal.c | 15 +----
fs/jbd2/revoke.c | 12 +---
fs/jbd2/transaction.c | 6 --
fs/jffs2/malloc.c | 27 +++------
fs/nfsd/nfscache.c | 6 --
fs/nilfs2/super.c | 12 +---
fs/ocfs2/dlm/dlmlock.c | 3 -
fs/ocfs2/dlm/dlmmaster.c | 16 +----
fs/ocfs2/super.c | 18 ++----
fs/ocfs2/uptodate.c | 3 -
lib/debugobjects.c | 3 -
net/core/sock.c | 12 +---
net/dccp/ackvec.c | 12 +---
net/dccp/ccid.c | 3 -
net/sunrpc/sched.c | 12 +---
75 files changed, 180 insertions(+), 381 deletions(-)
Remove unneeded NULL test.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression x;
@@
-if (x != NULL)
\(kmem_cache_destroy\|mempool_destroy\|dma_pool_destroy\)(x);
@@
expression x;
@@
-if (x != NULL) {
\(kmem_cache_destroy\|mempool_destroy\|dma_pool_destroy\)(x);
x = NULL;
-}
// </smpl>
Signed-off-by: Julia Lawall <[email protected]>
---
fs/jbd2/journal.c | 15 +++++----------
fs/jbd2/revoke.c | 12 ++++--------
fs/jbd2/transaction.c | 6 ++----
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 6b8338e..ab26122 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -51,10 +51,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)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 8270fe9..6b8c2c5 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2240,8 +2240,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;
}
}
@@ -2360,10 +2359,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;
}
/*
@@ -2621,10 +2618,8 @@ 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);
+ kmem_cache_destroy(jbd2_inode_cache);
}
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index 0abf2e7..1e77a9d 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -183,14 +183,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)
Remove unneeded NULL test.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@ expression x; @@
-if (x != NULL)
\(kmem_cache_destroy\|mempool_destroy\|dma_pool_destroy\)(x);
// </smpl>
Signed-off-by: Julia Lawall <[email protected]>
---
fs/ext4/crypto.c | 9 +++------
fs/ext4/extents_status.c | 3 +--
fs/ext4/mballoc.c | 3 +--
3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 26724ae..42096d3 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -161,8 +161,7 @@ int __init ext4_init_es(void)
void ext4_exit_es(void)
{
- if (ext4_es_cachep)
- kmem_cache_destroy(ext4_es_cachep);
+ kmem_cache_destroy(ext4_es_cachep);
}
void ext4_es_init_tree(struct ext4_es_tree *tree)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 34b610e..b5adfb9 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2520,8 +2520,7 @@ static void ext4_groupinfo_destroy_slabs(void)
int i;
for (i = 0; i < NR_GRPINFO_CACHES; i++) {
- if (ext4_groupinfo_caches[i])
- kmem_cache_destroy(ext4_groupinfo_caches[i]);
+ kmem_cache_destroy(ext4_groupinfo_caches[i]);
ext4_groupinfo_caches[i] = NULL;
}
}
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
index 4573155..e4d6d30 100644
--- a/fs/ext4/crypto.c
+++ b/fs/ext4/crypto.c
@@ -153,17 +153,14 @@ void ext4_exit_crypto(void)
list_for_each_entry_safe(pos, n, &ext4_free_crypto_ctxs, free_list)
kmem_cache_free(ext4_crypto_ctx_cachep, pos);
INIT_LIST_HEAD(&ext4_free_crypto_ctxs);
- if (ext4_bounce_page_pool)
- mempool_destroy(ext4_bounce_page_pool);
+ mempool_destroy(ext4_bounce_page_pool);
ext4_bounce_page_pool = NULL;
if (ext4_read_workqueue)
destroy_workqueue(ext4_read_workqueue);
ext4_read_workqueue = NULL;
- if (ext4_crypto_ctx_cachep)
- kmem_cache_destroy(ext4_crypto_ctx_cachep);
+ kmem_cache_destroy(ext4_crypto_ctx_cachep);
ext4_crypto_ctx_cachep = NULL;
- if (ext4_crypt_info_cachep)
- kmem_cache_destroy(ext4_crypt_info_cachep);
+ kmem_cache_destroy(ext4_crypt_info_cachep);
ext4_crypt_info_cachep = NULL;
}
> Recent commits to kernel/git/torvalds/linux.git have made the following
> functions able to tolerate NULL arguments:
>
> kmem_cache_destroy (commit 3942d29918522)
> mempool_destroy (commit 4e3ca3e033d1)
> dma_pool_destroy (commit 44d7175da6ea)
How do you think about to extend an other SmPL script?
Related topic:
scripts/coccinelle/free: Delete NULL test before freeing functions
https://systeme.lip6.fr/pipermail/cocci/2015-May/001960.html
https://www.mail-archive.com/[email protected]/msg01855.html
> If these changes are OK, I will address the remainder later.
Would anybody like to reuse my general SmPL approach for similar source
code clean-up?
Regards,
Markus