diff --git a/include/spdk/env.h b/include/spdk/env.h index a3ab17232..fceb814bf 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -1084,7 +1084,8 @@ int spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uin * \param map Memory map. * \param vaddr Virtual address. * \param size Contains the size of the memory region pointed to by vaddr. - * Updated with the size of the memory region for which the translation is valid. + * If vaddr is successfully translated, then this is updated with the size of + * the memory region for which the translation is valid. * * \return the translation of vaddr stored in the map, or default_translation * as specified in spdk_mem_map_alloc() if vaddr is not present in the map. diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index 7cfa5e4aa..02b1286a2 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -591,16 +591,10 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t uint64_t idx_256tb; uint64_t idx_1gb; uint64_t vfn_2mb; - uint64_t total_size = 0; uint64_t cur_size; uint64_t prev_translation; uint64_t orig_translation; - if (size != NULL) { - total_size = *size; - *size = 0; - } - if (spdk_unlikely(vaddr & ~MASK_256TB)) { DEBUG_PRINT("invalid usermode virtual address %p\n", (void *)vaddr); return map->default_translation; @@ -616,19 +610,18 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t } cur_size = VALUE_2MB - _2MB_OFFSET(vaddr); - if (size != NULL) { - *size = cur_size; - } - map_2mb = &map_1gb->map[idx_1gb]; if (size == NULL || map->ops.are_contiguous == NULL || map_2mb->translation_2mb == map->default_translation) { + if (size != NULL) { + *size = cur_size; + } return map_2mb->translation_2mb; } orig_translation = map_2mb->translation_2mb; prev_translation = orig_translation; - while (cur_size < total_size) { + while (cur_size < *size) { vfn_2mb++; idx_256tb = MAP_256TB_IDX(vfn_2mb); idx_1gb = MAP_1GB_IDX(vfn_2mb);