* [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects
@ 2024-12-16 15:27 Keisuke Nishimura
2024-12-16 15:49 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Keisuke Nishimura @ 2024-12-16 15:27 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 NVME_CSI_NVM is already used. This fix
introduces a new function to handle the error path.
Fixes: cc115cbe12d9 ("nvme: always initialize known command effects")
Signed-off-by: Keisuke Nishimura <keisuke.nishimura@inria.fr>
---
drivers/nvme/host/core.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 758de89b47b4..ce8b70dc45b2 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3173,6 +3173,25 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
return ret;
}
+static int nvme_init_effects_log(struct nvme_ctrl *ctrl,
+ u8 csi, struct nvme_effects_log **log)
+{
+ struct nvme_effects_log *effects, *old;
+
+ effects = kzalloc(sizeof(*effects), GFP_KERNEL);
+ if (effects)
+ return -ENOMEM;
+
+ old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL);
+ if (xa_is_err(old)) {
+ kfree(effects);
+ return xa_err(old);
+ }
+
+ *log = effects;
+ return 0;
+}
+
static void nvme_init_known_nvm_effects(struct nvme_ctrl *ctrl)
{
struct nvme_effects_log *log = ctrl->effects;
@@ -3219,10 +3238,9 @@ static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
}
if (!ctrl->effects) {
- ctrl->effects = kzalloc(sizeof(*ctrl->effects), GFP_KERNEL);
- if (!ctrl->effects)
- return -ENOMEM;
- xa_store(&ctrl->cels, NVME_CSI_NVM, ctrl->effects, GFP_KERNEL);
+ ret = nvme_init_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects);
+ if (ret < 0)
+ return ret;
}
nvme_init_known_nvm_effects(ctrl);
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects
2024-12-16 15:27 [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects Keisuke Nishimura
@ 2024-12-16 15:49 ` Christoph Hellwig
2025-01-10 9:58 ` Keisuke Nishimura
2025-01-10 22:50 ` Sagi Grimberg
2025-01-11 3:56 ` Keith Busch
2 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2024-12-16 15:49 UTC (permalink / raw)
To: Keisuke Nishimura
Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
linux-nvme
On Mon, Dec 16, 2024 at 04:27:20PM +0100, Keisuke Nishimura wrote:
> The xa_store() may fail due to memory allocation failure because there
> is no guarantee that the index NVME_CSI_NVM is already used. This fix
> introduces a new function to handle the error path.
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects
2024-12-16 15:49 ` Christoph Hellwig
@ 2025-01-10 9:58 ` Keisuke Nishimura
0 siblings, 0 replies; 5+ messages in thread
From: Keisuke Nishimura @ 2025-01-10 9:58 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Sagi Grimberg; +Cc: Christoph Hellwig, linux-nvme
On 16/12/2024 16:49, Christoph Hellwig wrote:
> On Mon, Dec 16, 2024 at 04:27:20PM +0100, Keisuke Nishimura wrote:
>> The xa_store() may fail due to memory allocation failure because there
>> is no guarantee that the index NVME_CSI_NVM is already used. This fix
>> introduces a new function to handle the error path.
>
> Looks good:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
This is a gentle ping. Please let me know if there is anything I can do:)
best,
Keisuke
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects
2024-12-16 15:27 [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects Keisuke Nishimura
2024-12-16 15:49 ` Christoph Hellwig
@ 2025-01-10 22:50 ` Sagi Grimberg
2025-01-11 3:56 ` Keith Busch
2 siblings, 0 replies; 5+ messages in thread
From: Sagi Grimberg @ 2025-01-10 22:50 UTC (permalink / raw)
To: Keisuke Nishimura, Keith Busch, Jens Axboe, Christoph Hellwig; +Cc: linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects
2024-12-16 15:27 [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects Keisuke Nishimura
2024-12-16 15:49 ` Christoph Hellwig
2025-01-10 22:50 ` Sagi Grimberg
@ 2025-01-11 3:56 ` Keith Busch
2 siblings, 0 replies; 5+ messages in thread
From: Keith Busch @ 2025-01-11 3:56 UTC (permalink / raw)
To: Keisuke Nishimura
Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg, linux-nvme
On Mon, Dec 16, 2024 at 04:27:20PM +0100, Keisuke Nishimura wrote:
> The xa_store() may fail due to memory allocation failure because there
> is no guarantee that the index NVME_CSI_NVM is already used. This fix
> introduces a new function to handle the error path.
>
> Fixes: cc115cbe12d9 ("nvme: always initialize known command effects")
> Signed-off-by: Keisuke Nishimura <keisuke.nishimura@inria.fr>
Queued up in nvme-6.14, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-11 3:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-16 15:27 [PATCH v2] nvme: Add error path for xa_store in nvme_init_effects Keisuke Nishimura
2024-12-16 15:49 ` Christoph Hellwig
2025-01-10 9:58 ` Keisuke Nishimura
2025-01-10 22:50 ` Sagi Grimberg
2025-01-11 3:56 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox