linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ACPI: scan: Fix DMA range assignment
@ 2022-10-18 13:14 Robin Murphy
  2022-10-18 13:31 ` Jianmin Lv
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Robin Murphy @ 2022-10-18 13:14 UTC (permalink / raw)
  To: rafael
  Cc: lvjianmin, yangyicong, lpieralisi, chenhuacai, linux-acpi,
	linux-kernel, lenb, jeremy.linton

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);
-- 
2.36.1.dirty


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] ACPI: scan: Fix DMA range assignment
  2022-10-18 13:14 [PATCH] ACPI: scan: Fix DMA range assignment Robin Murphy
@ 2022-10-18 13:31 ` Jianmin Lv
  2022-10-19  0:41 ` Jeremy Linton
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Jianmin Lv @ 2022-10-18 13:31 UTC (permalink / raw)
  To: Robin Murphy, rafael
  Cc: yangyicong, lpieralisi, chenhuacai, linux-acpi, linux-kernel,
	lenb, jeremy.linton

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);
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ACPI: scan: Fix DMA range assignment
  2022-10-18 13:14 [PATCH] ACPI: scan: Fix DMA range assignment Robin Murphy
  2022-10-18 13:31 ` Jianmin Lv
@ 2022-10-19  0:41 ` Jeremy Linton
  2022-10-19  2:07 ` Yicong Yang
  2022-10-19  8:13 ` Lorenzo Pieralisi
  3 siblings, 0 replies; 6+ messages in thread
From: Jeremy Linton @ 2022-10-19  0:41 UTC (permalink / raw)
  To: Robin Murphy, rafael
  Cc: lvjianmin, yangyicong, lpieralisi, chenhuacai, linux-acpi,
	linux-kernel, lenb

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);


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ACPI: scan: Fix DMA range assignment
  2022-10-18 13:14 [PATCH] ACPI: scan: Fix DMA range assignment Robin Murphy
  2022-10-18 13:31 ` Jianmin Lv
  2022-10-19  0:41 ` Jeremy Linton
@ 2022-10-19  2:07 ` Yicong Yang
  2022-10-19  8:13 ` Lorenzo Pieralisi
  3 siblings, 0 replies; 6+ messages in thread
From: Yicong Yang @ 2022-10-19  2:07 UTC (permalink / raw)
  To: Robin Murphy, rafael
  Cc: yangyicong, lvjianmin, lpieralisi, chenhuacai, linux-acpi,
	linux-kernel, lenb, jeremy.linton

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);
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ACPI: scan: Fix DMA range assignment
  2022-10-18 13:14 [PATCH] ACPI: scan: Fix DMA range assignment Robin Murphy
                   ` (2 preceding siblings ...)
  2022-10-19  2:07 ` Yicong Yang
@ 2022-10-19  8:13 ` Lorenzo Pieralisi
  2022-10-19 18:30   ` Rafael J. Wysocki
  3 siblings, 1 reply; 6+ messages in thread
From: Lorenzo Pieralisi @ 2022-10-19  8:13 UTC (permalink / raw)
  To: Robin Murphy
  Cc: rafael, lvjianmin, yangyicong, chenhuacai, linux-acpi,
	linux-kernel, lenb, jeremy.linton

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
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ACPI: scan: Fix DMA range assignment
  2022-10-19  8:13 ` Lorenzo Pieralisi
@ 2022-10-19 18:30   ` Rafael J. Wysocki
  0 siblings, 0 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2022-10-19 18:30 UTC (permalink / raw)
  To: Lorenzo Pieralisi, Robin Murphy
  Cc: rafael, lvjianmin, yangyicong, chenhuacai, linux-acpi,
	linux-kernel, lenb, jeremy.linton

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
> >

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-19 18:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-18 13:14 [PATCH] ACPI: scan: Fix DMA range assignment Robin Murphy
2022-10-18 13:31 ` Jianmin Lv
2022-10-19  0:41 ` Jeremy Linton
2022-10-19  2:07 ` Yicong Yang
2022-10-19  8:13 ` Lorenzo Pieralisi
2022-10-19 18:30   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).