diff mbox series

nvdimm: Call ida_simple_remove() when failed

Message ID 20220810060737.5087-1-liubo03@inspur.com (mailing list archive)
State New, archived
Headers show
Series nvdimm: Call ida_simple_remove() when failed | expand

Commit Message

Bo Liu Aug. 10, 2022, 6:07 a.m. UTC
In function nvdimm_bus_register(), when code execution fails, we should
call ida_simple_remove() to free ida.

Signed-off-by: Bo Liu <liubo03@inspur.com>
---
 drivers/nvdimm/bus.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Dan Williams Sept. 20, 2022, 5:32 p.m. UTC | #1
Bo Liu wrote:
> In function nvdimm_bus_register(), when code execution fails, we should
> call ida_simple_remove() to free ida.
> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
>  drivers/nvdimm/bus.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
> index b38d0355b0ac..3415dc62632b 100644
> --- a/drivers/nvdimm/bus.c
> +++ b/drivers/nvdimm/bus.c
> @@ -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().
diff mbox series

Patch

diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index b38d0355b0ac..3415dc62632b 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -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);