linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Nilsson <jesper.nilsson@axis.com>
To: Dan Williams <dan.j.williams@intel.com>,
	Vinod Koul <vinod.koul@intel.com>,
	dmaengine@vger.kernel.org,
	Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] DMA: nbpfaxi: check for errors from dma_map_single
Date: Wed, 5 Oct 2016 16:51:32 +0200	[thread overview]
Message-ID: <20161005145131.GJ30704@axis.com> (raw)

Check for error return from dma_map_single.
Move the addition of the node to the list to after we check
for error, so we can reuse the list in unmapping.

Found by enabling CONFIG_DMA_API_DEBUG.

Signed-off-by: Jesper Nilsson <jesper.nilsson@axis.com>
---
 drivers/dma/nbpfaxi.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/nbpfaxi.c b/drivers/dma/nbpfaxi.c
index 42ac2ff..4f5dd2e 100644
--- a/drivers/dma/nbpfaxi.c
+++ b/drivers/dma/nbpfaxi.c
@@ -731,10 +731,15 @@ static int __nbpf_desc_page_alloc(struct nbpf_channel *chan, gfp_t gfp)
 	     i < ARRAY_SIZE(dpage->ldesc);
 	     i++, ldesc++, hwdesc++) {
 		ldesc->hwdesc = hwdesc;
-		list_add_tail(&ldesc->node, &lhead);
 		ldesc->hwdesc_dma_addr = dma_map_single(dchan->device->dev,
 					hwdesc, sizeof(*hwdesc), DMA_TO_DEVICE);
 
+		if (dma_mapping_error(dchan->device->dev,
+				      ldesc->hwdesc_dma_addr)) {
+			goto unmap_err;
+		}
+		list_add_tail(&ldesc->node, &lhead);
+
 		dev_dbg(dev, "%s(): mapped 0x%p to %pad\n", __func__,
 			hwdesc, &ldesc->hwdesc_dma_addr);
 	}
@@ -754,6 +759,14 @@ static int __nbpf_desc_page_alloc(struct nbpf_channel *chan, gfp_t gfp)
 	list_add(&dpage->node, &chan->desc_page);
 
 	return ARRAY_SIZE(dpage->desc);
+unmap_err:
+	list_for_each_entry(ldesc, &lhead, node) {
+		dma_unmap_single(dchan->device->dev,
+				 ldesc->hwdesc_dma_addr,
+				 sizeof(*ldesc->hwdesc),
+				 DMA_TO_DEVICE);
+	}
+	return -ENOMEM;
 }
 
 static void __nbpf_desc_put(struct nbpf_desc *desc)
-- 
2.1.4


/^JN - Jesper Nilsson
-- 
               Jesper Nilsson -- jesper.nilsson@axis.com

             reply	other threads:[~2016-10-05 14:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-05 14:51 Jesper Nilsson [this message]
2016-10-18 14:59 ` [PATCH] DMA: nbpfaxi: check for errors from dma_map_single Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161005145131.GJ30704@axis.com \
    --to=jesper.nilsson@axis.com \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=g.liakhovetski@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).