From: Chaitanya Kulkarni Date: Wed, 30 Nov 2022 21:33:40 +0000 (-0800) Subject: nvme-fc: avoid null pointer dereference X-Git-Tag: v6.6.17~5962^2~4^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c90294d72a99e3ed51516124ba0984e28937d2d;p=platform%2Fkernel%2Flinux-rpi.git 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 Reviewed-by: James Smart Signed-off-by: Christoph Hellwig --- diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index 489f5e7..06bae71 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) ?