Skip to contentSkip to conversation

nvdimm: Call ida_simple_remove() when failed

PATCH In review Bo Liu 2 participants 2 messages Aug 10, 2022 – Sep 20, 2022 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Bo Liu

author
#0 lore raw

PATCH 1/1 nvdimm: Call ida_simple_remove() when failed

In function nvdimm_bus_register(), when code execution fails, we should call ida_simple_remove() to free ida.

---
 drivers/nvdimm/bus.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvdimm/bus.c +1 -0
index b38d0355b0ac..3415dc62632b 100644
@@ -371,6 +371,7 @@ struct nvdimm_bus *nvdimm_bus_register(struct device *parent,
 	return nvdimm_bus;
  err:
 	put_device(&nvdimm_bus->dev);
+	ida_simple_remove(&nd_ida, nvdimm_bus->id);
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(nvdimm_bus_register);
Signature · 1 line
2.27.0
#1 lore raw
Quoted 13 lines · Bo Liu

In function nvdimm_bus_register(), when code execution fails, we should call ida_simple_remove() to free ida.

---
 drivers/nvdimm/bus.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvdimm/bus.c +0 -0
index b38d0355b0ac..3415dc62632b 100644

drivers/nvdimm/bus.c struct nvdimm_bus *nvdimm_bus_register(struct device *parent, · line 374

Quoted 4 lines
drivers/nvdimm/bus.c +1 -0
@@ -371,6 +371,7 @@ struct nvdimm_bus *nvdimm_bus_register(struct device *parent,
 	return nvdimm_bus;
  err:
 	put_device(&nvdimm_bus->dev);
+	ida_simple_remove(&nd_ida, nvdimm_bus->id);

No, this is a double-free. The put_device() will trigger nvdimm_bus_release().