* [PATCH 12/39] dm: drop null test before destroy functions
2015-09-13 12:14 [PATCH 00/39] drop null test before destroy functions Julia Lawall
@ 2015-09-13 12:15 ` Julia Lawall
2015-09-14 13:46 ` [dm-devel] " Mikulas Patocka
2015-09-13 12:15 ` [PATCH 15/39] bcache: " Julia Lawall
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2015-09-13 12:15 UTC (permalink / raw)
To: Alasdair Kergon
Cc: sergey.senozhatsky, kernel-janitors, Mike Snitzer, dm-devel,
Neil Brown, linux-raid, linux-kernel
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 <Julia.Lawall@lip6.fr>
---
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 ++++---------
7 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 83cc52e..8ad39b6 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -1864,8 +1864,7 @@ static void __exit dm_bufio_exit(void)
for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) {
struct kmem_cache *kc = dm_bufio_caches[i];
- if (kc)
- kmem_cache_destroy(kc);
+ kmem_cache_destroy(kc);
}
for (i = 0; i < ARRAY_SIZE(dm_bufio_cache_names); i++)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 6264781..163de31 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2220,10 +2220,8 @@ static void cleanup_mapped_device(struct mapped_device *md)
destroy_workqueue(md->wq);
if (md->kworker_task)
kthread_stop(md->kworker_task);
- if (md->io_pool)
- mempool_destroy(md->io_pool);
- if (md->rq_pool)
- mempool_destroy(md->rq_pool);
+ mempool_destroy(md->io_pool);
+ mempool_destroy(md->rq_pool);
if (md->bs)
bioset_free(md->bs);
@@ -3508,11 +3506,8 @@ void dm_free_md_mempools(struct dm_md_mempools *pools)
if (!pools)
return;
- if (pools->io_pool)
- mempool_destroy(pools->io_pool);
-
- if (pools->rq_pool)
- mempool_destroy(pools->rq_pool);
+ mempool_destroy(pools->io_pool);
+ mempool_destroy(pools->rq_pool);
if (pools->bs)
bioset_free(pools->bs);
diff --git a/drivers/md/dm-log-userspace-base.c b/drivers/md/dm-log-userspace-base.c
index 058256d..53b7b06 100644
--- a/drivers/md/dm-log-userspace-base.c
+++ b/drivers/md/dm-log-userspace-base.c
@@ -313,8 +313,7 @@ static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti,
out:
kfree(devices_rdata);
if (r) {
- if (lc->flush_entry_pool)
- mempool_destroy(lc->flush_entry_pool);
+ mempool_destroy(lc->flush_entry_pool);
kfree(lc);
kfree(ctr_str);
} else {
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index 6f8e83b..81c5e1a 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -65,8 +65,7 @@ struct dm_io_client *dm_io_client_create(void)
return client;
bad:
- if (client->pool)
- mempool_destroy(client->pool);
+ mempool_destroy(client->pool);
kfree(client);
return ERR_PTR(-ENOMEM);
}
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index dd90d12..2fd4c82 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -2309,8 +2309,7 @@ static void destroy(struct cache *cache)
{
unsigned i;
- if (cache->migration_pool)
- mempool_destroy(cache->migration_pool);
+ mempool_destroy(cache->migration_pool);
if (cache->all_io_ds)
dm_deferred_set_destroy(cache->all_io_ds);
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index d60c88d..cf91a96 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1543,10 +1543,8 @@ static void crypt_dtr(struct dm_target *ti)
if (cc->bs)
bioset_free(cc->bs);
- if (cc->page_pool)
- mempool_destroy(cc->page_pool);
- if (cc->req_pool)
- mempool_destroy(cc->req_pool);
+ mempool_destroy(cc->page_pool);
+ mempool_destroy(cc->req_pool);
if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
cc->iv_gen_ops->dtr(cc);
diff --git a/drivers/md/dm-region-hash.c b/drivers/md/dm-region-hash.c
index b929fd5..f3d608b 100644
--- a/drivers/md/dm-region-hash.c
+++ b/drivers/md/dm-region-hash.c
@@ -249,9 +249,7 @@ void dm_region_hash_destroy(struct dm_region_hash *rh)
if (rh->log)
dm_dirty_log_destroy(rh->log);
- if (rh->region_pool)
- mempool_destroy(rh->region_pool);
-
+ mempool_destroy(rh->region_pool);
vfree(rh->buckets);
kfree(rh);
}
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [dm-devel] [PATCH 12/39] dm: drop null test before destroy functions
2015-09-13 12:15 ` [PATCH 12/39] dm: " Julia Lawall
@ 2015-09-14 13:46 ` Mikulas Patocka
2015-09-14 14:00 ` Mike Snitzer
2015-09-14 14:23 ` [dm-devel] " walter harms
0 siblings, 2 replies; 12+ messages in thread
From: Mikulas Patocka @ 2015-09-14 13:46 UTC (permalink / raw)
To: device-mapper development
Cc: Alasdair Kergon, Mike Snitzer, kernel-janitors, Neil Brown,
linux-kernel, linux-raid, sergey.senozhatsky
On Sun, 13 Sep 2015, Julia Lawall wrote:
> 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 <Julia.Lawall@lip6.fr>
>
> ---
> 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 ++++---------
> 7 files changed, 11 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> index 83cc52e..8ad39b6 100644
> --- a/drivers/md/dm-bufio.c
> +++ b/drivers/md/dm-bufio.c
> @@ -1864,8 +1864,7 @@ static void __exit dm_bufio_exit(void)
> for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) {
> struct kmem_cache *kc = dm_bufio_caches[i];
>
> - if (kc)
> - kmem_cache_destroy(kc);
> + kmem_cache_destroy(kc);
> }
The variable here can be NULL. I don't know how did you conclude that it
cannot. It seems that you didn't test the patch, if you did, you'd hit
NULL pointer dereference here.
> for (i = 0; i < ARRAY_SIZE(dm_bufio_cache_names); i++)
> diff --git a/drivers/md/dm.c b/drivers/md/dm.c
> index 6264781..163de31 100644
> --- a/drivers/md/dm.c
> +++ b/drivers/md/dm.c
> @@ -2220,10 +2220,8 @@ static void cleanup_mapped_device(struct mapped_device *md)
> destroy_workqueue(md->wq);
> if (md->kworker_task)
> kthread_stop(md->kworker_task);
> - if (md->io_pool)
> - mempool_destroy(md->io_pool);
> - if (md->rq_pool)
> - mempool_destroy(md->rq_pool);
> + mempool_destroy(md->io_pool);
> + mempool_destroy(md->rq_pool);
Likewise, these variables can be NULL.
> if (md->bs)
> bioset_free(md->bs);
>
> @@ -3508,11 +3506,8 @@ void dm_free_md_mempools(struct dm_md_mempools *pools)
> if (!pools)
> return;
>
> - if (pools->io_pool)
> - mempool_destroy(pools->io_pool);
> -
> - if (pools->rq_pool)
> - mempool_destroy(pools->rq_pool);
> + mempool_destroy(pools->io_pool);
> + mempool_destroy(pools->rq_pool);
>
> if (pools->bs)
> bioset_free(pools->bs);
Likewise, it can be NULL, see for example this code path:
pools->io_pool = mempool_create_slab_pool(pool_size, cachep);
if (!pools->io_pool)
goto out;
out:
dm_free_md_mempools(pools);
dm_free_md_mempools:
if (pools->io_pool)
mempool_destroy(pools->io_pool);
It seems that you set up the cocinelle tool incorrectly, so that it
produces many bogus suggestions.
Mikulas
> diff --git a/drivers/md/dm-log-userspace-base.c b/drivers/md/dm-log-userspace-base.c
> index 058256d..53b7b06 100644
> --- a/drivers/md/dm-log-userspace-base.c
> +++ b/drivers/md/dm-log-userspace-base.c
> @@ -313,8 +313,7 @@ static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti,
> out:
> kfree(devices_rdata);
> if (r) {
> - if (lc->flush_entry_pool)
> - mempool_destroy(lc->flush_entry_pool);
> + mempool_destroy(lc->flush_entry_pool);
> kfree(lc);
> kfree(ctr_str);
> } else {
> diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
> index 6f8e83b..81c5e1a 100644
> --- a/drivers/md/dm-io.c
> +++ b/drivers/md/dm-io.c
> @@ -65,8 +65,7 @@ struct dm_io_client *dm_io_client_create(void)
> return client;
>
> bad:
> - if (client->pool)
> - mempool_destroy(client->pool);
> + mempool_destroy(client->pool);
> kfree(client);
> return ERR_PTR(-ENOMEM);
> }
> diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
> index dd90d12..2fd4c82 100644
> --- a/drivers/md/dm-cache-target.c
> +++ b/drivers/md/dm-cache-target.c
> @@ -2309,8 +2309,7 @@ static void destroy(struct cache *cache)
> {
> unsigned i;
>
> - if (cache->migration_pool)
> - mempool_destroy(cache->migration_pool);
> + mempool_destroy(cache->migration_pool);
>
> if (cache->all_io_ds)
> dm_deferred_set_destroy(cache->all_io_ds);
> diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
> index d60c88d..cf91a96 100644
> --- a/drivers/md/dm-crypt.c
> +++ b/drivers/md/dm-crypt.c
> @@ -1543,10 +1543,8 @@ static void crypt_dtr(struct dm_target *ti)
> if (cc->bs)
> bioset_free(cc->bs);
>
> - if (cc->page_pool)
> - mempool_destroy(cc->page_pool);
> - if (cc->req_pool)
> - mempool_destroy(cc->req_pool);
> + mempool_destroy(cc->page_pool);
> + mempool_destroy(cc->req_pool);
>
> if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
> cc->iv_gen_ops->dtr(cc);
> diff --git a/drivers/md/dm-region-hash.c b/drivers/md/dm-region-hash.c
> index b929fd5..f3d608b 100644
> --- a/drivers/md/dm-region-hash.c
> +++ b/drivers/md/dm-region-hash.c
> @@ -249,9 +249,7 @@ void dm_region_hash_destroy(struct dm_region_hash *rh)
> if (rh->log)
> dm_dirty_log_destroy(rh->log);
>
> - if (rh->region_pool)
> - mempool_destroy(rh->region_pool);
> -
> + mempool_destroy(rh->region_pool);
> vfree(rh->buckets);
> kfree(rh);
> }
>
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 12/39] dm: drop null test before destroy functions
2015-09-14 13:46 ` [dm-devel] " Mikulas Patocka
@ 2015-09-14 14:00 ` Mike Snitzer
2015-09-14 14:05 ` Mikulas Patocka
2015-09-14 14:23 ` [dm-devel] " walter harms
1 sibling, 1 reply; 12+ messages in thread
From: Mike Snitzer @ 2015-09-14 14:00 UTC (permalink / raw)
To: Mikulas Patocka
Cc: device-mapper development, Alasdair Kergon, kernel-janitors,
Neil Brown, linux-kernel, linux-raid, sergey.senozhatsky
On Mon, Sep 14 2015 at 9:46am -0400,
Mikulas Patocka <mpatocka@redhat.com> wrote:
>
>
> On Sun, 13 Sep 2015, Julia Lawall wrote:
>
> > 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 <Julia.Lawall@lip6.fr>
> >
> > ---
> > 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 ++++---------
> > 7 files changed, 11 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> > index 83cc52e..8ad39b6 100644
> > --- a/drivers/md/dm-bufio.c
> > +++ b/drivers/md/dm-bufio.c
> > @@ -1864,8 +1864,7 @@ static void __exit dm_bufio_exit(void)
> > for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) {
> > struct kmem_cache *kc = dm_bufio_caches[i];
> >
> > - if (kc)
> > - kmem_cache_destroy(kc);
> > + kmem_cache_destroy(kc);
> > }
>
> The variable here can be NULL. I don't know how did you conclude that it
> cannot. It seems that you didn't test the patch, if you did, you'd hit
> NULL pointer dereference here.
kmem_cache_destroy(), mempool_destroy(), etc all check for NULL and just
return. So there is no need for the callers to check for NULL too.
Mike
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 12/39] dm: drop null test before destroy functions
2015-09-14 14:00 ` Mike Snitzer
@ 2015-09-14 14:05 ` Mikulas Patocka
2015-09-14 18:50 ` Julia Lawall
0 siblings, 1 reply; 12+ messages in thread
From: Mikulas Patocka @ 2015-09-14 14:05 UTC (permalink / raw)
To: Mike Snitzer
Cc: device-mapper development, Alasdair Kergon, kernel-janitors,
Neil Brown, linux-kernel, linux-raid, sergey.senozhatsky
On Mon, 14 Sep 2015, Mike Snitzer wrote:
> On Mon, Sep 14 2015 at 9:46am -0400,
> Mikulas Patocka <mpatocka@redhat.com> wrote:
>
> >
> >
> > On Sun, 13 Sep 2015, Julia Lawall wrote:
> >
> > > 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 <Julia.Lawall@lip6.fr>
> > >
> > > ---
> > > 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 ++++---------
> > > 7 files changed, 11 insertions(+), 24 deletions(-)
> > >
> > > diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> > > index 83cc52e..8ad39b6 100644
> > > --- a/drivers/md/dm-bufio.c
> > > +++ b/drivers/md/dm-bufio.c
> > > @@ -1864,8 +1864,7 @@ static void __exit dm_bufio_exit(void)
> > > for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) {
> > > struct kmem_cache *kc = dm_bufio_caches[i];
> > >
> > > - if (kc)
> > > - kmem_cache_destroy(kc);
> > > + kmem_cache_destroy(kc);
> > > }
> >
> > The variable here can be NULL. I don't know how did you conclude that it
> > cannot. It seems that you didn't test the patch, if you did, you'd hit
> > NULL pointer dereference here.
>
> kmem_cache_destroy(), mempool_destroy(), etc all check for NULL and just
> return. So there is no need for the callers to check for NULL too.
>
> Mike
I see. It was recent change that I missed.
Mikulas
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 12/39] dm: drop null test before destroy functions
2015-09-14 14:05 ` Mikulas Patocka
@ 2015-09-14 18:50 ` Julia Lawall
0 siblings, 0 replies; 12+ messages in thread
From: Julia Lawall @ 2015-09-14 18:50 UTC (permalink / raw)
To: Mikulas Patocka
Cc: Mike Snitzer, device-mapper development, Alasdair Kergon,
kernel-janitors, Neil Brown, linux-kernel, linux-raid,
sergey.senozhatsky
On Mon, 14 Sep 2015, Mikulas Patocka wrote:
>
>
> On Mon, 14 Sep 2015, Mike Snitzer wrote:
>
> > On Mon, Sep 14 2015 at 9:46am -0400,
> > Mikulas Patocka <mpatocka@redhat.com> wrote:
> >
> > >
> > >
> > > On Sun, 13 Sep 2015, Julia Lawall wrote:
> > >
> > > > 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 <Julia.Lawall@lip6.fr>
> > > >
> > > > ---
> > > > 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 ++++---------
> > > > 7 files changed, 11 insertions(+), 24 deletions(-)
> > > >
> > > > diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> > > > index 83cc52e..8ad39b6 100644
> > > > --- a/drivers/md/dm-bufio.c
> > > > +++ b/drivers/md/dm-bufio.c
> > > > @@ -1864,8 +1864,7 @@ static void __exit dm_bufio_exit(void)
> > > > for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) {
> > > > struct kmem_cache *kc = dm_bufio_caches[i];
> > > >
> > > > - if (kc)
> > > > - kmem_cache_destroy(kc);
> > > > + kmem_cache_destroy(kc);
> > > > }
> > >
> > > The variable here can be NULL. I don't know how did you conclude that it
> > > cannot. It seems that you didn't test the patch, if you did, you'd hit
> > > NULL pointer dereference here.
> >
> > kmem_cache_destroy(), mempool_destroy(), etc all check for NULL and just
> > return. So there is no need for the callers to check for NULL too.
> >
> > Mike
>
> I see. It was recent change that I missed.
The relevant commits were in the cover letter:
kmem_cache_destroy (commit 3942d29918522)
mempool_destroy (commit 4e3ca3e033d1)
dma_pool_destroy (commit 44d7175da6ea)
julia
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [dm-devel] [PATCH 12/39] dm: drop null test before destroy functions
2015-09-14 13:46 ` [dm-devel] " Mikulas Patocka
2015-09-14 14:00 ` Mike Snitzer
@ 2015-09-14 14:23 ` walter harms
1 sibling, 0 replies; 12+ messages in thread
From: walter harms @ 2015-09-14 14:23 UTC (permalink / raw)
To: Mikulas Patocka
Cc: device-mapper development, Alasdair Kergon, Mike Snitzer,
kernel-janitors, Neil Brown, linux-kernel, linux-raid,
sergey.senozhatsky
Am 14.09.2015 15:46, schrieb Mikulas Patocka:
>
> On Sun, 13 Sep 2015, Julia Lawall wrote:
>
>> > 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 <Julia.Lawall@lip6.fr>
>> >
>> > ---
>> > 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 ++++---------
>> > 7 files changed, 11 insertions(+), 24 deletions(-)
>> >
>> > diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
>> > index 83cc52e..8ad39b6 100644
>> > --- a/drivers/md/dm-bufio.c
>> > +++ b/drivers/md/dm-bufio.c
>> > @@ -1864,8 +1864,7 @@ static void __exit dm_bufio_exit(void)
>> > for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) {
>> > struct kmem_cache *kc = dm_bufio_caches[i];
>> >
>> > - if (kc)
>> > - kmem_cache_destroy(kc);
>> > + kmem_cache_destroy(kc);
>> > }
maybe you want to remove "kc" also
by calling kmem_cache_destroy(dm_bufio_caches[i]); directly ?
just a hint,
wh
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 15/39] bcache: drop null test before destroy functions
2015-09-13 12:14 [PATCH 00/39] drop null test before destroy functions Julia Lawall
2015-09-13 12:15 ` [PATCH 12/39] dm: " Julia Lawall
@ 2015-09-13 12:15 ` Julia Lawall
2015-09-14 9:08 ` Johannes Thumshirn
2015-09-13 12:15 ` [PATCH 17/39] md: " Julia Lawall
2015-09-14 11:55 ` [PATCH 00/39] " SF Markus Elfring
3 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2015-09-13 12:15 UTC (permalink / raw)
To: Kent Overstreet
Cc: sergey.senozhatsky, kernel-janitors, Neil Brown, linux-bcache,
linux-raid, linux-kernel
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 <Julia.Lawall@lip6.fr>
---
drivers/md/bcache/bset.c | 3 +--
drivers/md/bcache/request.c | 3 +--
drivers/md/bcache/super.c | 9 +++------
3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index 8e9877b..bd4678c 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -1145,8 +1145,7 @@ void bch_flash_dev_request_init(struct bcache_device *d)
void bch_request_exit(void)
{
- if (bch_search_cache)
- kmem_cache_destroy(bch_search_cache);
+ kmem_cache_destroy(bch_search_cache);
}
int __init bch_request_init(void)
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index 646fe85..479117c 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -1116,8 +1116,7 @@ struct bkey *bch_btree_iter_next_filter(struct btree_iter *iter,
void bch_bset_sort_state_free(struct bset_sort_state *state)
{
- if (state->pool)
- mempool_destroy(state->pool);
+ mempool_destroy(state->pool);
}
int bch_bset_sort_state_init(struct bset_sort_state *state, unsigned page_order)
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 679a093..c27a0ff 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1335,12 +1335,9 @@ static void cache_set_free(struct closure *cl)
destroy_workqueue(c->moving_gc_wq);
if (c->bio_split)
bioset_free(c->bio_split);
- if (c->fill_iter)
- mempool_destroy(c->fill_iter);
- if (c->bio_meta)
- mempool_destroy(c->bio_meta);
- if (c->search)
- mempool_destroy(c->search);
+ mempool_destroy(c->fill_iter);
+ mempool_destroy(c->bio_meta);
+ mempool_destroy(c->search);
kfree(c->devices);
mutex_lock(&bch_register_lock);
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 15/39] bcache: drop null test before destroy functions
2015-09-13 12:15 ` [PATCH 15/39] bcache: " Julia Lawall
@ 2015-09-14 9:08 ` Johannes Thumshirn
0 siblings, 0 replies; 12+ messages in thread
From: Johannes Thumshirn @ 2015-09-14 9:08 UTC (permalink / raw)
To: Julia Lawall
Cc: Kent Overstreet, sergey.senozhatsky, kernel-janitors, Neil Brown,
linux-bcache, linux-raid, linux-kernel
Julia Lawall <Julia.Lawall@lip6.fr> writes:
> 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 <Julia.Lawall@lip6.fr>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
>
> ---
> drivers/md/bcache/bset.c | 3 +--
> drivers/md/bcache/request.c | 3 +--
> drivers/md/bcache/super.c | 9 +++------
> 3 files changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
> index 8e9877b..bd4678c 100644
> --- a/drivers/md/bcache/request.c
> +++ b/drivers/md/bcache/request.c
> @@ -1145,8 +1145,7 @@ void bch_flash_dev_request_init(struct bcache_device *d)
>
> void bch_request_exit(void)
> {
> - if (bch_search_cache)
> - kmem_cache_destroy(bch_search_cache);
> + kmem_cache_destroy(bch_search_cache);
> }
>
> int __init bch_request_init(void)
> diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
> index 646fe85..479117c 100644
> --- a/drivers/md/bcache/bset.c
> +++ b/drivers/md/bcache/bset.c
> @@ -1116,8 +1116,7 @@ struct bkey *bch_btree_iter_next_filter(struct btree_iter *iter,
>
> void bch_bset_sort_state_free(struct bset_sort_state *state)
> {
> - if (state->pool)
> - mempool_destroy(state->pool);
> + mempool_destroy(state->pool);
> }
>
> int bch_bset_sort_state_init(struct bset_sort_state *state, unsigned page_order)
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index 679a093..c27a0ff 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -1335,12 +1335,9 @@ static void cache_set_free(struct closure *cl)
> destroy_workqueue(c->moving_gc_wq);
> if (c->bio_split)
> bioset_free(c->bio_split);
> - if (c->fill_iter)
> - mempool_destroy(c->fill_iter);
> - if (c->bio_meta)
> - mempool_destroy(c->bio_meta);
> - if (c->search)
> - mempool_destroy(c->search);
> + mempool_destroy(c->fill_iter);
> + mempool_destroy(c->bio_meta);
> + mempool_destroy(c->search);
> kfree(c->devices);
>
> mutex_lock(&bch_register_lock);
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bcache" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 17/39] md: drop null test before destroy functions
2015-09-13 12:14 [PATCH 00/39] drop null test before destroy functions Julia Lawall
2015-09-13 12:15 ` [PATCH 12/39] dm: " Julia Lawall
2015-09-13 12:15 ` [PATCH 15/39] bcache: " Julia Lawall
@ 2015-09-13 12:15 ` Julia Lawall
2015-09-15 7:29 ` Neil Brown
2015-09-14 11:55 ` [PATCH 00/39] " SF Markus Elfring
3 siblings, 1 reply; 12+ messages in thread
From: Julia Lawall @ 2015-09-13 12:15 UTC (permalink / raw)
To: Neil Brown; +Cc: sergey.senozhatsky, kernel-janitors, linux-raid, linux-kernel
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 <Julia.Lawall@lip6.fr>
---
drivers/md/multipath.c | 3 +--
drivers/md/raid1.c | 6 ++----
drivers/md/raid10.c | 9 +++------
drivers/md/raid5.c | 3 +--
4 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 15ef2c6..09a12d7 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2271,8 +2271,7 @@ static void shrink_stripes(struct r5conf *conf)
drop_one_stripe(conf))
;
- if (conf->slab_cache)
- kmem_cache_destroy(conf->slab_cache);
+ kmem_cache_destroy(conf->slab_cache);
conf->slab_cache = NULL;
}
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 4517f06..5f4f553 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2843,8 +2843,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
abort:
if (conf) {
- if (conf->r1bio_pool)
- mempool_destroy(conf->r1bio_pool);
+ mempool_destroy(conf->r1bio_pool);
kfree(conf->mirrors);
safe_put_page(conf->tmppage);
kfree(conf->poolinfo);
@@ -2946,8 +2945,7 @@ static void raid1_free(struct mddev *mddev, void *priv)
{
struct r1conf *conf = priv;
- if (conf->r1bio_pool)
- mempool_destroy(conf->r1bio_pool);
+ mempool_destroy(conf->r1bio_pool);
kfree(conf->mirrors);
safe_put_page(conf->tmppage);
kfree(conf->poolinfo);
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index d222522..d132f06 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -470,8 +470,7 @@ static int multipath_run (struct mddev *mddev)
return 0;
out_free_conf:
- if (conf->pool)
- mempool_destroy(conf->pool);
+ mempool_destroy(conf->pool);
kfree(conf->multipaths);
kfree(conf);
mddev->private = NULL;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 0fc33eb..7c99a40 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3486,8 +3486,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
printk(KERN_ERR "md/raid10:%s: couldn't allocate memory.\n",
mdname(mddev));
if (conf) {
- if (conf->r10bio_pool)
- mempool_destroy(conf->r10bio_pool);
+ mempool_destroy(conf->r10bio_pool);
kfree(conf->mirrors);
safe_put_page(conf->tmppage);
kfree(conf);
@@ -3682,8 +3681,7 @@ static int run(struct mddev *mddev)
out_free_conf:
md_unregister_thread(&mddev->thread);
- if (conf->r10bio_pool)
- mempool_destroy(conf->r10bio_pool);
+ mempool_destroy(conf->r10bio_pool);
safe_put_page(conf->tmppage);
kfree(conf->mirrors);
kfree(conf);
@@ -3696,8 +3694,7 @@ static void raid10_free(struct mddev *mddev, void *priv)
{
struct r10conf *conf = priv;
- if (conf->r10bio_pool)
- mempool_destroy(conf->r10bio_pool);
+ mempool_destroy(conf->r10bio_pool);
safe_put_page(conf->tmppage);
kfree(conf->mirrors);
kfree(conf->mirrors_old);
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 17/39] md: drop null test before destroy functions
2015-09-13 12:15 ` [PATCH 17/39] md: " Julia Lawall
@ 2015-09-15 7:29 ` Neil Brown
0 siblings, 0 replies; 12+ messages in thread
From: Neil Brown @ 2015-09-15 7:29 UTC (permalink / raw)
To: Julia Lawall
Cc: sergey.senozhatsky, kernel-janitors, linux-raid, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 3464 bytes --]
Julia Lawall <Julia.Lawall@lip6.fr> writes:
> 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 <Julia.Lawall@lip6.fr>
>
> ---
> drivers/md/multipath.c | 3 +--
> drivers/md/raid1.c | 6 ++----
> drivers/md/raid10.c | 9 +++------
> drivers/md/raid5.c | 3 +--
> 4 files changed, 7 insertions(+), 14 deletions(-)
Applied, thanks.
NeilBrown
>
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index 15ef2c6..09a12d7 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -2271,8 +2271,7 @@ static void shrink_stripes(struct r5conf *conf)
> drop_one_stripe(conf))
> ;
>
> - if (conf->slab_cache)
> - kmem_cache_destroy(conf->slab_cache);
> + kmem_cache_destroy(conf->slab_cache);
> conf->slab_cache = NULL;
> }
>
> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index 4517f06..5f4f553 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -2843,8 +2843,7 @@ static struct r1conf *setup_conf(struct mddev *mddev)
>
> abort:
> if (conf) {
> - if (conf->r1bio_pool)
> - mempool_destroy(conf->r1bio_pool);
> + mempool_destroy(conf->r1bio_pool);
> kfree(conf->mirrors);
> safe_put_page(conf->tmppage);
> kfree(conf->poolinfo);
> @@ -2946,8 +2945,7 @@ static void raid1_free(struct mddev *mddev, void *priv)
> {
> struct r1conf *conf = priv;
>
> - if (conf->r1bio_pool)
> - mempool_destroy(conf->r1bio_pool);
> + mempool_destroy(conf->r1bio_pool);
> kfree(conf->mirrors);
> safe_put_page(conf->tmppage);
> kfree(conf->poolinfo);
> diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
> index d222522..d132f06 100644
> --- a/drivers/md/multipath.c
> +++ b/drivers/md/multipath.c
> @@ -470,8 +470,7 @@ static int multipath_run (struct mddev *mddev)
> return 0;
>
> out_free_conf:
> - if (conf->pool)
> - mempool_destroy(conf->pool);
> + mempool_destroy(conf->pool);
> kfree(conf->multipaths);
> kfree(conf);
> mddev->private = NULL;
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index 0fc33eb..7c99a40 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -3486,8 +3486,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
> printk(KERN_ERR "md/raid10:%s: couldn't allocate memory.\n",
> mdname(mddev));
> if (conf) {
> - if (conf->r10bio_pool)
> - mempool_destroy(conf->r10bio_pool);
> + mempool_destroy(conf->r10bio_pool);
> kfree(conf->mirrors);
> safe_put_page(conf->tmppage);
> kfree(conf);
> @@ -3682,8 +3681,7 @@ static int run(struct mddev *mddev)
>
> out_free_conf:
> md_unregister_thread(&mddev->thread);
> - if (conf->r10bio_pool)
> - mempool_destroy(conf->r10bio_pool);
> + mempool_destroy(conf->r10bio_pool);
> safe_put_page(conf->tmppage);
> kfree(conf->mirrors);
> kfree(conf);
> @@ -3696,8 +3694,7 @@ static void raid10_free(struct mddev *mddev, void *priv)
> {
> struct r10conf *conf = priv;
>
> - if (conf->r10bio_pool)
> - mempool_destroy(conf->r10bio_pool);
> + mempool_destroy(conf->r10bio_pool);
> safe_put_page(conf->tmppage);
> kfree(conf->mirrors);
> kfree(conf->mirrors_old);
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 00/39] drop null test before destroy functions
2015-09-13 12:14 [PATCH 00/39] drop null test before destroy functions Julia Lawall
` (2 preceding siblings ...)
2015-09-13 12:15 ` [PATCH 17/39] md: " Julia Lawall
@ 2015-09-14 11:55 ` SF Markus Elfring
3 siblings, 0 replies; 12+ messages in thread
From: SF Markus Elfring @ 2015-09-14 11:55 UTC (permalink / raw)
To: Julia Lawall, kernel-janitors
Cc: iommu, dccp, dri-devel, intel-gfx, ecryptfs, dmaengine,
sergey.senozhatsky, Dan Williams, cluster-devel, intel-wired-lan,
Mitch Williams, John Ronciak, Matthew Vick, Don Skidmore,
Carolyn Wyborny, Shannon Nelson, Jesse Brandeburg, linux-nfs,
linux-raid, netdev, linux-atm-general, linux-btrfs, linux-nilfs,
linux-kernel, linux-mtd, linux-usb
> 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
^ permalink raw reply [flat|nested] 12+ messages in thread