* [PATCH] wifi: mt76: take into possible mt76_rx_token_consume failures
@ 2022-12-07 21:51 Lorenzo Bianconi
2022-12-08 10:41 ` Lorenzo Bianconi
0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Bianconi @ 2022-12-07 21:51 UTC (permalink / raw)
To: nbd; +Cc: lorenzo.bianconi, linux-wireless
Take into account possible error conditions of mt76_rx_token_consume
routine in mt7915_mmio_wed_init_rx_buf() and mt76_dma_add_buf()
Fixes: cd372b8c99c5 ("wifi: mt76: add WED RX support to mt76_dma_{add,get}_buf")
Fixes: 4f831d18d12d ("wifi: mt76: mt7915: enable WED RX support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
drivers/net/wireless/mediatek/mt76/dma.c | 10 +++++++++-
drivers/net/wireless/mediatek/mt76/mt7915/mmio.c | 7 +++++++
drivers/net/wireless/mediatek/mt76/tx.c | 6 ++++--
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
index e017d7529c2a..e1527a5a0b4d 100644
--- a/drivers/net/wireless/mediatek/mt76/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/dma.c
@@ -234,6 +234,9 @@ mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q,
rx_token = mt76_rx_token_consume(dev, (void *)skb, t,
buf[0].addr);
+ if (rx_token < 0)
+ return -ENOMEM;
+
buf1 |= FIELD_PREP(MT_DMA_CTL_TOKEN, rx_token);
ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len) |
MT_DMA_CTL_TO_HOST;
@@ -602,7 +605,12 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q)
qbuf.addr = addr + offset;
qbuf.len = len - offset;
qbuf.skip_unmap = false;
- mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t);
+ if (mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t) < 0) {
+ dma_unmap_single(dev->dma_dev, addr, len,
+ DMA_FROM_DEVICE);
+ skb_free_frag(buf);
+ break;
+ }
frames++;
}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
index 0a95c3da241b..8388e2a65853 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
@@ -653,6 +653,13 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
desc->buf0 = cpu_to_le32(phy_addr);
token = mt76_rx_token_consume(&dev->mt76, ptr, t, phy_addr);
+ if (token < 0) {
+ dma_unmap_single(dev->mt76.dma_dev, phy_addr,
+ wed->wlan.rx_size, DMA_TO_DEVICE);
+ skb_free_frag(ptr);
+ goto unmap;
+ }
+
desc->token |= cpu_to_le32(FIELD_PREP(MT_DMA_CTL_TOKEN,
token));
desc++;
diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c
index 24568b98ed9d..363d861a1d3e 100644
--- a/drivers/net/wireless/mediatek/mt76/tx.c
+++ b/drivers/net/wireless/mediatek/mt76/tx.c
@@ -766,8 +766,10 @@ int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
GFP_ATOMIC);
spin_unlock_bh(&dev->rx_token_lock);
- t->ptr = ptr;
- t->dma_addr = phys;
+ if (token >= 0) {
+ t->ptr = ptr;
+ t->dma_addr = phys;
+ }
return token;
}
--
2.38.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] wifi: mt76: take into possible mt76_rx_token_consume failures
2022-12-07 21:51 [PATCH] wifi: mt76: take into possible mt76_rx_token_consume failures Lorenzo Bianconi
@ 2022-12-08 10:41 ` Lorenzo Bianconi
0 siblings, 0 replies; 2+ messages in thread
From: Lorenzo Bianconi @ 2022-12-08 10:41 UTC (permalink / raw)
To: nbd; +Cc: lorenzo.bianconi, linux-wireless
[-- Attachment #1: Type: text/plain, Size: 3109 bytes --]
> Take into account possible error conditions of mt76_rx_token_consume
> routine in mt7915_mmio_wed_init_rx_buf() and mt76_dma_add_buf()
>
> Fixes: cd372b8c99c5 ("wifi: mt76: add WED RX support to mt76_dma_{add,get}_buf")
> Fixes: 4f831d18d12d ("wifi: mt76: mt7915: enable WED RX support")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Hi Felix,
please drop this version, I will post a new one.
Regards,
Lorenzo
> ---
> drivers/net/wireless/mediatek/mt76/dma.c | 10 +++++++++-
> drivers/net/wireless/mediatek/mt76/mt7915/mmio.c | 7 +++++++
> drivers/net/wireless/mediatek/mt76/tx.c | 6 ++++--
> 3 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
> index e017d7529c2a..e1527a5a0b4d 100644
> --- a/drivers/net/wireless/mediatek/mt76/dma.c
> +++ b/drivers/net/wireless/mediatek/mt76/dma.c
> @@ -234,6 +234,9 @@ mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q,
>
> rx_token = mt76_rx_token_consume(dev, (void *)skb, t,
> buf[0].addr);
> + if (rx_token < 0)
> + return -ENOMEM;
> +
> buf1 |= FIELD_PREP(MT_DMA_CTL_TOKEN, rx_token);
> ctrl = FIELD_PREP(MT_DMA_CTL_SD_LEN0, buf[0].len) |
> MT_DMA_CTL_TO_HOST;
> @@ -602,7 +605,12 @@ mt76_dma_rx_fill(struct mt76_dev *dev, struct mt76_queue *q)
> qbuf.addr = addr + offset;
> qbuf.len = len - offset;
> qbuf.skip_unmap = false;
> - mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t);
> + if (mt76_dma_add_buf(dev, q, &qbuf, 1, 0, buf, t) < 0) {
> + dma_unmap_single(dev->dma_dev, addr, len,
> + DMA_FROM_DEVICE);
> + skb_free_frag(buf);
> + break;
> + }
> frames++;
> }
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
> index 0a95c3da241b..8388e2a65853 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mmio.c
> @@ -653,6 +653,13 @@ static u32 mt7915_mmio_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
>
> desc->buf0 = cpu_to_le32(phy_addr);
> token = mt76_rx_token_consume(&dev->mt76, ptr, t, phy_addr);
> + if (token < 0) {
> + dma_unmap_single(dev->mt76.dma_dev, phy_addr,
> + wed->wlan.rx_size, DMA_TO_DEVICE);
> + skb_free_frag(ptr);
> + goto unmap;
> + }
> +
> desc->token |= cpu_to_le32(FIELD_PREP(MT_DMA_CTL_TOKEN,
> token));
> desc++;
> diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c
> index 24568b98ed9d..363d861a1d3e 100644
> --- a/drivers/net/wireless/mediatek/mt76/tx.c
> +++ b/drivers/net/wireless/mediatek/mt76/tx.c
> @@ -766,8 +766,10 @@ int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
> GFP_ATOMIC);
> spin_unlock_bh(&dev->rx_token_lock);
>
> - t->ptr = ptr;
> - t->dma_addr = phys;
> + if (token >= 0) {
> + t->ptr = ptr;
> + t->dma_addr = phys;
> + }
>
> return token;
> }
> --
> 2.38.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-08 10:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-07 21:51 [PATCH] wifi: mt76: take into possible mt76_rx_token_consume failures Lorenzo Bianconi
2022-12-08 10:41 ` Lorenzo Bianconi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox