netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: George Spelvin <lkml@sdf.org>
To: michael.chan@broadcom.com, netdev@vger.kernel.org
Cc: hauke@hauke-m.de, lkml@sdf.org
Subject: [RFC PATCH 3/4] b44: Unmap DMA ring buffers before kfree
Date: Sun, 8 Dec 2019 08:38:28 GMT	[thread overview]
Message-ID: <201912080838.xB88cSTa015147@sdf.org> (raw)

It's an unlikely error path during initialization, but let's
not leak DMA mappings.

Also the condition for an unacceptable mapping is corrected from
dma_addr + len > 0x3fffffff to dma_addr + len > 0x40000000, as in
the previous patch.

Signed-off-by: George Spelvin <lkml@sdf.org>
---
 drivers/net/ethernet/broadcom/b44.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c
index e540d5646aef..90e25a1f284f 100644
--- a/drivers/net/ethernet/broadcom/b44.c
+++ b/drivers/net/ethernet/broadcom/b44.c
@@ -1226,8 +1226,12 @@ static int b44_alloc_consistent(struct b44 *bp, gfp_t gfp)
 					     DMA_TABLE_BYTES,
 					     DMA_BIDIRECTIONAL);
 
-		if (dma_mapping_error(bp->sdev->dma_dev, rx_ring_dma) ||
-			rx_ring_dma + size > DMA_BIT_MASK(30)) {
+		if (dma_mapping_error(bp->sdev->dma_dev, rx_ring_dma))
+			goto rx_failed;
+		if (rx_ring_dma + size > DMA_BIT_MASK(30)+1) {
+			dma_unmap_single(bp->sdev->dma_dev, rx_ring_dma,
+					 DMA_TABLE_BYTES, DMA_BIDIRECTIONAL);
+rx_failed:
 			kfree(rx_ring);
 			goto out_err;
 		}
@@ -1254,8 +1258,12 @@ static int b44_alloc_consistent(struct b44 *bp, gfp_t gfp)
 					     DMA_TABLE_BYTES,
 					     DMA_TO_DEVICE);
 
-		if (dma_mapping_error(bp->sdev->dma_dev, tx_ring_dma) ||
-			tx_ring_dma + size > DMA_BIT_MASK(30)) {
+		if (dma_mapping_error(bp->sdev->dma_dev, tx_ring_dma))
+			goto tx_failed;
+		if (tx_ring_dma + size > DMA_BIT_MASK(30)+1) {
+			dma_unmap_single(bp->sdev->dma_dev, tx_ring_dma,
+					 DMA_TABLE_BYTES, DMA_TO_DEVICE);
+tx_failed:
 			kfree(tx_ring);
 			goto out_err;
 		}
-- 
2.24.0

                 reply	other threads:[~2019-12-08  8:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=201912080838.xB88cSTa015147@sdf.org \
    --to=lkml@sdf.org \
    --cc=hauke@hauke-m.de \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    /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).