* [PATCH] ndtest: Remove redundant NULL check
@ 2021-03-22 10:00 Jiapeng Chong
2021-03-22 20:20 ` Ira Weiny
0 siblings, 1 reply; 5+ messages in thread
From: Jiapeng Chong @ 2021-03-22 10:00 UTC (permalink / raw
To: dan.j.williams
Cc: vishal.l.verma, dave.jiang, ira.weiny, linux-nvdimm, linux-kernel,
Jiapeng Chong
Fix the following coccicheck warnings:
./tools/testing/nvdimm/test/ndtest.c:491:2-7: WARNING: NULL check before
some freeing functions is not needed.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
tools/testing/nvdimm/test/ndtest.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
index 6862915..98b4a43 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -487,8 +487,7 @@ static void *ndtest_alloc_resource(struct ndtest_priv *p, size_t size,
buf_err:
if (__dma && size >= DIMM_SIZE)
gen_pool_free(ndtest_pool, __dma, size);
- if (buf)
- vfree(buf);
+ vfree(buf);
kfree(res);
return NULL;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ndtest: Remove redundant NULL check
2021-03-22 10:00 [PATCH] ndtest: Remove redundant NULL check Jiapeng Chong
@ 2021-03-22 20:20 ` Ira Weiny
2021-03-23 2:30 ` Santosh Sivaraj
0 siblings, 1 reply; 5+ messages in thread
From: Ira Weiny @ 2021-03-22 20:20 UTC (permalink / raw
To: Jiapeng Chong
Cc: dan.j.williams, vishal.l.verma, dave.jiang, linux-nvdimm,
linux-kernel, Santosh Sivaraj
On Mon, Mar 22, 2021 at 06:00:40PM +0800, Jiapeng Chong wrote:
> Fix the following coccicheck warnings:
>
> ./tools/testing/nvdimm/test/ndtest.c:491:2-7: WARNING: NULL check before
> some freeing functions is not needed.
I don't think there is anything wrong with this patch specifically but why is
buf not checked for null after the vmalloc?
It seems to me that if size >= DIMM_SIZE and the vmalloc fails the gen pool
allocation is going to be leaked.
Ira
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> tools/testing/nvdimm/test/ndtest.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
> index 6862915..98b4a43 100644
> --- a/tools/testing/nvdimm/test/ndtest.c
> +++ b/tools/testing/nvdimm/test/ndtest.c
> @@ -487,8 +487,7 @@ static void *ndtest_alloc_resource(struct ndtest_priv *p, size_t size,
> buf_err:
> if (__dma && size >= DIMM_SIZE)
> gen_pool_free(ndtest_pool, __dma, size);
> - if (buf)
> - vfree(buf);
> + vfree(buf);
> kfree(res);
>
> return NULL;
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ndtest: Remove redundant NULL check
2021-03-22 20:20 ` Ira Weiny
@ 2021-03-23 2:30 ` Santosh Sivaraj
0 siblings, 0 replies; 5+ messages in thread
From: Santosh Sivaraj @ 2021-03-23 2:30 UTC (permalink / raw
To: Ira Weiny, Jiapeng Chong
Cc: dan.j.williams, vishal.l.verma, dave.jiang, linux-nvdimm,
linux-kernel
Hi Ira,
Ira Weiny <ira.weiny@intel.com> writes:
> On Mon, Mar 22, 2021 at 06:00:40PM +0800, Jiapeng Chong wrote:
>> Fix the following coccicheck warnings:
>>
>> ./tools/testing/nvdimm/test/ndtest.c:491:2-7: WARNING: NULL check before
>> some freeing functions is not needed.
>
> I don't think there is anything wrong with this patch specifically but why is
> buf not checked for null after the vmalloc?
>
> It seems to me that if size >= DIMM_SIZE and the vmalloc fails the gen pool
> allocation is going to be leaked.
>
If vmalloc fails, gen_pool_free will get called through ndtest_release_resource,
registered with devm_action. But we will still need to check for vmalloc fail.
I will fix that when I send my inject-error support for the driver.
Thanks,
Santosh
> Ira
>
>>
>> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
>> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
>> ---
>> tools/testing/nvdimm/test/ndtest.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
>> index 6862915..98b4a43 100644
>> --- a/tools/testing/nvdimm/test/ndtest.c
>> +++ b/tools/testing/nvdimm/test/ndtest.c
>> @@ -487,8 +487,7 @@ static void *ndtest_alloc_resource(struct ndtest_priv *p, size_t size,
>> buf_err:
>> if (__dma && size >= DIMM_SIZE)
>> gen_pool_free(ndtest_pool, __dma, size);
>> - if (buf)
>> - vfree(buf);
>> + vfree(buf);
>> kfree(res);
>>
>> return NULL;
>> --
>> 1.8.3.1
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] ndtest: Remove redundant NULL check
@ 2022-11-13 11:26 Kang Minchul
2022-11-13 11:32 ` Kang Minchul
0 siblings, 1 reply; 5+ messages in thread
From: Kang Minchul @ 2022-11-13 11:26 UTC (permalink / raw
To: Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny
Cc: nvdimm, linux-kernel, Kang Minchul
This addresses cocci warning as follows:
WARNING: NULL check before some freeing functions is not needed.
Signed-off-by: Kang Minchul <tegongkang@gmail.com>
---
tools/testing/nvdimm/test/ndtest.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
index 01ceb98c15a0..de4bc34bc47b 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -370,8 +370,7 @@ static void *ndtest_alloc_resource(struct ndtest_priv *p, size_t size,
buf_err:
if (__dma && size >= DIMM_SIZE)
gen_pool_free(ndtest_pool, __dma, size);
- if (buf)
- vfree(buf);
+ vfree(buf);
kfree(res);
return NULL;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ndtest: Remove redundant NULL check
2022-11-13 11:26 Kang Minchul
@ 2022-11-13 11:32 ` Kang Minchul
0 siblings, 0 replies; 5+ messages in thread
From: Kang Minchul @ 2022-11-13 11:32 UTC (permalink / raw
To: Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny; +Cc: nvdimm, linux-kernel
2022년 11월 13일 (일) 오후 8:26, Kang Minchul <tegongkang@gmail.com>님이 작성:
>
> This addresses cocci warning as follows:
> WARNING: NULL check before some freeing functions is not needed.
>
> Signed-off-by: Kang Minchul <tegongkang@gmail.com>
> ---
> tools/testing/nvdimm/test/ndtest.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
> index 01ceb98c15a0..de4bc34bc47b 100644
> --- a/tools/testing/nvdimm/test/ndtest.c
> +++ b/tools/testing/nvdimm/test/ndtest.c
> @@ -370,8 +370,7 @@ static void *ndtest_alloc_resource(struct ndtest_priv *p, size_t size,
> buf_err:
> if (__dma && size >= DIMM_SIZE)
> gen_pool_free(ndtest_pool, __dma, size);
> - if (buf)
> - vfree(buf);
> + vfree(buf);
> kfree(res);
>
> return NULL;
> --
> 2.34.1
>
I just found an earlier discussion about the same patch as mine.
Please ignore this patch.
Thanks.
Kang Minchul
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-13 11:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-22 10:00 [PATCH] ndtest: Remove redundant NULL check Jiapeng Chong
2021-03-22 20:20 ` Ira Weiny
2021-03-23 2:30 ` Santosh Sivaraj
-- strict thread matches above, loose matches on Subject: below --
2022-11-13 11:26 Kang Minchul
2022-11-13 11:32 ` Kang Minchul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).