mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Denis Orlov <denorl2009@gmail.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/6] net: designware: don't use dma_mapping_error for non-streaming DMA
Date: Mon, 14 Oct 2024 14:58:41 +0200	[thread overview]
Message-ID: <20241014125843.2064532-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241014125843.2064532-1-a.fatoum@pengutronix.de>

Streaming DMA operates at already allocated memory and the mapping needs
to be checked for errors with dma_mapping_error().

Calling it on the DMA address resulting from dma_alloc_coherent is
wrong, because error is indicated by returning a NULL pointer as CPU
address; The DMA address may not be set at all in that case.

While fixing this I wondered why priv->[tr]x_mac_descrtable_dev appear
to be unused. That's not the case, because they are used indirectly via
a helper function defined in a header, so add a comment about this while
we are at it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/designware.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 66f28b429dea..e7735a014cf4 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -480,18 +480,20 @@ struct dw_eth_dev *dwc_drv_probe(struct device *dev)
 	dwc_version(dev, readl(&priv->mac_regs_p->version));
 	priv->dma_regs_p = base + DW_DMA_BASE_OFFSET;
 
+	/* [tr]x_mac_descrtable_dev will be used by the [tr]x_dma_addr helpers */
+
 	priv->tx_mac_descrtable_cpu = dma_alloc_coherent(
 		CONFIG_TX_DESCR_NUM * sizeof(struct dmamacdescr),
 		&priv->tx_mac_descrtable_dev);
 
-	if (dma_mapping_error(dev, priv->tx_mac_descrtable_dev))
+	if (!priv->tx_mac_descrtable_cpu)
 		return ERR_PTR(-EFAULT);
 
 	priv->rx_mac_descrtable_cpu = dma_alloc_coherent(
 		CONFIG_RX_DESCR_NUM * sizeof(struct dmamacdescr),
 		&priv->rx_mac_descrtable_dev);
 
-	if (dma_mapping_error(dev, priv->rx_mac_descrtable_dev))
+	if (!priv->rx_mac_descrtable_cpu)
 		return ERR_PTR(-EFAULT);
 
 	priv->txbuffs = dma_alloc(TX_TOTAL_BUFSIZE);
-- 
2.39.5




  parent reply	other threads:[~2024-10-14 13:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 12:58 [PATCH 0/6] dma: give dma_alloc_coherent a device parameter Ahmad Fatoum
2024-10-14 12:58 ` [PATCH 1/6] dma: make DMA_ADDRESS_BROKEN type-safe Ahmad Fatoum
2024-10-14 12:58 ` [PATCH 2/6] video: stm: use DMA_ADDRESS_BROKEN instead of NULL Ahmad Fatoum
2024-10-14 12:58 ` [PATCH 3/6] crypto: caam - pbl-init: " Ahmad Fatoum
2024-10-14 12:58 ` Ahmad Fatoum [this message]
2024-10-14 12:58 ` [PATCH 5/6] net: macb: fix DMA_ADDRESS_BROKEN in the coherent ring allocations Ahmad Fatoum
2024-10-14 12:58 ` [PATCH 6/6] dma: give dma_alloc_coherent a device parameter Ahmad Fatoum
2024-10-15  7:41 ` [PATCH 0/6] " Sascha Hauer
2024-10-18  8:39 ` Sascha Hauer

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=20241014125843.2064532-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=denorl2009@gmail.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