Commit 9864ae0b authored by Keisuke Nishimura's avatar Keisuke Nishimura Committed by Jingtong Meng
Browse files

nvme: Add error check for xa_store in nvme_get_effects_log

stable inclusion
from stable-v6.6.76
commit 48ef61d25e7998873bac69de1152daf84bfe4226
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBS4SF

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.6.y&id=48ef61d25e7998873bac69de1152daf84bfe4226



--------------------------------

[ Upstream commit ac32057acc7f3d7a238dafaa9b2aa2bc9750080e ]

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: 1cf7a12e ("nvme: use an xarray to lookup the Commands Supported and Effects log")
Signed-off-by: default avatarKeisuke Nishimura <keisuke.nishimura@inria.fr>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarJingtong Meng <jingtong.meng@windriver.com>
parent 3a20dc05
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -2853,7 +2853,7 @@ int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi,
static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
				struct nvme_effects_log **log)
{
	struct nvme_effects_log	*cel = xa_load(&ctrl->cels, csi);
	struct nvme_effects_log *old, *cel = xa_load(&ctrl->cels, csi);
	int ret;

	if (cel)
@@ -2870,7 +2870,11 @@ static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi,
		return ret;
	}

	xa_store(&ctrl->cels, csi, cel, GFP_KERNEL);
	old = xa_store(&ctrl->cels, csi, cel, GFP_KERNEL);
	if (xa_is_err(old)) {
		kfree(cel);
		return xa_err(old);
	}
out:
	*log = cel;
	return 0;