From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754499AbbINOAo (ORCPT ); Mon, 14 Sep 2015 10:00:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51524 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751302AbbINOAm (ORCPT ); Mon, 14 Sep 2015 10:00:42 -0400 Date: Mon, 14 Sep 2015 10:00:40 -0400 From: Mike Snitzer To: Mikulas Patocka Cc: device-mapper development , Alasdair Kergon , kernel-janitors@vger.kernel.org, Neil Brown , linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, sergey.senozhatsky@gmail.com Subject: Re: [PATCH 12/39] dm: drop null test before destroy functions Message-ID: <20150914140040.GA11815@redhat.com> References: <1442146532-9100-1-git-send-email-Julia.Lawall@lip6.fr> <1442146532-9100-13-git-send-email-Julia.Lawall@lip6.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 14 2015 at 9:46am -0400, Mikulas Patocka 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/) > > > > // > > @@ expression x; @@ > > -if (x != NULL) > > \(kmem_cache_destroy\|mempool_destroy\|dma_pool_destroy\)(x); > > // > > > > Signed-off-by: Julia Lawall > > > > --- > > 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Snitzer Date: Mon, 14 Sep 2015 14:00:40 +0000 Subject: Re: [PATCH 12/39] dm: drop null test before destroy functions Message-Id: <20150914140040.GA11815@redhat.com> List-Id: References: <1442146532-9100-1-git-send-email-Julia.Lawall@lip6.fr> <1442146532-9100-13-git-send-email-Julia.Lawall@lip6.fr> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Mikulas Patocka Cc: device-mapper development , Alasdair Kergon , kernel-janitors@vger.kernel.org, Neil Brown , linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, sergey.senozhatsky@gmail.com On Mon, Sep 14 2015 at 9:46am -0400, Mikulas Patocka 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/) > > > > // > > @@ expression x; @@ > > -if (x != NULL) > > \(kmem_cache_destroy\|mempool_destroy\|dma_pool_destroy\)(x); > > // > > > > Signed-off-by: Julia Lawall > > > > --- > > 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