[PATCH] uio: uio_fsl_elbc_gpcm: Add check devm_kasprintf() returned value

Charles Han posted 1 patch 2 months ago
drivers/uio/uio_fsl_elbc_gpcm.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] uio: uio_fsl_elbc_gpcm: Add check devm_kasprintf() returned value
Posted by Charles Han 2 months ago
devm_kasprintf() can return a NULL pointer on failure but this
returned value in uio_fsl_elbc_gpcm_probe() is not checked.

Fixes: d57801c45f53 ("uio: uio_fsl_elbc_gpcm: use device-managed allocators")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/uio/uio_fsl_elbc_gpcm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/uio/uio_fsl_elbc_gpcm.c b/drivers/uio/uio_fsl_elbc_gpcm.c
index 496caff66e7e..6378e752f828 100644
--- a/drivers/uio/uio_fsl_elbc_gpcm.c
+++ b/drivers/uio/uio_fsl_elbc_gpcm.c
@@ -384,6 +384,9 @@ 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)
+		return -ENOMEM;
+
 	info->mem[0].addr = res.start;
 	info->mem[0].size = resource_size(&res);
 	info->mem[0].memtype = UIO_MEM_PHYS;
-- 
2.31.1
Re: [PATCH] uio: uio_fsl_elbc_gpcm: Add check devm_kasprintf() returned value
Posted by Greg KH 1 month, 2 weeks ago
On Sun, Sep 29, 2024 at 11:42:23AM +0800, Charles Han wrote:
> devm_kasprintf() can return a NULL pointer on failure but this
> returned value in uio_fsl_elbc_gpcm_probe() is not checked.
> 
> Fixes: d57801c45f53 ("uio: uio_fsl_elbc_gpcm: use device-managed allocators")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
>  drivers/uio/uio_fsl_elbc_gpcm.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/uio/uio_fsl_elbc_gpcm.c b/drivers/uio/uio_fsl_elbc_gpcm.c
> index 496caff66e7e..6378e752f828 100644
> --- a/drivers/uio/uio_fsl_elbc_gpcm.c
> +++ b/drivers/uio/uio_fsl_elbc_gpcm.c
> @@ -384,6 +384,9 @@ 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)
> +		return -ENOMEM;

This is wrong, please fix your tools that created such a patch as it now
leaks memory :(