[6/8] pata: ixp4xx: Use devm_platform_get_and_ioremap_resource()

Message ID 20230706124239.23366-6-frank.li@vivo.com
State New
Headers
Series [1/8] ata: ahci_octeon: Convert to devm_platform_ioremap_resource() |

Commit Message

李扬韬 July 6, 2023, 12:42 p.m. UTC
  Convert platform_get_resource(), devm_ioremap_resource() to a single
call to devm_platform_get_and_ioremap_resource(), as this is exactly
what this function does.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 drivers/ata/pata_ixp4xx_cf.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
  

Comments

Damien Le Moal July 6, 2023, 11:39 p.m. UTC | #1
On 7/6/23 21:42, Yangtao Li wrote:
> Convert platform_get_resource(), devm_ioremap_resource() to a single
> call to devm_platform_get_and_ioremap_resource(), as this is exactly
> what this function does.

Patch title:

ata: pata_ixp4xx: ...

> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>  drivers/ata/pata_ixp4xx_cf.c | 24 +++++++++---------------
>  1 file changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
> index b1daa4d3fcd9..246bb4f8f1f7 100644
> --- a/drivers/ata/pata_ixp4xx_cf.c
> +++ b/drivers/ata/pata_ixp4xx_cf.c
> @@ -242,12 +242,6 @@ static int ixp4xx_pata_probe(struct platform_device *pdev)
>  	int ret;
>  	int irq;
>  
> -	cmd = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	ctl = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> -
> -	if (!cmd || !ctl)
> -		return -EINVAL;
> -
>  	ixpp = devm_kzalloc(dev, sizeof(*ixpp), GFP_KERNEL);
>  	if (!ixpp)
>  		return -ENOMEM;
> @@ -271,18 +265,18 @@ static int ixp4xx_pata_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	ixpp->cmd = devm_ioremap_resource(dev, cmd);
> -	ixpp->ctl = devm_ioremap_resource(dev, ctl);
> -	if (IS_ERR(ixpp->cmd) || IS_ERR(ixpp->ctl))
> -		return -ENOMEM;
> +	ixpp->cmd = devm_platform_get_and_ioremap_resource(pdev, 0, &cmd);
> +	if (IS_ERR(ixpp->cmd))
> +		return PTR_ERR(ixpp->cmd);
> +
> +	ixpp->ctl = devm_platform_get_and_ioremap_resource(pdev, 1, &ctl);
> +	if (IS_ERR(ixpp->ctl))
> +		return PTR_ERR(ixpp->ctl);
>  
>  	irq = platform_get_irq(pdev, 0);
> -	if (irq > 0)
> -		irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
> -	else if (irq < 0)
> +	if (irq < 0)
>  		return irq;
> -	else
> -		return -EINVAL;
> +	irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);

This change is OK but this should be a different patch.

>  
>  	/* Just one port to set up */
>  	ixp4xx_setup_port(ixpp->host->ports[0], ixpp, cmd->start, ctl->start);
  
Sergey Shtylyov July 7, 2023, 6:58 p.m. UTC | #2
On 7/6/23 3:42 PM, Yangtao Li wrote:

> Convert platform_get_resource(), devm_ioremap_resource() to a single
> call to devm_platform_get_and_ioremap_resource(), as this is exactly
> what this function does.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
>  drivers/ata/pata_ixp4xx_cf.c | 24 +++++++++---------------
>  1 file changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
> index b1daa4d3fcd9..246bb4f8f1f7 100644
> --- a/drivers/ata/pata_ixp4xx_cf.c
> +++ b/drivers/ata/pata_ixp4xx_cf.c
[...]
> @@ -271,18 +265,18 @@ static int ixp4xx_pata_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	ixpp->cmd = devm_ioremap_resource(dev, cmd);
> -	ixpp->ctl = devm_ioremap_resource(dev, ctl);
> -	if (IS_ERR(ixpp->cmd) || IS_ERR(ixpp->ctl))
> -		return -ENOMEM;
> +	ixpp->cmd = devm_platform_get_and_ioremap_resource(pdev, 0, &cmd);
> +	if (IS_ERR(ixpp->cmd))
> +		return PTR_ERR(ixpp->cmd);
> +
> +	ixpp->ctl = devm_platform_get_and_ioremap_resource(pdev, 1, &ctl);
> +	if (IS_ERR(ixpp->ctl))
> +		return PTR_ERR(ixpp->ctl);

   Looks good...

>  
>  	irq = platform_get_irq(pdev, 0);
> -	if (irq > 0)
> -		irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
> -	else if (irq < 0)
> +	if (irq < 0)
>  		return irq;
> -	else
> -		return -EINVAL;
> +	irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);

   This change also looks good (but undescribed!), however it should be
done in a separate patch.
   For the future, try to follow a simple rule: do one thing per patch.
Oh, and don't forget to describe everything you do in a patch...

[...]

MBR, Sergey
  

Patch

diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index b1daa4d3fcd9..246bb4f8f1f7 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -242,12 +242,6 @@  static int ixp4xx_pata_probe(struct platform_device *pdev)
 	int ret;
 	int irq;
 
-	cmd = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	ctl = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-
-	if (!cmd || !ctl)
-		return -EINVAL;
-
 	ixpp = devm_kzalloc(dev, sizeof(*ixpp), GFP_KERNEL);
 	if (!ixpp)
 		return -ENOMEM;
@@ -271,18 +265,18 @@  static int ixp4xx_pata_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ixpp->cmd = devm_ioremap_resource(dev, cmd);
-	ixpp->ctl = devm_ioremap_resource(dev, ctl);
-	if (IS_ERR(ixpp->cmd) || IS_ERR(ixpp->ctl))
-		return -ENOMEM;
+	ixpp->cmd = devm_platform_get_and_ioremap_resource(pdev, 0, &cmd);
+	if (IS_ERR(ixpp->cmd))
+		return PTR_ERR(ixpp->cmd);
+
+	ixpp->ctl = devm_platform_get_and_ioremap_resource(pdev, 1, &ctl);
+	if (IS_ERR(ixpp->ctl))
+		return PTR_ERR(ixpp->ctl);
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq > 0)
-		irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
-	else if (irq < 0)
+	if (irq < 0)
 		return irq;
-	else
-		return -EINVAL;
+	irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
 
 	/* Just one port to set up */
 	ixp4xx_setup_port(ixpp->host->ports[0], ixpp, cmd->start, ctl->start);