linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: Use and error-check DMA_ERROR_CODE
@ 2014-09-30 20:15 Sean Paul
  2014-10-01 10:13 ` Will Deacon
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Paul @ 2014-09-30 20:15 UTC (permalink / raw)
  To: linux-arm-kernel

This patch replaces the static assignment of ~0 to dma_handle with
DMA_ERROR_CODE to be consistent with other platforms.

In addition to that, it also adds a check for DMA_ERROR_CODE before
calling __dma_free_coherent with an invalid dma_handle.

Signed-off-by: Sean Paul <seanpaul@chromium.org>
---
 arch/arm64/mm/dma-mapping.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 4164c5a..69fd2c4 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -125,7 +125,7 @@ static void *__dma_alloc_noncoherent(struct device *dev, size_t size,
 no_map:
 	__dma_free_coherent(dev, size, ptr, *dma_handle, attrs);
 no_mem:
-	*dma_handle = ~0;
+	*dma_handle = DMA_ERROR_CODE;
 	return NULL;
 }
 
@@ -136,7 +136,9 @@ static void __dma_free_noncoherent(struct device *dev, size_t size,
 	void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle));
 
 	vunmap(vaddr);
-	__dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);
+
+	if (dma_handle != DMA_ERROR_CODE)
+		__dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);
 }
 
 static dma_addr_t __swiotlb_map_page(struct device *dev, struct page *page,
-- 
2.1.1

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

* [PATCH] arm64: Use and error-check DMA_ERROR_CODE
  2014-09-30 20:15 [PATCH] arm64: Use and error-check DMA_ERROR_CODE Sean Paul
@ 2014-10-01 10:13 ` Will Deacon
  2014-10-01 10:56   ` Catalin Marinas
  2014-10-01 13:52   ` Russell King - ARM Linux
  0 siblings, 2 replies; 6+ messages in thread
From: Will Deacon @ 2014-10-01 10:13 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Sean,

On Tue, Sep 30, 2014 at 09:15:21PM +0100, Sean Paul wrote:
> This patch replaces the static assignment of ~0 to dma_handle with
> DMA_ERROR_CODE to be consistent with other platforms.
> 
> In addition to that, it also adds a check for DMA_ERROR_CODE before
> calling __dma_free_coherent with an invalid dma_handle.
> 
> Signed-off-by: Sean Paul <seanpaul@chromium.org>
> ---
>  arch/arm64/mm/dma-mapping.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
> index 4164c5a..69fd2c4 100644
> --- a/arch/arm64/mm/dma-mapping.c
> +++ b/arch/arm64/mm/dma-mapping.c
> @@ -125,7 +125,7 @@ static void *__dma_alloc_noncoherent(struct device *dev, size_t size,
>  no_map:
>  	__dma_free_coherent(dev, size, ptr, *dma_handle, attrs);
>  no_mem:
> -	*dma_handle = ~0;
> +	*dma_handle = DMA_ERROR_CODE;
>  	return NULL;
>  }
>  
> @@ -136,7 +136,9 @@ static void __dma_free_noncoherent(struct device *dev, size_t size,
>  	void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle));
>  
>  	vunmap(vaddr);
> -	__dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);
> +
> +	if (dma_handle != DMA_ERROR_CODE)
> +		__dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);

Is it legal to try and free a DMA buffer after a failed allocation? If so, I
think we need something similar for arch/arm/.

Will

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

