Skip to content

Commit d4a95ad

Browse files
mu-mu-mukeithbusch
authored andcommitted
nvme: Add error path for xa_store in nvme_init_effects
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: cc115cb ("nvme: always initialize known command effects") Signed-off-by: Keisuke Nishimura <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent e4a0a30 commit d4a95ad

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

drivers/nvme/host/core.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,6 +3175,25 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
31753175
return ret;
31763176
}
31773177

3178+
static int nvme_init_effects_log(struct nvme_ctrl *ctrl,
3179+
u8 csi, struct nvme_effects_log **log)
3180+
{
3181+
struct nvme_effects_log *effects, *old;
3182+
3183+
effects = kzalloc(sizeof(*effects), GFP_KERNEL);
3184+
if (effects)
3185+
return -ENOMEM;
3186+
3187+
old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL);
3188+
if (xa_is_err(old)) {
3189+
kfree(effects);
3190+
return xa_err(old);
3191+
}
3192+
3193+
*log = effects;
3194+
return 0;
3195+
}
3196+
31783197
static void nvme_init_known_nvm_effects(struct nvme_ctrl *ctrl)
31793198
{
31803199
struct nvme_effects_log *log = ctrl->effects;
@@ -3221,10 +3240,9 @@ static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
32213240
}
32223241

32233242
if (!ctrl->effects) {
3224-
ctrl->effects = kzalloc(sizeof(*ctrl->effects), GFP_KERNEL);
3225-
if (!ctrl->effects)
3226-
return -ENOMEM;
3227-
xa_store(&ctrl->cels, NVME_CSI_NVM, ctrl->effects, GFP_KERNEL);
3243+
ret = nvme_init_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects);
3244+
if (ret < 0)
3245+
return ret;
32283246
}
32293247

32303248
nvme_init_known_nvm_effects(ctrl);

0 commit comments

Comments
 (0)