diff mbox series

ndtest: Remove redundant NULL check

Message ID 1616407240-114077-1-git-send-email-jiapeng.chong@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series ndtest: Remove redundant NULL check | expand

Commit Message

Jiapeng Chong March 22, 2021, 10 a.m. UTC
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(-)

Comments

Ira Weiny March 22, 2021, 8:20 p.m. UTC | #1
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
>
Santosh Sivaraj March 23, 2021, 2:30 a.m. UTC | #2
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
>>
diff mbox series

Patch

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;