public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] misc: alcor_pci: Fix an error handling path
@ 2022-02-06  8:39 Christophe JAILLET
  2022-02-07  9:36 ` Oleksij Rempel
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2022-02-06  8:39 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, Oleksij Rempel, Ulf Hansson
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET

A successful ida_simple_get() should be balanced by a corresponding
ida_simple_remove().

Add the missing call in the error handling path of the probe.

While at it, switch to ida_alloc()/ida_free() instead to
ida_simple_get()/ida_simple_remove().
The latter is deprecated and more verbose.

Fixes: 4f556bc04e3c ("misc: cardreader: add new Alcor Micro Cardreader PCI driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/misc/cardreader/alcor_pci.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/cardreader/alcor_pci.c b/drivers/misc/cardreader/alcor_pci.c
index de6d44a158bb..3f514d77a843 100644
--- a/drivers/misc/cardreader/alcor_pci.c
+++ b/drivers/misc/cardreader/alcor_pci.c
@@ -266,7 +266,7 @@ static int alcor_pci_probe(struct pci_dev *pdev,
 	if (!priv)
 		return -ENOMEM;
 
-	ret = ida_simple_get(&alcor_pci_idr, 0, 0, GFP_KERNEL);
+	ret = ida_alloc(&alcor_pci_idr, GFP_KERNEL);
 	if (ret < 0)
 		return ret;
 	priv->id = ret;
@@ -280,7 +280,8 @@ static int alcor_pci_probe(struct pci_dev *pdev,
 	ret = pci_request_regions(pdev, DRV_NAME_ALCOR_PCI);
 	if (ret) {
 		dev_err(&pdev->dev, "Cannot request region\n");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto error_free_ida;
 	}
 
 	if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
@@ -324,6 +325,8 @@ static int alcor_pci_probe(struct pci_dev *pdev,
 
 error_release_regions:
 	pci_release_regions(pdev);
+error_free_ida:
+	ida_free(&alcor_pci_idr, priv->id);
 	return ret;
 }
 
@@ -337,7 +340,7 @@ static void alcor_pci_remove(struct pci_dev *pdev)
 
 	mfd_remove_devices(&pdev->dev);
 
-	ida_simple_remove(&alcor_pci_idr, priv->id);
+	ida_free(&alcor_pci_idr, priv->id);
 
 	pci_release_regions(pdev);
 	pci_set_drvdata(pdev, NULL);
-- 
2.32.0


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

* Re: [PATCH] misc: alcor_pci: Fix an error handling path
  2022-02-06  8:39 [PATCH] misc: alcor_pci: Fix an error handling path Christophe JAILLET
@ 2022-02-07  9:36 ` Oleksij Rempel
  0 siblings, 0 replies; 2+ messages in thread
From: Oleksij Rempel @ 2022-02-07  9:36 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Arnd Bergmann, Greg Kroah-Hartman, Oleksij Rempel, Ulf Hansson,
	linux-kernel, kernel-janitors

On Sun, Feb 06, 2022 at 09:39:54AM +0100, Christophe JAILLET wrote:
> A successful ida_simple_get() should be balanced by a corresponding
> ida_simple_remove().
> 
> Add the missing call in the error handling path of the probe.
> 
> While at it, switch to ida_alloc()/ida_free() instead to
> ida_simple_get()/ida_simple_remove().
> The latter is deprecated and more verbose.
> 
> Fixes: 4f556bc04e3c ("misc: cardreader: add new Alcor Micro Cardreader PCI driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>

Thank you!

> ---
>  drivers/misc/cardreader/alcor_pci.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/misc/cardreader/alcor_pci.c b/drivers/misc/cardreader/alcor_pci.c
> index de6d44a158bb..3f514d77a843 100644
> --- a/drivers/misc/cardreader/alcor_pci.c
> +++ b/drivers/misc/cardreader/alcor_pci.c
> @@ -266,7 +266,7 @@ static int alcor_pci_probe(struct pci_dev *pdev,
>  	if (!priv)
>  		return -ENOMEM;
>  
> -	ret = ida_simple_get(&alcor_pci_idr, 0, 0, GFP_KERNEL);
> +	ret = ida_alloc(&alcor_pci_idr, GFP_KERNEL);
>  	if (ret < 0)
>  		return ret;
>  	priv->id = ret;
> @@ -280,7 +280,8 @@ static int alcor_pci_probe(struct pci_dev *pdev,
>  	ret = pci_request_regions(pdev, DRV_NAME_ALCOR_PCI);
>  	if (ret) {
>  		dev_err(&pdev->dev, "Cannot request region\n");
> -		return -ENOMEM;
> +		ret = -ENOMEM;
> +		goto error_free_ida;
>  	}
>  
>  	if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
> @@ -324,6 +325,8 @@ static int alcor_pci_probe(struct pci_dev *pdev,
>  
>  error_release_regions:
>  	pci_release_regions(pdev);
> +error_free_ida:
> +	ida_free(&alcor_pci_idr, priv->id);
>  	return ret;
>  }
>  
> @@ -337,7 +340,7 @@ static void alcor_pci_remove(struct pci_dev *pdev)
>  
>  	mfd_remove_devices(&pdev->dev);
>  
> -	ida_simple_remove(&alcor_pci_idr, priv->id);
> +	ida_free(&alcor_pci_idr, priv->id);
>  
>  	pci_release_regions(pdev);
>  	pci_set_drvdata(pdev, NULL);
> -- 
> 2.32.0
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

end of thread, other threads:[~2022-02-07  9:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-06  8:39 [PATCH] misc: alcor_pci: Fix an error handling path Christophe JAILLET
2022-02-07  9:36 ` Oleksij Rempel

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