diff mbox series

[v3,01/10] ata: pata_platform: Make use of platform_get_mem_or_io()

Message ID 20211224131300.18198-2-prabhakar.mahadev-lad.rj@bp.renesas.com
State New
Headers show
Series [v3,01/10] ata: pata_platform: Make use of platform_get_mem_or_io() | expand

Commit Message

Lad Prabhakar Dec. 24, 2021, 1:12 p.m. UTC
Make use of platform_get_mem_or_io() to simplify the code.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---
 drivers/ata/pata_platform.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

Comments

Sergey Shtylyov Dec. 24, 2021, 5:56 p.m. UTC | #1
On 12/24/21 4:12 PM, Lad Prabhakar wrote:

> Make use of platform_get_mem_or_io() to simplify the code.
> 
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> ---
>  drivers/ata/pata_platform.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
> index 028329428b75..cb3134bf88eb 100644
> --- a/drivers/ata/pata_platform.c
> +++ b/drivers/ata/pata_platform.c
> @@ -198,22 +198,16 @@ static int pata_platform_probe(struct platform_device *pdev)
>  	/*
>  	 * Get the I/O base first
>  	 */
> -	io_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
> -	if (io_res == NULL) {
> -		io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -		if (unlikely(io_res == NULL))
> -			return -EINVAL;
> -	}
> +	io_res = platform_get_mem_or_io(pdev, 0);
> +	if (unlikely(!io_res))

   You don't have to keep unlikely() here -- the first *if* doesn't have it anyway,
only the 2nd one does...

> +		return -EINVAL;
>  
>  	/*
>  	 * Then the CTL base
>  	 */
> -	ctl_res = platform_get_resource(pdev, IORESOURCE_IO, 1);
> -	if (ctl_res == NULL) {
> -		ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> -		if (unlikely(ctl_res == NULL))
> -			return -EINVAL;
> -	}
> +	ctl_res = platform_get_mem_or_io(pdev, 1);
> +	if (unlikely(!ctl_res))

   Ditto.

> +		return -EINVAL;

MBR, Sergey
Lad, Prabhakar Dec. 24, 2021, 6:01 p.m. UTC | #2
Hi Sergey,

Thank you for the review.

On Fri, Dec 24, 2021 at 5:56 PM Sergey Shtylyov <s.shtylyov@omp.ru> wrote:
>
> On 12/24/21 4:12 PM, Lad Prabhakar wrote:
>
> > Make use of platform_get_mem_or_io() to simplify the code.
> >
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> > Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> > ---
> >  drivers/ata/pata_platform.c | 18 ++++++------------
> >  1 file changed, 6 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
> > index 028329428b75..cb3134bf88eb 100644
> > --- a/drivers/ata/pata_platform.c
> > +++ b/drivers/ata/pata_platform.c
> > @@ -198,22 +198,16 @@ static int pata_platform_probe(struct platform_device *pdev)
> >       /*
> >        * Get the I/O base first
> >        */
> > -     io_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
> > -     if (io_res == NULL) {
> > -             io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > -             if (unlikely(io_res == NULL))
> > -                     return -EINVAL;
> > -     }
> > +     io_res = platform_get_mem_or_io(pdev, 0);
> > +     if (unlikely(!io_res))
>
>    You don't have to keep unlikely() here -- the first *if* doesn't have it anyway,
> only the 2nd one does...
>
Agreed the first if doesn't have it, ie unlikely() will only be hit
when resource 0 isn't mem/IO, So with my patch introduced if mem/io is
NULL  unlikely() will be called. So there is "NO" behavioral change.

> > +             return -EINVAL;
> >
> >       /*
> >        * Then the CTL base
> >        */
> > -     ctl_res = platform_get_resource(pdev, IORESOURCE_IO, 1);
> > -     if (ctl_res == NULL) {
> > -             ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> > -             if (unlikely(ctl_res == NULL))
> > -                     return -EINVAL;
> > -     }
> > +     ctl_res = platform_get_mem_or_io(pdev, 1);
> > +     if (unlikely(!ctl_res))
>
>    Ditto.
>
Ditto.

Cheers,
Prabhakar
diff mbox series

Patch

diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 028329428b75..cb3134bf88eb 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -198,22 +198,16 @@  static int pata_platform_probe(struct platform_device *pdev)
 	/*
 	 * Get the I/O base first
 	 */
-	io_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
-	if (io_res == NULL) {
-		io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-		if (unlikely(io_res == NULL))
-			return -EINVAL;
-	}
+	io_res = platform_get_mem_or_io(pdev, 0);
+	if (unlikely(!io_res))
+		return -EINVAL;
 
 	/*
 	 * Then the CTL base
 	 */
-	ctl_res = platform_get_resource(pdev, IORESOURCE_IO, 1);
-	if (ctl_res == NULL) {
-		ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-		if (unlikely(ctl_res == NULL))
-			return -EINVAL;
-	}
+	ctl_res = platform_get_mem_or_io(pdev, 1);
+	if (unlikely(!ctl_res))
+		return -EINVAL;
 
 	/*
 	 * And the IRQ