summaryrefslogtreecommitdiff
path: root/drivers/nvme
diff options
context:
space:
mode:
authorChaitanya Kulkarni <kch@nvidia.com>2022-12-01 00:33:40 +0300
committerChristoph Hellwig <hch@lst.de>2022-12-06 11:27:24 +0300
commit6c90294d72a99e3ed51516124ba0984e28937d2d (patch)
tree2dcdb3f12cb90186e903d0c9938013bcd4b39161 /drivers/nvme
parentea43fceea4171f29457f8d46543ec320b777c1c7 (diff)
downloadlinux-6c90294d72a99e3ed51516124ba0984e28937d2d.tar.xz
nvme-fc: avoid null pointer dereference
Before using dynamically allcoated variable lsop in the nvme_fc_rcv_ls_req(), add a check for NULL and error out early. Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: James Smart <jsmart2021@gmail.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/nvme')
-rw-r--r--drivers/nvme/host/fc.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 489f5e797204..06bae7150087 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -1754,9 +1754,18 @@ nvme_fc_rcv_ls_req(struct nvme_fc_remote_port *portptr,
}
lsop = kzalloc(sizeof(*lsop), GFP_KERNEL);
+ if (!lsop) {
+ dev_info(lport->dev,
+ "RCV %s LS failed: No memory\n",
+ (w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
+ nvmefc_ls_names[w0->ls_cmd] : "");
+ ret = -ENOMEM;
+ goto out_put;
+ }
+
lsop->rqstbuf = kzalloc(sizeof(*lsop->rqstbuf), GFP_KERNEL);
lsop->rspbuf = kzalloc(sizeof(*lsop->rspbuf), GFP_KERNEL);
- if (!lsop || !lsop->rqstbuf || !lsop->rspbuf) {
+ if (!lsop->rqstbuf || !lsop->rspbuf) {
dev_info(lport->dev,
"RCV %s LS failed: No memory\n",
(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?