dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ioat: ioat_alloc_ring() failure handling.
@ 2019-12-25 17:55 Alexander.Barabash
  2019-12-26 15:48 ` Jiang, Dave
  2019-12-27  6:36 ` Vinod Koul
  0 siblings, 2 replies; 3+ messages in thread
From: Alexander.Barabash @ 2019-12-25 17:55 UTC (permalink / raw)
  To: dmaengine; +Cc: alexander.barabash

If dma_alloc_coherent() returns NULL in ioat_alloc_ring(), ring
allocation must not proceed.

Until now, if the first call to dma_alloc_coherent() in
ioat_alloc_ring() returned NULL, the processing could proceed, failing
with NULL-pointer dereferencing further down the line.

Signed-off-by: Alexander Barabash <alexander.barabash@dell.com>
---
 drivers/dma/ioat/dma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
index 1a422a8..18c011e 100644
--- a/drivers/dma/ioat/dma.c
+++ b/drivers/dma/ioat/dma.c
@@ -377,10 +377,11 @@ struct ioat_ring_ent **
 
 		descs->virt = dma_alloc_coherent(to_dev(ioat_chan),
 						 SZ_2M, &descs->hw, flags);
-		if (!descs->virt && (i > 0)) {
+		if (!descs->virt) {
 			int idx;
 
 			for (idx = 0; idx < i; idx++) {
+				descs = &ioat_chan->descs[idx];
 				dma_free_coherent(to_dev(ioat_chan), SZ_2M,
 						  descs->virt, descs->hw);
 				descs->virt = NULL;
-- 
1.8.3.1


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

* RE: [PATCH v2] ioat: ioat_alloc_ring() failure handling.
  2019-12-25 17:55 [PATCH v2] ioat: ioat_alloc_ring() failure handling Alexander.Barabash
@ 2019-12-26 15:48 ` Jiang, Dave
  2019-12-27  6:36 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Jiang, Dave @ 2019-12-26 15:48 UTC (permalink / raw)
  To: Alexander.Barabash, dmaengine; +Cc: alexander.barabash



> -----Original Message-----
> From: dmaengine-owner@vger.kernel.org <dmaengine-
> owner@vger.kernel.org> On Behalf Of Alexander.Barabash@dell.com
> Sent: Wednesday, December 25, 2019 10:56 AM
> To: dmaengine@vger.kernel.org
> Cc: alexander.barabash@gmail.com
> Subject: [PATCH v2] ioat: ioat_alloc_ring() failure handling.
> 
> If dma_alloc_coherent() returns NULL in ioat_alloc_ring(), ring allocation
> must not proceed.
> 
> Until now, if the first call to dma_alloc_coherent() in
> ioat_alloc_ring() returned NULL, the processing could proceed, failing with
> NULL-pointer dereferencing further down the line.
> 
> Signed-off-by: Alexander Barabash <alexander.barabash@dell.com>

Acked-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  drivers/dma/ioat/dma.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c index
> 1a422a8..18c011e 100644
> --- a/drivers/dma/ioat/dma.c
> +++ b/drivers/dma/ioat/dma.c
> @@ -377,10 +377,11 @@ struct ioat_ring_ent **
> 
>  		descs->virt = dma_alloc_coherent(to_dev(ioat_chan),
>  						 SZ_2M, &descs->hw, flags);
> -		if (!descs->virt && (i > 0)) {
> +		if (!descs->virt) {
>  			int idx;
> 
>  			for (idx = 0; idx < i; idx++) {
> +				descs = &ioat_chan->descs[idx];
>  				dma_free_coherent(to_dev(ioat_chan),
> SZ_2M,
>  						  descs->virt, descs->hw);
>  				descs->virt = NULL;
> --
> 1.8.3.1


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

* Re: [PATCH v2] ioat: ioat_alloc_ring() failure handling.
  2019-12-25 17:55 [PATCH v2] ioat: ioat_alloc_ring() failure handling Alexander.Barabash
  2019-12-26 15:48 ` Jiang, Dave
@ 2019-12-27  6:36 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2019-12-27  6:36 UTC (permalink / raw)
  To: Alexander.Barabash; +Cc: dmaengine, alexander.barabash

On 25-12-19, 17:55, Alexander.Barabash@dell.com wrote:
> If dma_alloc_coherent() returns NULL in ioat_alloc_ring(), ring
> allocation must not proceed.
> 
> Until now, if the first call to dma_alloc_coherent() in
> ioat_alloc_ring() returned NULL, the processing could proceed, failing
> with NULL-pointer dereferencing further down the line.

Applied, thanks

-- 
~Vinod

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

end of thread, other threads:[~2019-12-27  6:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-25 17:55 [PATCH v2] ioat: ioat_alloc_ring() failure handling Alexander.Barabash
2019-12-26 15:48 ` Jiang, Dave
2019-12-27  6:36 ` Vinod Koul

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