From: Maurizio Lombardi Date: Thu, 23 Nov 2023 14:07:41 +0000 (+0100) Subject: nvme-core: fix a memory leak in nvme_ns_info_from_identify() X-Git-Tag: v6.6.14~720 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75cc56afb28b0f113f79d8906f7fed9100cea288;p=platform%2Fkernel%2Flinux-starfive.git nvme-core: fix a memory leak in nvme_ns_info_from_identify() [ Upstream commit e3139cef8257fcab1725441e2fd5fd0ccb5481b1 ] In case of error, free the nvme_id_ns structure that was allocated by nvme_identify_ns(). Signed-off-by: Maurizio Lombardi Reviewed-by: Sagi Grimberg Reviewed-by: Kanchan Joshi Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index b32e3cf..2129913 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1479,7 +1479,8 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, if (id->ncap == 0) { /* namespace not allocated or attached */ info->is_removed = true; - return -ENODEV; + ret = -ENODEV; + goto error; } info->anagrpid = id->anagrpid; @@ -1497,8 +1498,10 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, !memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) memcpy(ids->nguid, id->nguid, sizeof(ids->nguid)); } + +error: kfree(id); - return 0; + return ret; } static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl,