diff mbox series

ACPI: scan: Fix DMA range assignment

Message ID e94f99cfe09a64c590f009d21c566339117394e2.1666098844.git.robin.murphy@arm.com (mailing list archive)
State Mainlined, archived
Headers show
Series ACPI: scan: Fix DMA range assignment | expand

Commit Message

Robin Murphy Oct. 18, 2022, 1:14 p.m. UTC
Assigning the device's dma_range_map from the iterator variable after
the loop means it always points to the empty terminator at the end of
the map, which is not what we want. Similarly, freeing the iterator on
error when it points to somwhere in the middle of the allocated array
won't work either. Fix this.

Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets")
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/acpi/scan.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

吕建民 Oct. 18, 2022, 1:31 p.m. UTC | #1
Seems good. Thanks very much.

Reviewed-by: Jianmin Lv <lvjianmin@loongson.cn>

On 2022/10/18 下午9:14, Robin Murphy wrote:
> Assigning the device's dma_range_map from the iterator variable after
> the loop means it always points to the empty terminator at the end of
> the map, which is not what we want. Similarly, freeing the iterator on
> error when it points to somwhere in the middle of the allocated array
> won't work either. Fix this.
> 
> Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets")
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>   drivers/acpi/scan.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 558664d169fc..024cc373a197 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
>   			goto out;
>   		}
>   
> +		*map = r;
> +
>   		list_for_each_entry(rentry, &list, node) {
>   			if (rentry->res->start >= rentry->res->end) {
> -				kfree(r);
> +				kfree(*map);
> +				*map = NULL;
>   				ret = -EINVAL;
>   				dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
>   				goto out;
> @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
>   			r->offset = rentry->offset;
>   			r++;
>   		}
> -
> -		*map = r;
>   	}
>    out:
>   	acpi_dev_free_resource_list(&list);
>
Jeremy Linton Oct. 19, 2022, 12:41 a.m. UTC | #2
Hi,

On 10/18/22 08:14, Robin Murphy wrote:
> Assigning the device's dma_range_map from the iterator variable after
> the loop means it always points to the empty terminator at the end of
> the map, which is not what we want. Similarly, freeing the iterator on
> error when it points to somwhere in the middle of the allocated array
> won't work either. Fix this.

This fixes the boot problem on both SoC generations of the rpi4+ACPI,

Thanks,

Tested-by: Jeremy Linton <jeremy.linton@arm.com>

> 
> Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets")
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>   drivers/acpi/scan.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 558664d169fc..024cc373a197 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
>   			goto out;
>   		}
>   
> +		*map = r;
> +
>   		list_for_each_entry(rentry, &list, node) {
>   			if (rentry->res->start >= rentry->res->end) {
> -				kfree(r);
> +				kfree(*map);
> +				*map = NULL;
>   				ret = -EINVAL;
>   				dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
>   				goto out;
> @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
>   			r->offset = rentry->offset;
>   			r++;
>   		}
> -
> -		*map = r;
>   	}
>    out:
>   	acpi_dev_free_resource_list(&list);
Yicong Yang Oct. 19, 2022, 2:07 a.m. UTC | #3
On 2022/10/18 21:14, Robin Murphy wrote:
> Assigning the device's dma_range_map from the iterator variable after
> the loop means it always points to the empty terminator at the end of
> the map, which is not what we want. Similarly, freeing the iterator on
> error when it points to somwhere in the middle of the allocated array
> won't work either. Fix this.
> 
> Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets")

Thanks for fixing this. Works on my platform.

Tested-by: Yicong Yang <yangyicong@hisilicon.com>

> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>  drivers/acpi/scan.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 558664d169fc..024cc373a197 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
>  			goto out;
>  		}
>  
> +		*map = r;
> +
>  		list_for_each_entry(rentry, &list, node) {
>  			if (rentry->res->start >= rentry->res->end) {
> -				kfree(r);
> +				kfree(*map);
> +				*map = NULL;
>  				ret = -EINVAL;
>  				dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
>  				goto out;
> @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
>  			r->offset = rentry->offset;
>  			r++;
>  		}
> -
> -		*map = r;
>  	}
>   out:
>  	acpi_dev_free_resource_list(&list);
>
Lorenzo Pieralisi Oct. 19, 2022, 8:13 a.m. UTC | #4
On Tue, Oct 18, 2022 at 02:14:04PM +0100, Robin Murphy wrote:
> Assigning the device's dma_range_map from the iterator variable after
> the loop means it always points to the empty terminator at the end of
> the map, which is not what we want. Similarly, freeing the iterator on
> error when it points to somwhere in the middle of the allocated array
> won't work either. Fix this.
> 
> Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets")
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>  drivers/acpi/scan.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

