Skip to content

Commit e3139ce

Browse files
maurizio-lombardikeithbusch
authored andcommitted
nvme-core: fix a memory leak in nvme_ns_info_from_identify()
In case of error, free the nvme_id_ns structure that was allocated by nvme_identify_ns(). Signed-off-by: Maurizio Lombardi <mlombard@redhat.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Reviewed-by: Kanchan Joshi <joshi.k@samsung.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 136cfcb commit e3139ce

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: drivers/nvme/host/core.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,8 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl,
14871487
if (id->ncap == 0) {
14881488
/* namespace not allocated or attached */
14891489
info->is_removed = true;
1490-
return -ENODEV;
1490+
ret = -ENODEV;
1491+
goto error;
14911492
}
14921493

14931494
info->anagrpid = id->anagrpid;
@@ -1505,8 +1506,10 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl,
15051506
!memchr_inv(ids->nguid, 0, sizeof(ids->nguid)))
15061507
memcpy(ids->nguid, id->nguid, sizeof(ids->nguid));
15071508
}
1509+
1510+
error:
15081511
kfree(id);
1509-
return 0;
1512+
return ret;
15101513
}
15111514

15121515
static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,

0 commit comments

Comments
 (0)