Skip to contentSkip to conversation

nvme-core: fix a memory leak in nvme_ns_info_from_identify()

PATCH Applied Maurizio Lombardi 4 participants 4 messages Nov 23, 2023 – Nov 27, 2023 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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().

---
 drivers/nvme/host/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +5 -2
index 88b54cdcbd68..d7f90a4475d5 100644
@@ -1480,7 +1480,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;
@@ -1498,8 +1499,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,
Signature · 1 line
2.39.3
maintainer Applied
#3 lore raw
In reply to Maurizio Lombardi
Quoted 2 lines · Maurizio Lombardi

In case of error, free the nvme_id_ns structure that was allocated by nvme_identify_ns().

Thanks, applied to nvme-6.7.