* [PATCH] arm64: Use and error-check DMA_ERROR_CODE
  2014-10-01 10:13 ` Will Deacon
@ 2014-10-01 10:56   ` Catalin Marinas
  2014-10-01 13:52   ` Russell King - ARM Linux
  1 sibling, 0 replies; 6+ messages in thread
From: Catalin Marinas @ 2014-10-01 10:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Oct 01, 2014 at 11:13:23AM +0100, Will Deacon wrote:
> On Tue, Sep 30, 2014 at 09:15:21PM +0100, Sean Paul wrote:
> > This patch replaces the static assignment of ~0 to dma_handle with
> > DMA_ERROR_CODE to be consistent with other platforms.
> > 
> > In addition to that, it also adds a check for DMA_ERROR_CODE before
> > calling __dma_free_coherent with an invalid dma_handle.
> > 
> > Signed-off-by: Sean Paul <seanpaul@chromium.org>
> > ---
> >  arch/arm64/mm/dma-mapping.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
> > index 4164c5a..69fd2c4 100644
> > --- a/arch/arm64/mm/dma-mapping.c
> > +++ b/arch/arm64/mm/dma-mapping.c
> > @@ -125,7 +125,7 @@ static void *__dma_alloc_noncoherent(struct device *dev, size_t size,
> >  no_map:
> >  	__dma_free_coherent(dev, size, ptr, *dma_handle, attrs);
> >  no_mem:
> > -	*dma_handle = ~0;
> > +	*dma_handle = DMA_ERROR_CODE;
> >  	return NULL;
> >  }
> >  
> > @@ -136,7 +136,9 @@ static void __dma_free_noncoherent(struct device *dev, size_t size,
> >  	void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle));
> >  
> >  	vunmap(vaddr);
> > -	__dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);
> > +
> > +	if (dma_handle != DMA_ERROR_CODE)
> > +		__dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);
> 
> Is it legal to try and free a DMA buffer after a failed allocation? If so, I
> think we need something similar for arch/arm/.

If the allocation failed, we don't even have a vaddr to unmap, so I
don't see the reason for the additional check.

-- 
Catalin

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

* [PATCH] arm64: Use and error-check DMA_ERROR_CODE
  2014-10-01 10:13 ` Will Deacon
  2014-10-01 10:56   ` Catalin Marinas
@ 2014-10-01 13:52   ` Russell King - ARM Linux
  2014-10-01 15:31     ` [PATCH v2] arm64: Use DMA_ERROR_CODE to denote failed allocation Sean Paul
  1 sibling, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux @ 2014-10-01 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Oct 01, 2014 at 11:13:23AM +0100, Will Deacon wrote:
> Hi Sean,
> 
> On Tue, Sep 30, 2014 at 09:15:21PM +0100, Sean Paul wrote:
> > +
> > +	if (dma_handle != DMA_ERROR_CODE)
> > +		__dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);
> 
> Is it legal to try and free a DMA buffer after a failed allocation? If so, I
> think we need something similar for arch/arm/.

No.

	void
	dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
	                           dma_addr_t dma_handle)

	Free a region of consistent memory you previously allocated.  dev,
	                                       ^^^^^^^^^^^^^^^^^^^^^
This implies that the allocation was successful.

	size and dma_handle must all be the same as those passed into
	dma_alloc_coherent().  cpu_addr must be the virtual address returned by
	                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If you want this behaviour, the proper way to do it would be to check
for a NULL cpu_addr, just like kfree() etc.

	the dma_alloc_coherent().

-- 
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.

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

* [PATCH v2] arm64: Use DMA_ERROR_CODE to denote failed allocation
  2014-10-01 13:52   ` Russell King - ARM Linux
@ 2014-10-01 15:31     ` Sean Paul
  2014-10-02 10:57       ` Catalin Marinas
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Paul @ 2014-10-01 15:31 UTC (permalink / raw)
  To: linux-arm-kernel

This patch replaces the static assignment of ~0 to dma_handle with
DMA_ERROR_CODE to be consistent with other platforms.

Signed-off-by: Sean Paul <seanpaul@chromium.org>
---

Changes in v2:
	- Removed the check for DMA_ERROR_CODE in __dma_free_noncoherent
	  the function shouldn't be called after failed allocation

 arch/arm64/mm/dma-mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 4164c5a..5687dd4 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -125,7 +125,7 @@ static void *__dma_alloc_noncoherent(struct device *dev, size_t size,
 no_map:
 	__dma_free_coherent(dev, size, ptr, *dma_handle, attrs);
 no_mem:
-	*dma_handle = ~0;
+	*dma_handle = DMA_ERROR_CODE;
 	return NULL;
 }
 
-- 
2.1.1

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

* [PATCH v2] arm64: Use DMA_ERROR_CODE to denote failed allocation
  2014-10-01 15:31     ` [PATCH v2] arm64: Use DMA_ERROR_CODE to denote failed allocation Sean Paul
@ 2014-10-02 10:57       ` Catalin Marinas
  0 siblings, 0 replies; 6+ messages in thread
From: Catalin Marinas @ 2014-10-02 10:57 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Oct 01, 2014 at 04:31:50PM +0100, Sean Paul wrote:
> This patch replaces the static assignment of ~0 to dma_handle with
> DMA_ERROR_CODE to be consistent with other platforms.
> 
> Signed-off-by: Sean Paul <seanpaul@chromium.org>

Applied. Thanks.

-- 
Catalin

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

end of thread, other threads:[~2014-10-02 10:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-30 20:15 [PATCH] arm64: Use and error-check DMA_ERROR_CODE Sean Paul
2014-10-01 10:13 ` Will Deacon
2014-10-01 10:56   ` Catalin Marinas
2014-10-01 13:52   ` Russell King - ARM Linux
2014-10-01 15:31     ` [PATCH v2] arm64: Use DMA_ERROR_CODE to denote failed allocation Sean Paul
2014-10-02 10:57       ` Catalin Marinas

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