nvme-core: fix a memory leak in nvme_ns_info_from_identify()
authorMaurizio Lombardi <mlombard@redhat.com>
Thu, 23 Nov 2023 14:07:41 +0000 (15:07 +0100)
committerKeith Busch <kbusch@kernel.org>
Mon, 27 Nov 2023 18:26:43 +0000 (10:26 -0800)
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>
drivers/nvme/host/core.c

index 8bf24c1cd8bba39591de66a30a7a6ad876b58161..af94d067ac140da8edaa12ecd91350dfc490770f 100644 (file)
@@ -1487,7 +1487,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;
@@ -1505,8 +1506,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,