From: Andrea Merello <andrea.merello@gmail.com>
To: linville@tuxdriver.com
Cc: linux-wireless@vger.kernel.org, Larry.Finger@lwfinger.net,
bernhard@schiffner-limbach.de, dan.carpenter@oracle.com,
liuhq11@mails.tsinghua.edu.cn,
andrea merello <andrea.merello@gmail.com>
Subject: [PATCH 3/7] rtl818x: check for pci_map_single() success when initializing RX ring
Date: Tue, 18 Feb 2014 02:10:42 +0100 [thread overview]
Message-ID: <1392685846-10116-4-git-send-email-andrea.merello@gmail.com> (raw)
In-Reply-To: <1392685846-10116-1-git-send-email-andrea.merello@gmail.com>
From: andrea merello <andrea.merello@gmail.com>
During initialization a number of RX skbs are allocated and mapped
for DMA.
Currently if pci_map_single() fails, it will result in passing to the
HW a wrong DMA address (to write to!).
This patch detects this condition, eventually it tries to get a more
luky skb, and if it finally fails to get things right, it makes the
driver not to initialize, avoiding at least dangerous DMAs.
Signed-off-by: Andrea Merello <andrea.merello@gmail.com>
---
drivers/net/wireless/rtl818x/rtl8180/dev.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c
index bf59ff9..848ea59 100644
--- a/drivers/net/wireless/rtl818x/rtl8180/dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c
@@ -458,6 +458,7 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev)
{
struct rtl8180_priv *priv = dev->priv;
struct rtl8180_rx_desc *entry;
+ int dma_map_fail_count = 0;
int i;
priv->rx_ring = pci_alloc_consistent(priv->pdev,
@@ -483,6 +484,19 @@ static int rtl8180_init_rx_ring(struct ieee80211_hw *dev)
mapping = (dma_addr_t *)skb->cb;
*mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb),
MAX_RX_SIZE, PCI_DMA_FROMDEVICE);
+
+ if (pci_dma_mapping_error(priv->pdev, *mapping)) {
+ kfree_skb(skb);
+ if (dma_map_fail_count++ > 32) {
+ wiphy_err(dev->wiphy, "Cannot map DMA for RX skb\n");
+ return -ENOMEM;
+ }
+
+ i--;
+ continue;
+ }
+
+
entry->rx_buf = cpu_to_le32(*mapping);
entry->flags = cpu_to_le32(RTL818X_RX_DESC_FLAG_OWN |
MAX_RX_SIZE);
--
1.8.3.2
next prev parent reply other threads:[~2014-02-18 1:10 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-18 1:10 [PATCH 0/7] rtl818x: second bunch of fixes ported from rtl8187se merge process Andrea Merello
2014-02-18 1:10 ` [PATCH 1/7] rtl818x: Explicitly enable contetion window Andrea Merello
2014-02-18 1:10 ` [PATCH 2/7] rtl818x: pci_iomap() should pair with pci_iounmap() Andrea Merello
2014-02-18 1:10 ` Andrea Merello [this message]
2014-02-18 9:31 ` [PATCH 3/7] rtl818x: check for pci_map_single() success when initializing RX ring Dan Carpenter
2014-02-18 18:05 ` Andrea Merello
2014-02-18 18:27 ` Dan Carpenter
2014-02-18 19:06 ` Andrea Merello
2014-02-18 19:22 ` Dan Carpenter
2014-02-18 20:17 ` Andrea Merello
2014-02-18 20:36 ` Dan Carpenter
2014-02-18 22:10 ` Andrea Merello
2014-02-22 16:57 ` [PATCH 3/7 V2] " Andrea Merello
2014-02-18 1:10 ` [PATCH 4/7] rtl818x: make dev_alloc_skb() null pointer check to really work Andrea Merello
2014-02-18 1:10 ` [PATCH 5/7] rtl818x: add comments to explain few not obvious HW configs Andrea Merello
2014-02-18 1:10 ` [PATCH 6/7] rtl818x: Make sure the TX descriptor "valid" flag is written by last Andrea Merello
2014-02-18 1:10 ` [PATCH 7/7] rtl818x: make sure TX descriptor writes are done before kicking DMA Andrea Merello
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=1392685846-10116-4-git-send-email-andrea.merello@gmail.com \
--to=andrea.merello@gmail.com \
--cc=Larry.Finger@lwfinger.net \
--cc=bernhard@schiffner-limbach.de \
--cc=dan.carpenter@oracle.com \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=liuhq11@mails.tsinghua.edu.cn \
/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).