Skip to contentSkip to conversation

uio: uio_fsl_elbc_gpcm: Add NULL check in the uio_fsl_elbc_gpcm_probe

PATCH Superseded Henry Martin 3 participants 4 messages Mar 31, 2025 – Apr 1, 2025 Userspace I/O (UIO)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uio: uio_fsl_elbc_gpcm: Add NULL check in the uio_fsl_elbc_gpcm_probe

When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function uio_fsl_elbc_gpcm_probe.

A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error.

Fixes d57801c45f53e ("uio: uio_fsl_elbc_gpcm: use device-managed allocators")
---
 drivers/uio/uio_fsl_elbc_gpcm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/uio/uio_fsl_elbc_gpcm.c +4 -0
index 81454c3e2484..59ba1a2dcfe3 100644
@@ -384,6 +384,10 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev)
 
 	/* set all UIO data */
 	info->mem[0].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn", node);
+	if (!info->mem[0].name) {
+		dev_err(priv->dev, "devm_kasprintf failed for region name\n");
+		return -ENOMEM;
+	}
 	info->mem[0].addr = res.start;
 	info->mem[0].size = resource_size(&res);
 	info->mem[0].memtype = UIO_MEM_PHYS;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 6 lines · Henry Martin

When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function uio_fsl_elbc_gpcm_probe.

A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error.

Fixes d57801c45f53e ("uio: uio_fsl_elbc_gpcm: use device-managed allocators")

Same comments as for other patches.

Quoted 10 lines
---
 drivers/uio/uio_fsl_elbc_gpcm.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/uio/uio_fsl_elbc_gpcm.c +0 -0
index 81454c3e2484..59ba1a2dcfe3 100644

drivers/uio/uio_fsl_elbc_gpcm.c static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev) · line 388

Quoted 5 lines
drivers/uio/uio_fsl_elbc_gpcm.c +2 -0
@@ -384,6 +384,10 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev)
 
 	/* set all UIO data */
 	info->mem[0].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn", node);
+	if (!info->mem[0].name) {
+		dev_err(priv->dev, "devm_kasprintf failed for region name\n");

There is never a printk after memory allocation failure.

Also, just like in some of the other patches, you did not really analyze the code - you leak here resource map. Just look at the entire code instead of blindly pasting the same code here and there.

Best regards,
Krzysztof

#2 lore raw

PATCH v2 1/1 uio: uio_fsl_elbc_gpcm: Add NULL check in the uio_fsl_elbc_gpcm_probe()

devm_kasprintf() returns NULL when memory allocation fails. Currently, uio_fsl_elbc_gpcm_probe() does not check for this case, which results in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue and ensuring no resources are left allocated.

Fixes d57801c45f53 ("uio: uio_fsl_elbc_gpcm: use device-managed allocators")

---
V1 -> V2: Remove printk after memory failure and add proper resource cleanup.

 drivers/uio/uio_fsl_elbc_gpcm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/uio/uio_fsl_elbc_gpcm.c +5 -0
index 81454c3e2484..26be556d956c 100644
@@ -384,6 +384,10 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev)
 
 	/* set all UIO data */
 	info->mem[0].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn", node);
+	if (!info->mem[0].name) {
+		ret = -ENOMEM;
+		goto out_err3;
+	}
 	info->mem[0].addr = res.start;
 	info->mem[0].size = resource_size(&res);
 	info->mem[0].memtype = UIO_MEM_PHYS;
@@ -423,6 +427,7 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev)
 out_err2:
 	if (priv->shutdown)
 		priv->shutdown(info, true);
+out_err3:
 	iounmap(info->mem[0].internal_addr);
 	return ret;
 }
Signature · 1 line
2.34.1
maintainer
#3 lore raw

Re: [PATCH v2] uio: uio_fsl_elbc_gpcm: Add NULL check in the uio_fsl_elbc_gpcm_probe()

Quoted 42 lines · Henry Martin

devm_kasprintf() returns NULL when memory allocation fails. Currently, uio_fsl_elbc_gpcm_probe() does not check for this case, which results in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue and ensuring no resources are left allocated.

Fixes d57801c45f53 ("uio: uio_fsl_elbc_gpcm: use device-managed allocators")

---
V1 -> V2: Remove printk after memory failure and add proper resource cleanup.

 drivers/uio/uio_fsl_elbc_gpcm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/uio/uio_fsl_elbc_gpcm.c +5 -0
index 81454c3e2484..26be556d956c 100644
@@ -384,6 +384,10 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev)
 
 	/* set all UIO data */
 	info->mem[0].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn", node);
+	if (!info->mem[0].name) {
+		ret = -ENOMEM;
+		goto out_err3;
+	}
 	info->mem[0].addr = res.start;
 	info->mem[0].size = resource_size(&res);
 	info->mem[0].memtype = UIO_MEM_PHYS;
@@ -423,6 +427,7 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev)
 out_err2:
 	if (priv->shutdown)
 		priv->shutdown(info, true);
+out_err3:
 	iounmap(info->mem[0].internal_addr);
 	return ret;
 }
Signature · 1 line
2.34.1

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot