Skip to content

Commit ac32057

Browse files
mu-mu-mukeithbusch
authored andcommitted
nvme: Add error check for xa_store in nvme_get_effects_log
The xa_store() may fail due to memory allocation failure because there is no guarantee that the index csi is already used. This fix adds an error check of the return value of xa_store() in nvme_get_effects_log(). Fixes: 1cf7a12 ("nvme: use an xarray to lookup the Commands Supported and Effects log") Signed-off-by: Keisuke Nishimura <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 3219378 commit ac32057

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,7 +3092,7 @@ int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
30923092
static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
30933093
struct nvme_effects_log **log)
30943094
{
3095-
struct nvme_effects_log *cel = xa_load(&ctrl->cels, csi);
3095+
struct nvme_effects_log *old, *cel = xa_load(&ctrl->cels, csi);
30963096
int ret;
30973097

30983098
if (cel)
@@ -3109,7 +3109,11 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
31093109
return ret;
31103110
}
31113111

3112-
xa_store(&ctrl->cels, csi, cel, GFP_KERNEL);
3112+
old = xa_store(&ctrl->cels, csi, cel, GFP_KERNEL);
3113+
if (xa_is_err(old)) {
3114+
kfree(cel);
3115+
return xa_err(old);
3116+
}
31133117
out:
31143118
*log = cel;
31153119
return 0;

0 commit comments

Comments
 (0)