From 24a170cd3061d5d85f6ab7cdceb0ac55458e0e02 Mon Sep 17 00:00:00 2001 From: Shreyansh Jain Date: Thu, 22 Jun 2017 19:27:15 +0530 Subject: [PATCH] bus/fslmc: add check for memseg availability Cleanup the DMA map logic for memsegs. Earlier, in case DMA mapping reaching end of segment, it reports a spurious error. Signed-off-by: Shreyansh Jain --- drivers/bus/fslmc/fslmc_vfio.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 8471a9a54a..49bb670c81 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -214,17 +214,18 @@ int rte_fslmc_vfio_dmamap(void) if (is_dma_done) return 0; - is_dma_done = 1; - for (i = 0; i < RTE_MAX_MEMSEG; i++) { - memseg = rte_eal_get_physmem_layout(); - if (memseg == NULL) { - FSLMC_VFIO_LOG(ERR, "Cannot get physical layout."); - return -ENODEV; - } + memseg = rte_eal_get_physmem_layout(); + if (memseg == NULL) { + FSLMC_VFIO_LOG(ERR, "Cannot get physical layout."); + return -ENODEV; + } - if (memseg[i].addr == NULL && memseg[i].len == 0) + for (i = 0; i < RTE_MAX_MEMSEG; i++) { + if (memseg[i].addr == NULL && memseg[i].len == 0) { + FSLMC_VFIO_LOG(DEBUG, "Total %d segments found.", i); break; + } dma_map.size = memseg[i].len; dma_map.vaddr = memseg[i].addr_64; @@ -254,12 +255,20 @@ int rte_fslmc_vfio_dmamap(void) } } + /* Verifying that at least single segment is available */ + if (i <= 0) { + FSLMC_VFIO_LOG(ERR, "No Segments found for VFIO Mapping"); + return -1; + } + /* TODO - This is a W.A. as VFIO currently does not add the mapping of * the interrupt region to SMMU. This should be removed once the * support is added in the Kernel. */ vfio_map_irq_region(group); + is_dma_done = 1; + return 0; } -- 2.20.1