All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kunwu Chan <chentao@kylinos.cn>
To: manoj@linux.ibm.com, mrochs@linux.ibm.com, ukrishn@linux.ibm.com,
	jejb@linux.ibm.com, martin.petersen@oracle.com
Cc: kunwu.chan@hotmail.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org, Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH] scsi: cxlflash: Fix null pointer dereference in ocxlflash_get_fd
Date: Mon, 27 Nov 2023 10:51:27 +0800	[thread overview]
Message-ID: <20231127025127.1545877-1-chentao@kylinos.cn> (raw)

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: 926a62f9bd53 ("scsi: cxlflash: Support adapter file descriptors for OCXL")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/scsi/cxlflash/ocxl_hw.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/scsi/cxlflash/ocxl_hw.c b/drivers/scsi/cxlflash/ocxl_hw.c
index 6542818e595a..aa5703a69bc0 100644
--- a/drivers/scsi/cxlflash/ocxl_hw.c
+++ b/drivers/scsi/cxlflash/ocxl_hw.c
@@ -1231,6 +1231,11 @@ static struct file *ocxlflash_get_fd(void *ctx_cookie,
 		fops = (struct file_operations *)&ocxl_afu_fops;
 
 	name = kasprintf(GFP_KERNEL, "ocxlflash:%d", ctx->pe);
+	if (!name) {
+		rc = -ENOMEM;
+		dev_err(dev, "%s: kasprintf allocation failed\n", __func__);
+		goto err2;
+	}
 	file = ocxlflash_getfile(dev, name, fops, ctx, flags);
 	kfree(name);
 	if (IS_ERR(file)) {
-- 
2.34.1


             reply	other threads:[~2023-11-27  2:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-27  2:51 Kunwu Chan [this message]
2024-01-17 21:24 ` [PATCH] scsi: cxlflash: Fix null pointer dereference in ocxlflash_get_fd Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231127025127.1545877-1-chentao@kylinos.cn \
    --to=chentao@kylinos.cn \
    --cc=jejb@linux.ibm.com \
    --cc=kunwu.chan@hotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=manoj@linux.ibm.com \
    --cc=martin.petersen@oracle.com \
    --cc=mrochs@linux.ibm.com \
    --cc=ukrishn@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.