* [PATCH v3] uio: uio_fsl_elbc_gpcm: Add NULL check in the uio_fsl_elbc_gpcm_probe()
@ 2025-04-01 10:16 Henry Martin
2025-04-15 15:09 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Henry Martin @ 2025-04-01 10:16 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Henry Martin, stable
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.
Cc: stable@vger.kernel.org
Fixes: d57801c45f53 ("uio: uio_fsl_elbc_gpcm: use device-managed allocators")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
V2 -> V3: Add Cc: stable@vger.kernel.org
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(+)
diff --git a/drivers/uio/uio_fsl_elbc_gpcm.c b/drivers/uio/uio_fsl_elbc_gpcm.c
index 81454c3e2484..26be556d956c 100644
--- a/drivers/uio/uio_fsl_elbc_gpcm.c
+++ b/drivers/uio/uio_fsl_elbc_gpcm.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] uio: uio_fsl_elbc_gpcm: Add NULL check in the uio_fsl_elbc_gpcm_probe()
2025-04-01 10:16 [PATCH v3] uio: uio_fsl_elbc_gpcm: Add NULL check in the uio_fsl_elbc_gpcm_probe() Henry Martin
@ 2025-04-15 15:09 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-04-15 15:09 UTC (permalink / raw)
To: Henry Martin; +Cc: linux-kernel, stable
On Tue, Apr 01, 2025 at 06:16:02PM +0800, Henry Martin wrote:
> 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.
>
> Cc: stable@vger.kernel.org
> Fixes: d57801c45f53 ("uio: uio_fsl_elbc_gpcm: use device-managed allocators")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> ---
> V2 -> V3: Add Cc: stable@vger.kernel.org
> 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(+)
>
> diff --git a/drivers/uio/uio_fsl_elbc_gpcm.c b/drivers/uio/uio_fsl_elbc_gpcm.c
> index 81454c3e2484..26be556d956c 100644
> --- a/drivers/uio/uio_fsl_elbc_gpcm.c
> +++ b/drivers/uio/uio_fsl_elbc_gpcm.c
> @@ -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;
> }
> --
> 2.34.1
>
>
How was this tested?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-15 15:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-01 10:16 [PATCH v3] uio: uio_fsl_elbc_gpcm: Add NULL check in the uio_fsl_elbc_gpcm_probe() Henry Martin
2025-04-15 15:09 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox