diff mbox series

[10/11] usb: dwc3: rtk: return directly and simplify with devm_platform_ioremap_resource

Message ID 20240814-b4-cleanup-h-of-node-put-usb-v1-10-95481b9682bc@linaro.org (mailing list archive)
State New
Headers show
Series usb: dwc3: various cleanups | expand

Commit Message

Krzysztof Kozlowski Aug. 14, 2024, 10:35 a.m. UTC
Use devm_platform_ioremap_resource() wrapper instead of two calls, which
together with returning directly instead of useless goto, allows to
nicely simplify the probe() function.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/usb/dwc3/dwc3-rtk.c | 33 ++++++++-------------------------
 1 file changed, 8 insertions(+), 25 deletions(-)

Comments

Thinh Nguyen Aug. 27, 2024, 1:44 a.m. UTC | #1
On Wed, Aug 14, 2024, Krzysztof Kozlowski wrote:
> Use devm_platform_ioremap_resource() wrapper instead of two calls, which
> together with returning directly instead of useless goto, allows to
> nicely simplify the probe() function.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/usb/dwc3/dwc3-rtk.c | 33 ++++++++-------------------------
>  1 file changed, 8 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-rtk.c b/drivers/usb/dwc3/dwc3-rtk.c
> index 1e3ec2084286..b3db5cd9906e 100644
> --- a/drivers/usb/dwc3/dwc3-rtk.c
> +++ b/drivers/usb/dwc3/dwc3-rtk.c
> @@ -358,30 +358,18 @@ static int dwc3_rtk_probe(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct resource *res;
>  	void __iomem *regs;
> -	int ret = 0;
>  
>  	rtk = devm_kzalloc(dev, sizeof(*rtk), GFP_KERNEL);
> -	if (!rtk) {
> -		ret = -ENOMEM;
> -		goto out;
> -	}
> +	if (!rtk)
> +		return -ENOMEM;
>  
>  	platform_set_drvdata(pdev, rtk);
>  
>  	rtk->dev = dev;
>  
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	if (!res) {
> -		dev_err(dev, "missing memory resource\n");
> -		ret = -ENODEV;
> -		goto out;
> -	}
> -
> -	regs = devm_ioremap_resource(dev, res);
> -	if (IS_ERR(regs)) {
> -		ret = PTR_ERR(regs);
> -		goto out;
> -	}
> +	regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> +	if (IS_ERR(regs))
> +		return PTR_ERR(regs);
>  
>  	rtk->regs = regs;
>  	rtk->regs_size = resource_size(res);
> @@ -389,16 +377,11 @@ static int dwc3_rtk_probe(struct platform_device *pdev)
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>  	if (res) {
>  		rtk->pm_base = devm_ioremap_resource(dev, res);
> -		if (IS_ERR(rtk->pm_base)) {
> -			ret = PTR_ERR(rtk->pm_base);
> -			goto out;
> -		}
> +		if (IS_ERR(rtk->pm_base))
> +			return PTR_ERR(rtk->pm_base);
>  	}
>  
> -	ret = dwc3_rtk_probe_dwc3_core(rtk);
> -
> -out:
> -	return ret;
> +	return dwc3_rtk_probe_dwc3_core(rtk);
>  }
>  
>  static void dwc3_rtk_remove(struct platform_device *pdev)
> 
> -- 
> 2.43.0
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thanks,
Thinh
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-rtk.c b/drivers/usb/dwc3/dwc3-rtk.c
index 1e3ec2084286..b3db5cd9906e 100644
--- a/drivers/usb/dwc3/dwc3-rtk.c
+++ b/drivers/usb/dwc3/dwc3-rtk.c
@@ -358,30 +358,18 @@  static int dwc3_rtk_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct resource *res;
 	void __iomem *regs;
-	int ret = 0;
 
 	rtk = devm_kzalloc(dev, sizeof(*rtk), GFP_KERNEL);
-	if (!rtk) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!rtk)
+		return -ENOMEM;
 
 	platform_set_drvdata(pdev, rtk);
 
 	rtk->dev = dev;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(dev, "missing memory resource\n");
-		ret = -ENODEV;
-		goto out;
-	}
-
-	regs = devm_ioremap_resource(dev, res);
-	if (IS_ERR(regs)) {
-		ret = PTR_ERR(regs);
-		goto out;
-	}
+	regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(regs))
+		return PTR_ERR(regs);
 
 	rtk->regs = regs;
 	rtk->regs_size = resource_size(res);
@@ -389,16 +377,11 @@  static int dwc3_rtk_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (res) {
 		rtk->pm_base = devm_ioremap_resource(dev, res);
-		if (IS_ERR(rtk->pm_base)) {
-			ret = PTR_ERR(rtk->pm_base);
-			goto out;
-		}
+		if (IS_ERR(rtk->pm_base))
+			return PTR_ERR(rtk->pm_base);
 	}
 
-	ret = dwc3_rtk_probe_dwc3_core(rtk);
-
-out:
-	return ret;
+	return dwc3_rtk_probe_dwc3_core(rtk);
 }
 
 static void dwc3_rtk_remove(struct platform_device *pdev)