From ece4a53416de7c78d397eae80506e704639fca35 Mon Sep 17 00:00:00 2001 From: Susheel Khiani Date: Tue, 15 Dec 2015 16:47:56 +0530 Subject: [PATCH] dma-mapping: Check for valid IOVA address We might fail in alloc_iova if we run out of virtual addresses in pool. Currently, if we fail in alloc_iova we are not checking for return value and directly going ahead and mapping invalid IOVA address. Fix this by explicitly checking for return value from alloc_iova. Change-Id: I7681d13b75f47a86f0b0b6cbf4b8405a7528ff66 Signed-off-by: Susheel Khiani --- arch/arm/mm/dma-mapping.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 9932ba9a59f4..ce1c0b40bb9b 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1738,6 +1738,12 @@ int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg, total_length += s->length; iova = __alloc_iova(mapping, total_length); + + if (iova == DMA_ERROR_CODE) { + dev_err(dev, "Couldn't allocate iova for sg %p\n", sg); + return 0; + } + ret = iommu_map_sg(mapping->domain, iova, sg, nents, prot); if (ret != total_length) { __free_iova(mapping, iova, total_length);