unsigned long is not the right type for manipulating pointer values. Since C99 there are suitable unsigned and signed types available, namely uintptr_t and intptr_t respectively.
Use them in physmap.c where applicable. This should be done in a lot of other places in flashrom too, but that's a huge pile of work and we better start it with a small step than never (which is the forseeable alternative ;)
This patch also changes the display width of all address values in physmap.c to 16/8 hex characters depending on the architecture.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- physmap.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/physmap.c b/physmap.c index a9445d5..8b9fea7 100644 --- a/physmap.c +++ b/physmap.c @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#include <inttypes.h> #include <unistd.h> #include <stdbool.h> #include <stdio.h> @@ -35,6 +36,8 @@ #include <errno.h> #endif
+#define PRIxPTR_WIDTH ((int)(sizeof(uintptr_t)*2)) + #ifdef __DJGPP__ #include <dpmi.h> #include <sys/nearptr.h> @@ -43,7 +46,7 @@
static void *realmem_map;
-static void *map_first_meg(unsigned long phys_addr, size_t len) +static void *map_first_meg(uintptr_t phys_addr, size_t len) { if (realmem_map) return realmem_map + phys_addr; @@ -62,7 +65,7 @@ static void *map_first_meg(unsigned long phys_addr, size_t len) return realmem_map + phys_addr; }
-static void *sys_physmap(unsigned long phys_addr, size_t len) +static void *sys_physmap(uintptr_t phys_addr, size_t len) { int ret; __dpmi_meminfo mi; @@ -110,7 +113,7 @@ void physunmap(void *virt_addr, size_t len)
#define MEM_DEV ""
-void *sys_physmap(unsigned long phys_addr, size_t len) +void *sys_physmap(uintptr_t phys_addr, size_t len) { return (void *)phys_to_virt(phys_addr); } @@ -134,7 +137,7 @@ void cleanup_cpu_msr(void)
#define MEM_DEV "DirectHW"
-static void *sys_physmap(unsigned long phys_addr, size_t len) +static void *sys_physmap(uintptr_t phys_addr, size_t len) { /* The short form of ?: is a GNU extension. * FIXME: map_physical returns NULL both for errors and for success @@ -166,7 +169,7 @@ static int fd_mem = -1; static int fd_mem_cached = -1;
/* For MMIO access. Must be uncached, doesn't make sense to restrict to ro. */ -static void *sys_physmap_rw_uncached(unsigned long phys_addr, size_t len) +static void *sys_physmap_rw_uncached(uintptr_t phys_addr, size_t len) { void *virt_addr;
@@ -186,7 +189,7 @@ static void *sys_physmap_rw_uncached(unsigned long phys_addr, size_t len) /* For reading DMI/coreboot/whatever tables. We should never write, and we * do not care about caching. */ -static void *sys_physmap_ro_cached(unsigned long phys_addr, size_t len) +static void *sys_physmap_ro_cached(uintptr_t phys_addr, size_t len) { void *virt_addr;
@@ -232,14 +235,13 @@ static int physmap_shutdown(void *data) return 0; }
-static void *physmap_common(const char *descr, unsigned long phys_addr, size_t len, bool mayfail, +static void *physmap_common(const char *descr, uintptr_t phys_addr, size_t len, bool mayfail, bool readonly, bool autocleanup) { void *virt_addr;
if (len == 0) { - msg_pspew("Not mapping %s, zero size at 0x%08lx.\n", - descr, phys_addr); + msg_pspew("Not mapping %s, zero size at 0x%0*" PRIxPTR ".\n", descr, PRIxPTR_WIDTH, phys_addr); return ERROR_PTR; }
@@ -261,8 +263,8 @@ static void *physmap_common(const char *descr, unsigned long phys_addr, size_t l if (ERROR_PTR == virt_addr) { if (NULL == descr) descr = "memory"; - msg_perr("Error accessing %s, 0x%lx bytes at 0x%08lx\n", descr, - (unsigned long)len, phys_addr); + msg_perr("Error accessing %s, 0x%0zx bytes at 0x%0*" PRIxPTR "\n", + descr, len, PRIxPTR_WIDTH, phys_addr); perror(MEM_DEV " mmap failed"); #ifdef __linux__ if (EINVAL == errno) { @@ -302,17 +304,17 @@ unmap_out: return ERROR_PTR; }
-void *physmap(const char *descr, unsigned long phys_addr, size_t len) +void *physmap(const char *descr, uintptr_t phys_addr, size_t len) { return physmap_common(descr, phys_addr, len, false, false, false); }
-void *physmap_autocleanup(const char *descr, unsigned long phys_addr, size_t len) +void *physmap_autocleanup(const char *descr, uintptr_t phys_addr, size_t len) { return physmap_common(descr, phys_addr, len, false, false, true); }
-void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len) +void *physmap_try_ro(const char *descr, uintptr_t phys_addr, size_t len) { return physmap_common(descr, phys_addr, len, true, true, false); }