mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: cxlflash: Fix null pointer dereference in ocxlflash_get_fd
@ 2023-11-27  2:51 Kunwu Chan
  2024-01-17 21:24 ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Kunwu Chan @ 2023-11-27  2:51 UTC (permalink / raw)
  To: manoj, mrochs, ukrishn, jejb, martin.petersen
  Cc: kunwu.chan, linux-scsi, linux-kernel, Kunwu Chan

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] scsi: cxlflash: Fix null pointer dereference in ocxlflash_get_fd
  2023-11-27  2:51 [PATCH] scsi: cxlflash: Fix null pointer dereference in ocxlflash_get_fd Kunwu Chan
@ 2024-01-17 21:24 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2024-01-17 21:24 UTC (permalink / raw)
  To: Kunwu Chan, linux-scsi, kernel-janitors, James E. J. Bottomley,
	Manoj N. Kumar, Matthew R. Ochs, Uma Krishnan,
	Martin K. Petersen
  Cc: LKML, Kunwu Chan

> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
…
> +++ 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;
> +	}
…

How do you think about to omit the extra error message?

Regards,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-17 21:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-27  2:51 [PATCH] scsi: cxlflash: Fix null pointer dereference in ocxlflash_get_fd Kunwu Chan
2024-01-17 21:24 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®