The returned value of lseek is a virtual address which can be different from the offset. Indeed, if the return address has a 64-bit canonical form, the 16 higher bits are all 1 if bit 47 is 1.
So the check was wrong. It is better to test against an error value. Acked-by: Damien Millescamps <damien.millescamps at 6wind.com> Signed-off-by: Thomas Monjalon <thomas.monjalon at 6wind.com> --- lib/librte_eal/linuxapp/eal/eal_memory.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index a47dab4..30a955f 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -2,6 +2,7 @@ * BSD LICENSE * * Copyright(c) 2010-2012 Intel Corporation. All rights reserved. + * Copyright(c) 2012-2013 6WIND. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -292,7 +293,7 @@ find_physaddr(struct hugepage *hugepg_tbl, struct hugepage_info *hpi) virt_pfn = (unsigned long)hugepg_tbl[i].orig_va / page_size; offset = sizeof(uint64_t) * virt_pfn; - if (lseek(fd, offset, SEEK_SET) != offset){ + if (lseek(fd, offset, SEEK_SET) == (off_t) -1) { RTE_LOG(ERR, EAL, "%s(): seek error in /proc/self/pagemap: %s", __func__, strerror(errno)); close(fd); -- 1.7.2.5