[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <8d40259f863ed1a077687f3c3d5b8b3707478170.1675632296.git.geoff@infradead.org>
Date: Sun, 05 Feb 2023 22:10:17 +0000
From: Geoff Levand <geoff@...radead.org>
To: netdev@...r.kernel.org, Jakub Kicinski <kuba@...nel.org>,
"David S. Miller" <davem@...emloft.net>
Subject: [PATCH net v4 2/2] net/ps3_gelic_net: Use dma_mapping_error
The current Gelic Etherenet driver was checking the return value of its
dma_map_single call, and not using the dma_mapping_error() routine.
Fixes runtime problems like these:
DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error
WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc
Fixes: 02c1889166b4 (ps3: gigabit ethernet driver for PS3, take3)
Signed-off-by: Geoff Levand <geoff@...radead.org>
---
drivers/net/ethernet/toshiba/ps3_gelic_net.c | 52 ++++++++++----------
1 file changed, 27 insertions(+), 25 deletions(-)
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 7a8b5e1e77a6..5622b512e2e4 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -309,22 +309,34 @@ static int gelic_card_init_chain(struct gelic_card *card,
struct gelic_descr_chain *chain,
struct gelic_descr *start_descr, int no)
{
- int i;
+ struct device *dev = ctodev(card);
struct gelic_descr *descr;
+ int i;
- descr = start_descr;
- memset(descr, 0, sizeof(*descr) * no);
+ memset(start_descr, 0, no * sizeof(*start_descr));
/* set up the hardware pointers in each descriptor */
- for (i = 0; i < no; i++, descr++) {
+ for (i = 0, descr = start_descr; i < no; i++, descr++) {
gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
descr->bus_addr =
dma_map_single(ctodev(card), descr,
GELIC_DESCR_SIZE,
DMA_BIDIRECTIONAL);
- if (!descr->bus_addr)
- goto iommu_error;
+ if (unlikely(dma_mapping_error(dev, descr->bus_addr))) {
+ dev_err(dev, "%s:%d: dma_mapping_error\n", __func__,
+ __LINE__);
+
+ for (i--, descr--; i > 0; i--, descr--) {
+ if (descr->bus_addr) {
+ dma_unmap_single(ctodev(card),
+ descr->bus_addr,
+ GELIC_DESCR_SIZE,
+ DMA_BIDIRECTIONAL);
+ }
+ }
+ return -ENOMEM;
+ }
descr->next = descr + 1;
descr->prev = descr - 1;
@@ -334,8 +346,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
start_descr->prev = (descr - 1);
/* chain bus addr of hw descriptor */
- descr = start_descr;
- for (i = 0; i < no; i++, descr++) {
+ for (i = 0, descr = start_descr; i < no; i++, descr++) {
descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
}
@@ -346,14 +357,6 @@ static int gelic_card_init_chain(struct gelic_card *card,
(descr - 1)->next_descr_addr = 0;
return 0;
-
-iommu_error:
- for (i--, descr--; 0 <= i; i--, descr--)
- if (descr->bus_addr)
- dma_unmap_single(ctodev(card), descr->bus_addr,
- GELIC_DESCR_SIZE,
- DMA_BIDIRECTIONAL);
- return -ENOMEM;
}
/**
@@ -407,19 +410,18 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
cpu_addr = dma_map_single(dev, descr->skb->data, descr->buf_size,
DMA_FROM_DEVICE);
- descr->buf_addr = cpu_to_be32(cpu_addr);
-
- if (!descr->buf_addr) {
+ if (unlikely(dma_mapping_error(dev, cpu_addr))) {
+ dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
dev_kfree_skb_any(descr->skb);
descr->buf_addr = 0;
descr->buf_size = 0;
descr->skb = NULL;
- dev_info(dev,
- "%s:Could not iommu-map rx buffer\n", __func__);
gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
return -ENOMEM;
}
+ descr->buf_addr = cpu_to_be32(cpu_addr);
+
gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
return 0;
}
@@ -775,6 +777,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
struct gelic_descr *descr,
struct sk_buff *skb)
{
+ struct device *dev = ctodev(card);
dma_addr_t buf;
if (card->vlan_required) {
@@ -789,11 +792,10 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
skb = skb_tmp;
}
- buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
+ buf = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
- if (!buf) {
- dev_err(ctodev(card),
- "dma map 2 failed (%p, %i). Dropping packet\n",
+ if (unlikely(dma_mapping_error(dev, buf))) {
+ dev_err(dev, "dma map 2 failed (%p, %i). Dropping packet\n",
skb->data, skb->len);
return -ENOMEM;
}
--
2.34.1
Powered by blists - more mailing lists