public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] nvme: Allocate memory for xa_store in advance in nvme_get_effects_log
@ 2024-12-02 12:42 Keisuke Nishimura
  2024-12-12  6:27 ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Keisuke Nishimura @ 2024-12-02 12:42 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
  Cc: linux-nvme, Keisuke Nishimura

The xa_store() may fail due to memory allocation failure because there
is no guarantee that the index csi is already used. This code allocates
the memory in advance to ensure the xa_store() succeeds before
nvme_get_log().

Fixes: 1cf7a12e09aa ("nvme: use an xarray to lookup the Commands Supported and Effects log")
Signed-off-by: Keisuke Nishimura <keisuke.nishimura@inria.fr>
---
 drivers/nvme/host/core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1a8d32a4a5c3..758de89b47b4 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3098,6 +3098,12 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
 	if (!cel)
 		return -ENOMEM;
 
+	ret = xa_reserve(&ctrl->cels, csi, GFP_KERNEL);
+	if (ret) {
+		kfree(cel);
+		return ret;
+	}
+
 	ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi,
 			cel, sizeof(*cel), 0);
 	if (ret) {
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-01-07 17:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-02 12:42 [PATCH] nvme: Allocate memory for xa_store in advance in nvme_get_effects_log Keisuke Nishimura
2024-12-12  6:27 ` Christoph Hellwig
2024-12-16 13:06   ` Keisuke Nishimura
2024-12-16 15:52     ` Christoph Hellwig
2024-12-20 11:50       ` Keisuke Nishimura
2024-12-20 12:00       ` [PATCH] nvme: Add error check for xa_store " Keisuke Nishimura
2024-12-24 10:11         ` Sagi Grimberg
2025-01-03  6:52         ` Christoph Hellwig
2025-01-07 16:48         ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox