diff options
author | Alan Douglas <adouglas@cadence.com> | 2014-07-23 06:06:40 -0400 |
---|---|---|
committer | Max Filippov <jcmvbkbc@gmail.com> | 2014-08-14 03:59:14 -0400 |
commit | 1ca49463c44c970b1ab1d71b0f268bfdf8427a7e (patch) | |
tree | c6ece6e5481ac4a06803bc6ed8a2b7f8d3d653ae /arch/xtensa | |
parent | f61bf8e7d19e0a3456a7a9ed97c399e4353698dc (diff) |
xtensa: fix address checks in dma_{alloc,free}_coherent
Virtual address is translated to the XCHAL_KSEG_CACHED region in the
dma_free_coherent, but is checked to be in the 0...XCHAL_KSEG_SIZE
range.
Change check for end of the range from 'addr >= X' to 'addr > X - 1' to
handle the case of X == 0.
Replace 'if (C) BUG();' construct with 'BUG_ON(C);'.
Cc: stable@vger.kernel.org
Signed-off-by: Alan Douglas <adouglas@cadence.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Diffstat (limited to 'arch/xtensa')
-rw-r--r-- | arch/xtensa/kernel/pci-dma.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/arch/xtensa/kernel/pci-dma.c b/arch/xtensa/kernel/pci-dma.c index 2d9cc6dbfd78..e8b76b8e4b29 100644 --- a/arch/xtensa/kernel/pci-dma.c +++ b/arch/xtensa/kernel/pci-dma.c | |||
@@ -49,9 +49,8 @@ dma_alloc_coherent(struct device *dev,size_t size,dma_addr_t *handle,gfp_t flag) | |||
49 | 49 | ||
50 | /* We currently don't support coherent memory outside KSEG */ | 50 | /* We currently don't support coherent memory outside KSEG */ |
51 | 51 | ||
52 | if (ret < XCHAL_KSEG_CACHED_VADDR | 52 | BUG_ON(ret < XCHAL_KSEG_CACHED_VADDR || |
53 | || ret >= XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_SIZE) | 53 | ret > XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_SIZE - 1); |
54 | BUG(); | ||
55 | 54 | ||
56 | 55 | ||
57 | if (ret != 0) { | 56 | if (ret != 0) { |
@@ -68,10 +67,11 @@ EXPORT_SYMBOL(dma_alloc_coherent); | |||
68 | void dma_free_coherent(struct device *hwdev, size_t size, | 67 | void dma_free_coherent(struct device *hwdev, size_t size, |
69 | void *vaddr, dma_addr_t dma_handle) | 68 | void *vaddr, dma_addr_t dma_handle) |
70 | { | 69 | { |
71 | long addr=(long)vaddr+XCHAL_KSEG_CACHED_VADDR-XCHAL_KSEG_BYPASS_VADDR; | 70 | unsigned long addr = (unsigned long)vaddr + |
71 | XCHAL_KSEG_CACHED_VADDR - XCHAL_KSEG_BYPASS_VADDR; | ||
72 | 72 | ||
73 | if (addr < 0 || addr >= XCHAL_KSEG_SIZE) | 73 | BUG_ON(addr < XCHAL_KSEG_CACHED_VADDR || |
74 | BUG(); | 74 | addr > XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_SIZE - 1); |
75 | 75 | ||
76 | free_pages(addr, get_order(size)); | 76 | free_pages(addr, get_order(size)); |
77 | } | 77 | } |