From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: "Anders Grafström" <grfstrm@users.sourceforge.net>
Cc: linux-arm-kernel@lists.arm.linux.org.uk, netdev@vger.kernel.org
Subject: Re: Validation of DMA params breaks e100 driver (2.6.28-rc2)
Date: Fri, 31 Oct 2008 21:01:32 +0000 [thread overview]
Message-ID: <20081031210131.GA18015@flint.arm.linux.org.uk> (raw)
In-Reply-To: <4909E08F.9040306@users.sourceforge.net>
On Thu, Oct 30, 2008 at 05:27:59PM +0100, Anders Grafström wrote:
> The e100 driver triggers BUG_ON(buf->direction != dir)
> by doing pci_map_single(..., PCI_DMA_BIDIRECTIONAL)
> and pci_dma_sync_single_for_device(..., PCI_DMA_TODEVICE).
>
> I'm guessing it's allowed to do that and that something like
> the patch below is called for?
No, it is not allowed to do that - that's why it's called "BUG_ON".
Changing the DMA direction, especially with dmabounce will result
in unexpected behaviour.
> -----------------
>
> [PATCH] [ARM] dma: Fix DMA params validation
>
> This patch makes the DMA params validation less strict
> and more like the generic implementation.
>
> Signed-off-by: Anders Grafström <grfstrm@users.sourceforge.net>
> ---
> arch/arm/common/dmabounce.c | 13 ++++++-------
> 1 files changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c
> index f030f07..a0c9c7b 100644
> --- a/arch/arm/common/dmabounce.c
> +++ b/arch/arm/common/dmabounce.c
> @@ -289,7 +289,6 @@ static inline void unmap_single(struct device *dev, dma_addr_t dma_addr,
>
> if (buf) {
> BUG_ON(buf->size != size);
> - BUG_ON(buf->direction != dir);
>
> dev_dbg(dev,
> "%s: unsafe buffer %p (dma=%#x) mapped to %p (dma=%#x)\n",
> @@ -382,8 +381,6 @@ int dmabounce_sync_for_cpu(struct device *dev, dma_addr_t addr,
> if (!buf)
> return 1;
>
> - BUG_ON(buf->direction != dir);
> -
> dev_dbg(dev, "%s: unsafe buffer %p (dma=%#x) mapped to %p (dma=%#x)\n",
> __func__, buf->ptr, virt_to_dma(dev, buf->ptr),
> buf->safe, buf->safe_dma_addr);
> @@ -394,7 +391,9 @@ int dmabounce_sync_for_cpu(struct device *dev, dma_addr_t addr,
> dev_dbg(dev, "%s: copy back safe %p to unsafe %p size %d\n",
> __func__, buf->safe + off, buf->ptr + off, sz);
> memcpy(buf->ptr + off, buf->safe + off, sz);
> - }
> + } else
> + BUG_ON(dir != DMA_TO_DEVICE);
> +
> return 0;
> }
> EXPORT_SYMBOL(dmabounce_sync_for_cpu);
> @@ -411,8 +410,6 @@ int dmabounce_sync_for_device(struct device *dev, dma_addr_t addr,
> if (!buf)
> return 1;
>
> - BUG_ON(buf->direction != dir);
> -
> dev_dbg(dev, "%s: unsafe buffer %p (dma=%#x) mapped to %p (dma=%#x)\n",
> __func__, buf->ptr, virt_to_dma(dev, buf->ptr),
> buf->safe, buf->safe_dma_addr);
> @@ -423,7 +420,9 @@ int dmabounce_sync_for_device(struct device *dev, dma_addr_t addr,
> dev_dbg(dev, "%s: copy out unsafe %p to safe %p, size %d\n",
> __func__,buf->ptr + off, buf->safe + off, sz);
> memcpy(buf->safe + off, buf->ptr + off, sz);
> - }
> + } else
> + BUG_ON(dir != DMA_FROM_DEVICE);
> +
> return 0;
> }
> EXPORT_SYMBOL(dmabounce_sync_for_device);
> --
> 1.5.6.5
>
>
next parent reply other threads:[~2008-10-31 21:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4909E08F.9040306@users.sourceforge.net>
2008-10-31 21:01 ` Russell King - ARM Linux [this message]
2008-11-14 1:21 ` Validation of DMA params breaks e100 driver (2.6.28-rc2) Brandeburg, Jesse
2008-11-14 2:42 ` David Miller
2008-11-14 20:37 ` Anders Grafström
2008-11-14 22:30 ` Brandeburg, Jesse
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=20081031210131.GA18015@flint.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=grfstrm@users.sourceforge.net \
--cc=linux-arm-kernel@lists.arm.linux.org.uk \
--cc=netdev@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.