aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMarek Szyprowski <m.szyprowski@samsung.com>2015-04-29 06:29:19 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2015-05-03 18:21:55 -0400
commit1424532b2163bf1580f4b1091a5801e12310fac5 (patch)
tree660249983a3f4cf6b190fa99cd9e44703b60a3b0 /arch
parentb787f68c36d49bb1d9236f403813641efa74a031 (diff)
ARM: 8347/1: dma-mapping: fix off-by-one check in arm_setup_iommu_dma_ops
Patch 22b3c181c6c324a46f71aae806d8ddbe61d25761 ("arm: dma-mapping: limit IOMMU mapping size") added a check for IO address space size. However this patch broke IOMMU initialization for typical platforms initialized from device tree, which get the default IO address space size of 4GiB. This value doesn't fit into size_t and fails a check introduced by that commit resulting in failed dma-mapping/iommu initialization. This patch fixes this issue by adding proper support for full 4GiB address space size. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/include/asm/dma-iommu.h2
-rw-r--r--arch/arm/mm/dma-mapping.c13
2 files changed, 6 insertions, 9 deletions
diff --git a/arch/arm/include/asm/dma-iommu.h b/arch/arm/include/asm/dma-iommu.h
index 8e3fcb924db6..2ef282f96651 100644
--- a/arch/arm/include/asm/dma-iommu.h
+++ b/arch/arm/include/asm/dma-iommu.h
@@ -25,7 +25,7 @@ struct dma_iommu_mapping {
25}; 25};
26 26
27struct dma_iommu_mapping * 27struct dma_iommu_mapping *
28arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size); 28arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size);
29 29
30void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping); 30void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping);
31 31
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 09c5fe3d30c2..7e7583ddd607 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1878,7 +1878,7 @@ struct dma_map_ops iommu_coherent_ops = {
1878 * arm_iommu_attach_device function. 1878 * arm_iommu_attach_device function.
1879 */ 1879 */
1880struct dma_iommu_mapping * 1880struct dma_iommu_mapping *
1881arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size) 1881arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, u64 size)
1882{ 1882{
1883 unsigned int bits = size >> PAGE_SHIFT; 1883 unsigned int bits = size >> PAGE_SHIFT;
1884 unsigned int bitmap_size = BITS_TO_LONGS(bits) * sizeof(long); 1884 unsigned int bitmap_size = BITS_TO_LONGS(bits) * sizeof(long);
@@ -1886,6 +1886,10 @@ arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size)
1886 int extensions = 1; 1886 int extensions = 1;
1887 int err = -ENOMEM; 1887 int err = -ENOMEM;
1888 1888
1889 /* currently only 32-bit DMA address space is supported */
1890 if (size > DMA_BIT_MASK(32) + 1)
1891 return ERR_PTR(-ERANGE);
1892
1889 if (!bitmap_size) 1893 if (!bitmap_size)
1890 return ERR_PTR(-EINVAL); 1894 return ERR_PTR(-EINVAL);
1891 1895
@@ -2057,13 +2061,6 @@ static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,
2057 if (!iommu) 2061 if (!iommu)
2058 return false; 2062 return false;
2059 2063
2060 /*
2061 * currently arm_iommu_create_mapping() takes a max of size_t
2062 * for size param. So check this limit for now.
2063 */
2064 if (size > SIZE_MAX)
2065 return false;
2066
2067 mapping = arm_iommu_create_mapping(dev->bus, dma_base, size); 2064 mapping = arm_iommu_create_mapping(dev->bus, dma_base, size);
2068 if (IS_ERR(mapping)) { 2065 if (IS_ERR(mapping)) {
2069 pr_warn("Failed to create %llu-byte IOMMU mapping for device %s\n", 2066 pr_warn("Failed to create %llu-byte IOMMU mapping for device %s\n",