Skip to contentSkip to conversation

nvdimm: nfit: remove redundant NULL check before vfree()

PATCH Applied [email protected] 3 participants 3 messages Jul 3 – Jul 15 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvdimm: nfit: remove redundant NULL check before vfree()

From: Mohammad Shahid <[email protected]>

vfree() safely handles NULL pointers, so the explicit NULL check before calling vfree() is unnecessary.

This issue was reported by ifnullfree.cocci.

---
 tools/testing/nvdimm/test/nfit.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/nvdimm/test/nfit.c +1 -2
index f87e9f251d13..009fe107b0d7 100644
@@ -1644,8 +1644,7 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
  err:
 	if (*dma && size >= DIMM_SIZE)
 		gen_pool_free(nfit_pool, *dma, size);
-	if (buf)
-		vfree(buf);
+	vfree(buf);
 	kfree(nfit_res);
 	return NULL;
 }
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On 7/3/26 7:48 AM, [email protected] wrote:

From: Mohammad Shahid <[email protected]>

vfree() safely handles NULL pointers, so the explicit NULL check before calling vfree() is unnecessary.

This issue was reported by ifnullfree.cocci.

Quoted 18 lines
---
 tools/testing/nvdimm/test/nfit.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/nvdimm/test/nfit.c +1 -2
index f87e9f251d13..009fe107b0d7 100644
@@ -1644,8 +1644,7 @@ static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
  err:
 	if (*dma && size >= DIMM_SIZE)
 		gen_pool_free(nfit_pool, *dma, size);
-	if (buf)
-		vfree(buf);
+	vfree(buf);
 	kfree(nfit_res);
 	return NULL;
 }
maintainer Applied
#2 lore raw
In reply to [email protected]
Quoted 8 lines · On Fri, Jul 03, 2026 at 08:18:51PM +0530, [email protected] wrote:

From: Mohammad Shahid <[email protected]>

vfree() safely handles NULL pointers, so the explicit NULL check before calling vfree() is unnecessary.

This issue was reported by ifnullfree.cocci.

Applied to libnvdimm-for-next:
https://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm.git/