Skip to contentSkip to conversation

nvdimm/pmem: Fix leak on dax_add_host() failure

PATCH Superseded Mathieu Desnoyers 3 participants 3 messages Feb 12, 2024

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvdimm/pmem: Fix leak on dax_add_host() failure

Fix a leak on dax_add_host() error, where "goto out_cleanup_dax" is done before setting pmem->dax_dev, which therefore issues the two following calls on NULL pointers:

out_cleanup_dax:

        kill_dax(pmem->dax_dev);
        put_dax(pmem->dax_dev);
---
 drivers/nvdimm/pmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvdimm/pmem.c +1 -2
index 4e8fdcb3f1c8..9fe358090720 100644
@@ -566,12 +566,11 @@ static int pmem_attach_disk(struct device *dev,
 	set_dax_nomc(dax_dev);
 	if (is_nvdimm_sync(nd_region))
 		set_dax_synchronous(dax_dev);
+	pmem->dax_dev = dax_dev;
 	rc = dax_add_host(dax_dev, disk);
 	if (rc)
 		goto out_cleanup_dax;
 	dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
-	pmem->dax_dev = dax_dev;
-
 	rc = device_add_disk(dev, disk, pmem_attribute_groups);
 	if (rc)
 		goto out_remove_host;
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Mathieu Desnoyers

Fix a leak on dax_add_host() error, where "goto out_cleanup_dax" is done before setting pmem->dax_dev, which therefore issues the two following calls on NULL pointers:

out_cleanup_dax:

        kill_dax(pmem->dax_dev);
        put_dax(pmem->dax_dev);
Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Mikulas Patocka <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Dan Williams <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Arnd Bergmann <[email protected]>
Quoted 8 lines
Quoted 22 lines
---
 drivers/nvdimm/pmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvdimm/pmem.c +1 -2
index 4e8fdcb3f1c8..9fe358090720 100644
@@ -566,12 +566,11 @@ static int pmem_attach_disk(struct device *dev,
 	set_dax_nomc(dax_dev);
 	if (is_nvdimm_sync(nd_region))
 		set_dax_synchronous(dax_dev);
+	pmem->dax_dev = dax_dev;
 	rc = dax_add_host(dax_dev, disk);
 	if (rc)
 		goto out_cleanup_dax;
 	dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
-	pmem->dax_dev = dax_dev;
-
 	rc = device_add_disk(dev, disk, pmem_attribute_groups);
 	if (rc)
 		goto out_remove_host;
Reviewed-by Fan Ni on v1 1/1
#2 lore raw
In reply to Mathieu Desnoyers
Quoted 20 lines · Mathieu Desnoyers

Fix a leak on dax_add_host() error, where "goto out_cleanup_dax" is done before setting pmem->dax_dev, which therefore issues the two following calls on NULL pointers:

out_cleanup_dax:

        kill_dax(pmem->dax_dev);
        put_dax(pmem->dax_dev);
Cc Alasdair Kergon <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Mikulas Patocka <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Dan Williams <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Arnd Bergmann <[email protected]>
Quoted 8 lines
Quoted 25 lines
---
 drivers/nvdimm/pmem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvdimm/pmem.c +1 -2
index 4e8fdcb3f1c8..9fe358090720 100644
@@ -566,12 +566,11 @@ static int pmem_attach_disk(struct device *dev,
 	set_dax_nomc(dax_dev);
 	if (is_nvdimm_sync(nd_region))
 		set_dax_synchronous(dax_dev);
+	pmem->dax_dev = dax_dev;
 	rc = dax_add_host(dax_dev, disk);
 	if (rc)
 		goto out_cleanup_dax;
 	dax_write_cache(dax_dev, nvdimm_has_cache(nd_region));
-	pmem->dax_dev = dax_dev;
-
 	rc = device_add_disk(dev, disk, pmem_attribute_groups);
 	if (rc)
 		goto out_remove_host;
Signature · 1 line
2.39.2