Skip to contentSkip to conversation

ndtest: Remove redundant NULL check

PATCH In review Jiapeng Chong 3 participants 3 messages Mar 22, 2021 – Mar 23, 2021 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ndtest: Remove redundant NULL check

Fix the following coccicheck warnings:

./tools/testing/nvdimm/test/ndtest.c:491:2-7: WARNING: NULL check before some freeing functions is not needed.

---
 tools/testing/nvdimm/test/ndtest.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/nvdimm/test/ndtest.c +1 -2
index 6862915..98b4a43 100644
@@ -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;
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#1 lore raw
Quoted 4 lines · 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.

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

Quoted 24 lines
---
 tools/testing/nvdimm/test/ndtest.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/nvdimm/test/ndtest.c +1 -2
index 6862915..98b4a43 100644
@@ -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;
Signature · 1 line
1.8.3.1

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]

#2 lore raw

Hi Ira,

Quoted 12 lines · Ira Weiny
Quoted 4 lines · 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.

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

Quoted 22 lines

Ira

Quoted 20 lines
---
 tools/testing/nvdimm/test/ndtest.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/nvdimm/test/ndtest.c +1 -2
index 6862915..98b4a43 100644
@@ -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);
 
Quoted 4 lines
Quoted 4 lines
tools/testing/nvdimm/test/ndtest.c +0 -0
 	return NULL;
Signature · 1 line
1.8.3.1

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]