[PATCH 00/39] drop null test before destroy functions
STALE4055d
12 messages,
5 authors,
2015-09-15 · open the first message on its own page
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); // </smpl>
Signed-off-by: Julia Lawall <redacted>
---
drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
index 631c603..5f98870 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_fcoe.c @@ -620,8 +620,7 @@ static void ixgbe_fcoe_dma_pool_free(struct ixgbe_fcoe *fcoe, unsigned int cpu)
struct ixgbe_fcoe_ddp_pool * ddp_pool ;
ddp_pool = per_cpu_ptr ( fcoe -> ddp_pool , cpu );
- if ( ddp_pool -> pool )
- dma_pool_destroy ( ddp_pool -> pool );
+ dma_pool_destroy ( ddp_pool -> pool );
ddp_pool -> pool = NULL ;
}
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 <redacted>
---
net/dccp/ackvec.c | 12 ++++--------
net/dccp/ccid.c | 3 +--
2 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/net/dccp/ccid.c b/net/dccp/ccid.c
index 8349897..90f77d0 100644
--- a/net/dccp/ccid.c
+++ b/net/dccp/ccid.c @@ -95,8 +95,7 @@ static struct kmem_cache *ccid_kmem_cache_create(int obj_size, char *slab_name_f
static void ccid_kmem_cache_destroy ( struct kmem_cache * slab )
{
- if ( slab != NULL )
- kmem_cache_destroy ( slab );
+ kmem_cache_destroy ( slab );
}
static int __init ccid_activate ( struct ccid_operations * ccid_ops ) diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c
index bd9e718..3de0d03 100644
--- a/net/dccp/ackvec.c
+++ b/net/dccp/ackvec.c @@ -398,12 +398,8 @@ out_err:
void dccp_ackvec_exit ( void )
{
- if ( dccp_ackvec_slab != NULL ) {
- kmem_cache_destroy ( dccp_ackvec_slab );
- dccp_ackvec_slab = NULL ;
- }
- if ( dccp_ackvec_record_slab != NULL ) {
- kmem_cache_destroy ( dccp_ackvec_record_slab );
- dccp_ackvec_record_slab = NULL ;
- }
+ kmem_cache_destroy ( dccp_ackvec_slab );
+ dccp_ackvec_slab = NULL ;
+ kmem_cache_destroy ( dccp_ackvec_record_slab );
+ dccp_ackvec_record_slab = NULL ;
}
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);
x = NULL;
- }// </smpl>
Signed-off-by: Julia Lawall <redacted>
---
net/core/sock.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index ca2984a..3307c02 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c @@ -2740,10 +2740,8 @@ static void req_prot_cleanup(struct request_sock_ops *rsk_prot)
return ;
kfree ( rsk_prot -> slab_name );
rsk_prot -> slab_name = NULL ;
- if ( rsk_prot -> slab ) {
- kmem_cache_destroy ( rsk_prot -> slab );
- rsk_prot -> slab = NULL ;
- }
+ kmem_cache_destroy ( rsk_prot -> slab );
+ rsk_prot -> slab = NULL ;
}
static int req_prot_init ( const struct proto * prot ) @@ -2828,10 +2826,8 @@ void proto_unregister(struct proto *prot)
list_del ( & prot -> node );
mutex_unlock ( & proto_list_mutex );
- if ( prot -> slab != NULL ) {
- kmem_cache_destroy ( prot -> slab );
- prot -> slab = NULL ;
- }
+ kmem_cache_destroy ( prot -> slab );
+ prot -> slab = NULL ;
req_prot_cleanup ( prot -> rsk_prot );
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 <redacted>
---
net/sunrpc/sched.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index b140c09..425ca2f 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c @@ -1092,14 +1092,10 @@ void
rpc_destroy_mempool ( void )
{
rpciod_stop ();
- if ( rpc_buffer_mempool )
- mempool_destroy ( rpc_buffer_mempool );
- if ( rpc_task_mempool )
- mempool_destroy ( rpc_task_mempool );
- if ( rpc_task_slabp )
- kmem_cache_destroy ( rpc_task_slabp );
- if ( rpc_buffer_slabp )
- kmem_cache_destroy ( rpc_buffer_slabp );
+ mempool_destroy ( rpc_buffer_mempool );
+ mempool_destroy ( rpc_task_mempool );
+ kmem_cache_destroy ( rpc_task_slabp );
+ kmem_cache_destroy ( rpc_buffer_slabp );
rpc_destroy_wait_queue ( & delay_queue );
}
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 <redacted>
---
drivers/atm/he.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index a8da3a5..0f5cb37 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c @@ -1578,9 +1578,7 @@ he_stop(struct he_dev *he_dev)
kfree ( he_dev -> rbpl_virt );
kfree ( he_dev -> rbpl_table );
-
- if ( he_dev -> rbpl_pool )
- dma_pool_destroy ( he_dev -> rbpl_pool );
+ dma_pool_destroy ( he_dev -> rbpl_pool );
if ( he_dev -> rbrq_base )
dma_free_coherent ( & he_dev -> pci_dev -> dev , CONFIG_RBRQ_SIZE * sizeof ( struct he_rbrq ), @@ -1594,8 +1592,7 @@ he_stop(struct he_dev *he_dev)
dma_free_coherent ( & he_dev -> pci_dev -> dev , CONFIG_TBRQ_SIZE * sizeof ( struct he_tbrq ),
he_dev -> tpdrq_base , he_dev -> tpdrq_phys );
- if ( he_dev -> tpd_pool )
- dma_pool_destroy ( he_dev -> tpd_pool );
+ dma_pool_destroy ( he_dev -> tpd_pool );
if ( he_dev -> pci_dev ) {
pci_read_config_word ( he_dev -> pci_dev , PCI_COMMAND , & command );
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/cocci@systeme.lip6.fr/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
ACK, but assuming Trond takes this one.--b.
On Sun, Sep 13, 2015 at 02:15:07PM +0200, Julia Lawall wrote: quoted hunk 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 <redacted>
---
net/sunrpc/sched.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index b140c09..425ca2f 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c @@ -1092,14 +1092,10 @@ void
rpc_destroy_mempool ( void )
{
rpciod_stop ();
- if ( rpc_buffer_mempool )
- mempool_destroy ( rpc_buffer_mempool );
- if ( rpc_task_mempool )
- mempool_destroy ( rpc_task_mempool );
- if ( rpc_task_slabp )
- kmem_cache_destroy ( rpc_task_slabp );
- if ( rpc_buffer_slabp )
- kmem_cache_destroy ( rpc_buffer_slabp );
+ mempool_destroy ( rpc_buffer_mempool );
+ mempool_destroy ( rpc_task_mempool );
+ kmem_cache_destroy ( rpc_task_slabp );
+ kmem_cache_destroy ( rpc_buffer_slabp );
rpc_destroy_wait_queue ( & delay_queue );
}
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Sep 14, 2015 at 12:07 PM, J. Bruce Fields [off-list ref] wrote: ACK, but assuming Trond takes this one.--b.
No problem. I'll pick it up...
Cheers
Trond
On Sun, Sep 13, 2015 at 02:15:07PM +0200, Julia Lawall wrote: quoted 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 <redacted>
---
net/sunrpc/sched.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index b140c09..425ca2f 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c @@ -1092,14 +1092,10 @@ void
rpc_destroy_mempool ( void )
{
rpciod_stop ();
- if ( rpc_buffer_mempool )
- mempool_destroy ( rpc_buffer_mempool );
- if ( rpc_task_mempool )
- mempool_destroy ( rpc_task_mempool );
- if ( rpc_task_slabp )
- kmem_cache_destroy ( rpc_task_slabp );
- if ( rpc_buffer_slabp )
- kmem_cache_destroy ( rpc_buffer_slabp );
+ mempool_destroy ( rpc_buffer_mempool );
+ mempool_destroy ( rpc_task_mempool );
+ kmem_cache_destroy ( rpc_task_slabp );
+ kmem_cache_destroy ( rpc_buffer_slabp );
rpc_destroy_wait_queue ( & delay_queue );
}
From: Julia Lawall <redacted>
Date: Sun, 13 Sep 2015 14:15:18 +0200
quoted hunk 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);
x = NULL;
- }// </smpl>
Signed-off-by: Julia Lawall <redacted>
Applied.
From: Julia Lawall <redacted>
Date: Sun, 13 Sep 2015 14:15:27 +0200
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 <redacted>
Applied.
From: Julia Lawall <redacted>
Date: Sun, 13 Sep 2015 14:15:03 +0200
quoted hunk 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 <redacted>
Applied.