[PATCH] dmaengine: idxd: Fix the error handling path in idxd_cdev_register()

Christophe JAILLET posted 1 patch 4 years ago
drivers/dma/idxd/cdev.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
[PATCH] dmaengine: idxd: Fix the error handling path in idxd_cdev_register()
Posted by Christophe JAILLET 4 years ago
If a call to alloc_chrdev_region() fails, the already allocated resources
are leaking.

Add the needed error handling path to fix the leak.

Fixes: 42d279f9137a ("dmaengine: idxd: add char driver to expose submission portal to userland")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/dma/idxd/cdev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
index b9b2b4a4124e..033df43db0ce 100644
--- a/drivers/dma/idxd/cdev.c
+++ b/drivers/dma/idxd/cdev.c
@@ -369,10 +369,16 @@ int idxd_cdev_register(void)
 		rc = alloc_chrdev_region(&ictx[i].devt, 0, MINORMASK,
 					 ictx[i].name);
 		if (rc)
-			return rc;
+			goto err_free_chrdev_region;
 	}
 
 	return 0;
+
+err_free_chrdev_region:
+	for (i--; i >= 0; i--)
+		unregister_chrdev_region(ictx[i].devt, MINORMASK);
+
+	return rc;
 }
 
 void idxd_cdev_remove(void)
-- 
2.32.0
Re: [PATCH] dmaengine: idxd: Fix the error handling path in idxd_cdev_register()
Posted by Vinod Koul 4 years ago
On 21-04-22, 08:13, Christophe JAILLET wrote:
> If a call to alloc_chrdev_region() fails, the already allocated resources
> are leaking.
> 
> Add the needed error handling path to fix the leak.

Applied, thanks

-- 
~Vinod
Re: [PATCH] dmaengine: idxd: Fix the error handling path in idxd_cdev_register()
Posted by Dave Jiang 4 years ago
On 4/20/2022 11:13 PM, Christophe JAILLET wrote:
> If a call to alloc_chrdev_region() fails, the already allocated resources
> are leaking.
>
> Add the needed error handling path to fix the leak.
>
> Fixes: 42d279f9137a ("dmaengine: idxd: add char driver to expose submission portal to userland")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Dave Jiang <dave.jiang@intel.com>

Thanks!

> ---
>   drivers/dma/idxd/cdev.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
> index b9b2b4a4124e..033df43db0ce 100644
> --- a/drivers/dma/idxd/cdev.c
> +++ b/drivers/dma/idxd/cdev.c
> @@ -369,10 +369,16 @@ int idxd_cdev_register(void)
>   		rc = alloc_chrdev_region(&ictx[i].devt, 0, MINORMASK,
>   					 ictx[i].name);
>   		if (rc)
> -			return rc;
> +			goto err_free_chrdev_region;
>   	}
>   
>   	return 0;
> +
> +err_free_chrdev_region:
> +	for (i--; i >= 0; i--)
> +		unregister_chrdev_region(ictx[i].devt, MINORMASK);
> +
> +	return rc;
>   }
>   
>   void idxd_cdev_remove(void)