A quick comment below, otherwise:

Reviewed-by: Lorenzo Pieralisi <lpieralisi@kernel.org>

> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 558664d169fc..024cc373a197 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
>  			goto out;
>  		}
>  
> +		*map = r;

I wonder whether having a local variable to stash the base pointer
would make code easier to read (so that we avoid using *map for that
purpose and also to return the array to the caller).

Thanks for fixing it so promptly.

Lorenzo

> +
>  		list_for_each_entry(rentry, &list, node) {
>  			if (rentry->res->start >= rentry->res->end) {
> -				kfree(r);
> +				kfree(*map);
> +				*map = NULL;
>  				ret = -EINVAL;
>  				dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
>  				goto out;
> @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
>  			r->offset = rentry->offset;
>  			r++;
>  		}
> -
> -		*map = r;
>  	}
>   out:
>  	acpi_dev_free_resource_list(&list);
> -- 
> 2.36.1.dirty
>
Rafael J. Wysocki Oct. 19, 2022, 6:30 p.m. UTC | #5
On Wed, Oct 19, 2022 at 10:13 AM Lorenzo Pieralisi
<lpieralisi@kernel.org> wrote:
>
> On Tue, Oct 18, 2022 at 02:14:04PM +0100, Robin Murphy wrote:
> > Assigning the device's dma_range_map from the iterator variable after
> > the loop means it always points to the empty terminator at the end of
> > the map, which is not what we want. Similarly, freeing the iterator on
> > error when it points to somwhere in the middle of the allocated array
> > won't work either. Fix this.
> >
> > Fixes: bf2ee8d0c385 ("ACPI: scan: Support multiple DMA windows with different offsets")
> > Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> > ---
> >  drivers/acpi/scan.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
>
> A quick comment below, otherwise:
>
> Reviewed-by: Lorenzo Pieralisi <lpieralisi@kernel.org>

Applied as is and the code may be cleaned up later.

Thanks!

> > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> > index 558664d169fc..024cc373a197 100644
> > --- a/drivers/acpi/scan.c
> > +++ b/drivers/acpi/scan.c
> > @@ -1509,9 +1509,12 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
> >                       goto out;
> >               }
> >
> > +             *map = r;
>
> I wonder whether having a local variable to stash the base pointer
> would make code easier to read (so that we avoid using *map for that
> purpose and also to return the array to the caller).
>
> Thanks for fixing it so promptly.
>
> Lorenzo
>
> > +
> >               list_for_each_entry(rentry, &list, node) {
> >                       if (rentry->res->start >= rentry->res->end) {
> > -                             kfree(r);
> > +                             kfree(*map);
> > +                             *map = NULL;
> >                               ret = -EINVAL;
> >                               dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
> >                               goto out;
> > @@ -1523,8 +1526,6 @@ int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
> >                       r->offset = rentry->offset;
> >                       r++;
> >               }
> > -
> > -             *map = r;
> >       }
> >   out:
> >       acpi_dev_free_resource_list(&list);
> > --
> > 2.36.1.dirty
> >
diff mbox series

Patch

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 558664d169fc..024cc373a197 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1509,9 +1509,12 @@  int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
 			goto out;
 		}
 
+		*map = r;
+
 		list_for_each_entry(rentry, &list, node) {
 			if (rentry->res->start >= rentry->res->end) {
-				kfree(r);
+				kfree(*map);
+				*map = NULL;
 				ret = -EINVAL;
 				dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
 				goto out;
@@ -1523,8 +1526,6 @@  int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
 			r->offset = rentry->offset;
 			r++;
 		}
-
-		*map = r;
 	}
  out:
 	acpi_dev_free_resource_list(&list);