nvme: fix memory leak freeing command effects
Keith Busch
maintainerPATCH 1/1 nvme: fix memory leak freeing command effects
xa_destroy() frees only internal data. The caller is responsible for freeing the exteranl objects referenced by an xarray.
--- drivers/nvme/host/core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +14 -2
@@ -4398,6 +4398,19 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) }EXPORT_SYMBOL_GPL (nvme_uninit_ctrl); +static void nvme_free_cels (struct nvme_ctrl *ctrl) +{ +struct nvme_effects_log *cel; +unsigned long i; + + xa_for_each (&ctrl->cels, i, cel) { +xa_erase (&ctrl->cels, i); +kfree (cel); + } + +xa_destroy (&ctrl->cels); +} +static void nvme_free_ctrl (struct device *dev) { struct nvme_ctrl *ctrl =
@@ -4407,8 +4420,7 @@ static void nvme_free_ctrl(struct device *dev)if (!subsys || ctrl->instance != subsys->instance)ida_simple_remove (&nvme_instance_ida, ctrl->instance); -xa_destroy (&ctrl->cels); - +nvme_free_cels (ctrl);nvme_mpath_uninit (ctrl);__free_page (ctrl->discard_page);
Signature · 7 lines
2.24.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks, applied to nvme-5.10.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 6 lines · Keith Busch
xa_destroy()frees only internal data. The caller is responsible for freeing the exteranl objects referenced by an xarray.Fixes 1cf7a12e09aa4 ("nvme: use an xarray to lookup the Commands Supported and Effects log")Signed-off-by Keith Busch <[email protected]>---
Thanks for fixing this up, it'd nice to have a common helper
which also erases the itmes from XArray so we don't have to
repeat the code to erase item indivisually.
I'll see if I can send an RFC.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerQuoted 11 lines · Chaitanya Kulkarni
Quoted 6 lines · Keith Busch
xa_destroy()frees only internal data. The caller is responsible for freeing the exteranl objects referenced by an xarray.Fixes 1cf7a12e09aa4 ("nvme: use an xarray to lookup the Commands Supported and Effects log")Signed-off-by Keith Busch <[email protected]>---
Thanks for fixing this up, it'd nice to have a common helper which also erases the itmes from XArray so we don't have to repeat the code to erase item indivisually.
That would be okay if there are multiple users that have a simple kfree() on their elements when tearing down their xarray, but I'm not finding others so far.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme