Skip to content

Commit 8168d23

Browse files
keithbuschChristoph Hellwig
authored andcommitted
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. Fixes: 1cf7a12 ("nvme: use an xarray to lookup the Commands Supported and Effects log") Signed-off-by: Keith Busch <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent f6224b8 commit 8168d23

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,6 +4373,19 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
43734373
}
43744374
EXPORT_SYMBOL_GPL(nvme_uninit_ctrl);
43754375

4376+
static void nvme_free_cels(struct nvme_ctrl *ctrl)
4377+
{
4378+
struct nvme_effects_log *cel;
4379+
unsigned long i;
4380+
4381+
xa_for_each (&ctrl->cels, i, cel) {
4382+
xa_erase(&ctrl->cels, i);
4383+
kfree(cel);
4384+
}
4385+
4386+
xa_destroy(&ctrl->cels);
4387+
}
4388+
43764389
static void nvme_free_ctrl(struct device *dev)
43774390
{
43784391
struct nvme_ctrl *ctrl =
@@ -4382,8 +4395,7 @@ static void nvme_free_ctrl(struct device *dev)
43824395
if (!subsys || ctrl->instance != subsys->instance)
43834396
ida_simple_remove(&nvme_instance_ida, ctrl->instance);
43844397

4385-
xa_destroy(&ctrl->cels);
4386-
4398+
nvme_free_cels(ctrl);
43874399
nvme_mpath_uninit(ctrl);
43884400
__free_page(ctrl->discard_page);
43894401

0 commit comments

Comments
 (0)