[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231127025127.1545877-1-chentao@kylinos.cn>
Date:   Mon, 27 Nov 2023 10:51:27 +0800
From:   Kunwu Chan <chentao@...inos.cn>
To:     manoj@...ux.ibm.com, mrochs@...ux.ibm.com, ukrishn@...ux.ibm.com,
        jejb@...ux.ibm.com, martin.petersen@...cle.com
Cc:     kunwu.chan@...mail.com, linux-scsi@...r.kernel.org,
        linux-kernel@...r.kernel.org, Kunwu Chan <chentao@...inos.cn>
Subject: [PATCH] scsi: cxlflash: Fix null pointer dereference in ocxlflash_get_fd
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@...inos.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
Powered by blists - more mailing lists
 
