From: "Arend van Spriel" <arend@broadcom.com>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: linux-wireless@vger.kernel.org,
"brcm80211 development" <brcm80211-dev-list@broadcom.com>
Subject: Re: [RFC] brcmsmac: check return from dma_map_single
Date: Wed, 3 Oct 2012 11:08:01 +0200 [thread overview]
Message-ID: <506C0071.1000707@broadcom.com> (raw)
In-Reply-To: <1349203585-16095-1-git-send-email-linville@tuxdriver.com>
On 10/02/2012 08:46 PM, John W. Linville wrote:
> From: "John W. Linville" <linville@tuxdriver.com>
>
> dma_map_single can fail, so it's return value needs to be checked and
> handled accordingly. Failure to do so is akin to failing to check the
> return from a kmalloc.
>
> http://linuxdriverproject.org/mediawiki/index.php/DMA_Mapping_Error_Analysis
>
> Signed-off-by: John W. Linville <linville@tuxdriver.com>
> Cc: Arend van Spriel <arend@broadcom.com>
> ---
> I'm not too sure about the bail-out in dma_rxfill. Perhaps the experts
> can suggest something better?
>
> drivers/net/wireless/brcm80211/brcmsmac/dma.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/wireless/brcm80211/brcmsmac/dma.c b/drivers/net/wireless/brcm80211/brcmsmac/dma.c
> index 5e53305..fa24c58 100644
> --- a/drivers/net/wireless/brcm80211/brcmsmac/dma.c
> +++ b/drivers/net/wireless/brcm80211/brcmsmac/dma.c
> @@ -1079,6 +1079,10 @@ bool dma_rxfill(struct dma_pub *pub)
>
> pa = dma_map_single(di->dmadev, p->data, di->rxbufsize,
> DMA_FROM_DEVICE);
> + if (dma_mapping_error(di->dmadev, pa)) {
> + brcmu_pkt_buf_free_skb(p);
> + break;
> + }
I noticed the calling function is ignoring any error returned by
dma_rxfill(). I am not sure what to do here when this mapping error
happens after being halfway the for loop filling the dma with receive
buffers. The function is being called on mac80211 .start() callback so
we have to pass the failure back to that.
> /* save the free packet pointer */
> di->rxp[rxout] = p;
> @@ -1293,13 +1297,15 @@ int dma_txfast(struct dma_pub *pub, struct sk_buff *p, bool commit)
> if (len == 0)
> return 0;
>
> + /* get physical address of buffer start */
> + pa = dma_map_single(di->dmadev, data, len, DMA_TO_DEVICE);
> + if (dma_mapping_error(di->dmadev, pa))
> + return -1;
> +
Same for dma_txfast() and from DMA-API.txt I understand the buffer needs
to be freed:
- checking the returned dma_addr_t of dma_map_single and dma_map_page
by using dma_mapping_error():
dma_addr_t dma_handle;
dma_handle = dma_map_single(dev, addr, size, direction);
if (dma_mapping_error(dev, dma_handle)) {
/*
* reduce current DMA mapping usage,
* delay and try again later or
* reset driver.
*/
}
Networking drivers must call dev_kfree_skb to free the socket buffer
and return NETDEV_TX_OK if the DMA mapping fails on the transmit hook
(ndo_start_xmit). This means that the socket buffer is just dropped in
the failure case.
> /* return nonzero if out of tx descriptors */
> if (nexttxd(di, txout) == di->txin)
> goto outoftxd;
>
> - /* get physical address of buffer start */
> - pa = dma_map_single(di->dmadev, data, len, DMA_TO_DEVICE);
> -
> /* With a DMA segment list, Descriptor table is filled
> * using the segment list instead of looping over
> * buffers in multi-chain DMA. Therefore, EOF for SGLIST
>
I will discuss how we should handle the error flows given the options
mentioned in the DMA-API pseudo-code above.
Gr. AvS
prev parent reply other threads:[~2012-10-03 9:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-02 18:46 [RFC] brcmsmac: check return from dma_map_single John W. Linville
2012-10-03 9:08 ` Arend van Spriel [this message]
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=506C0071.1000707@broadcom.com \
--to=arend@broadcom.com \
--cc=brcm80211-dev-list@broadcom.com \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.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;
as well as URLs for NNTP newsgroup(s).