[PATCH ath-next] wifi: ath5k: ahb: use devm for ioremap

Rosen Penev posted 1 patch 1 month, 3 weeks ago
drivers/net/wireless/ath/ath5k/ahb.c | 33 ++++++----------------------
1 file changed, 7 insertions(+), 26 deletions(-)
[PATCH ath-next] wifi: ath5k: ahb: use devm for ioremap
Posted by Rosen Penev 1 month, 3 weeks ago
Simplifies the code by quite a bit in probe.

Also allows removing a goto and returning directly.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/wireless/ath/ath5k/ahb.c | 33 ++++++----------------------
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git a/drivers/net/wireless/ath/ath5k/ahb.c b/drivers/net/wireless/ath/ath5k/ahb.c
index cb3e891ee1bd..f34313568d9c 100644
--- a/drivers/net/wireless/ath/ath5k/ahb.c
+++ b/drivers/net/wireless/ath/ath5k/ahb.c
@@ -87,7 +87,6 @@ static int ath_ahb_probe(struct platform_device *pdev)
 	struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
 	struct ath5k_hw *ah;
 	struct ieee80211_hw *hw;
-	struct resource *res;
 	void __iomem *mem;
 	int irq;
 	int ret = 0;
@@ -95,35 +94,21 @@ static int ath_ahb_probe(struct platform_device *pdev)

 	if (!dev_get_platdata(&pdev->dev)) {
 		dev_err(&pdev->dev, "no platform data specified\n");
-		ret = -EINVAL;
-		goto err_out;
+		return -EINVAL;
 	}

-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (res == NULL) {
-		dev_err(&pdev->dev, "no memory resource found\n");
-		ret = -ENXIO;
-		goto err_out;
-	}
-
-	mem = ioremap(res->start, resource_size(res));
-	if (mem == NULL) {
-		dev_err(&pdev->dev, "ioremap failed\n");
-		ret = -ENOMEM;
-		goto err_out;
-	}
+	mem = devm_platform_ioremap_resources(pdev, 0);
+	if (IS_ERR(mem))
+		return dev_err_probe(&pdev->dev, PTR_ERR(mem), "ioremap failed\n");

 	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		ret = irq;
-		goto err_iounmap;
-	}
+	if (irq < 0)
+		return irq;

 	hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
 	if (hw == NULL) {
 		dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
-		ret = -ENOMEM;
-		goto err_iounmap;
+		return -ENOMEM;
 	}

 	ah = hw->priv;
@@ -179,9 +164,6 @@ static int ath_ahb_probe(struct platform_device *pdev)

  err_free_hw:
 	ieee80211_free_hw(hw);
- err_iounmap:
-        iounmap(mem);
- err_out:
 	return ret;
 }

@@ -213,7 +195,6 @@ static void ath_ahb_remove(struct platform_device *pdev)
 	}

 	ath5k_deinit_ah(ah);
-	iounmap(ah->iobase);
 	ieee80211_free_hw(hw);
 }

--
2.53.0
Re: [PATCH ath-next] wifi: ath5k: ahb: use devm for ioremap
Posted by Jiri Slaby 1 month, 3 weeks ago
On 23. 02. 26, 4:08, Rosen Penev wrote:
> Simplifies the code by quite a bit in probe.
> 
> Also allows removing a goto and returning directly.

Looks good except:

> --- a/drivers/net/wireless/ath/ath5k/ahb.c
> +++ b/drivers/net/wireless/ath/ath5k/ahb.c
...
> @@ -95,35 +94,21 @@ static int ath_ahb_probe(struct platform_device *pdev)
> 
>   	if (!dev_get_platdata(&pdev->dev)) {
>   		dev_err(&pdev->dev, "no platform data specified\n");
> -		ret = -EINVAL;
> -		goto err_out;
> +		return -EINVAL;
>   	}
> 
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	if (res == NULL) {
> -		dev_err(&pdev->dev, "no memory resource found\n");
> -		ret = -ENXIO;
> -		goto err_out;
> -	}
> -
> -	mem = ioremap(res->start, resource_size(res));
> -	if (mem == NULL) {
> -		dev_err(&pdev->dev, "ioremap failed\n");
> -		ret = -ENOMEM;
> -		goto err_out;
> -	}
> +	mem = devm_platform_ioremap_resources(pdev, 0);

Is this a typo or devm_platform_ioremap_resources() is new?

-- 
js
suse labs
Re: [PATCH ath-next] wifi: ath5k: ahb: use devm for ioremap
Posted by Rosen Penev 1 month, 2 weeks ago
On Tue, Feb 24, 2026 at 10:23 AM Jiri Slaby <jirislaby@kernel.org> wrote:
>
> On 23. 02. 26, 4:08, Rosen Penev wrote:
> > Simplifies the code by quite a bit in probe.
> >
> > Also allows removing a goto and returning directly.
>
> Looks good except:
>
> > --- a/drivers/net/wireless/ath/ath5k/ahb.c
> > +++ b/drivers/net/wireless/ath/ath5k/ahb.c
> ...
> > @@ -95,35 +94,21 @@ static int ath_ahb_probe(struct platform_device *pdev)
> >
> >       if (!dev_get_platdata(&pdev->dev)) {
> >               dev_err(&pdev->dev, "no platform data specified\n");
> > -             ret = -EINVAL;
> > -             goto err_out;
> > +             return -EINVAL;
> >       }
> >
> > -     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > -     if (res == NULL) {
> > -             dev_err(&pdev->dev, "no memory resource found\n");
> > -             ret = -ENXIO;
> > -             goto err_out;
> > -     }
> > -
> > -     mem = ioremap(res->start, resource_size(res));
> > -     if (mem == NULL) {
> > -             dev_err(&pdev->dev, "ioremap failed\n");
> > -             ret = -ENOMEM;
> > -             goto err_out;
> > -     }
> > +     mem = devm_platform_ioremap_resources(pdev, 0);
>
> Is this a typo or devm_platform_ioremap_resources() is new?
typo. Looks like COMPILE_TEST is needed.
>
> --
> js
> suse labs