hello_fft: Fixup offset calculation when mapping/unmapping buffers
authorpopcornmix <popcornmix@gmail.com>
Fri, 14 Jul 2017 13:48:11 +0000 (14:48 +0100)
committerpopcornmix <popcornmix@gmail.com>
Tue, 22 Aug 2017 14:19:55 +0000 (15:19 +0100)
See: https://github.com/raspberrypi/userland/issues/408

host_applications/linux/apps/hello_pi/hello_fft/mailbox.c

index 2958d33eb66c013a61e9e30f460fcb4e1c650ab8..de44e81229d30080c9b101247db7a56d3b3c9abc 100644 (file)
@@ -44,6 +44,7 @@ void *mapmem(unsigned base, unsigned size)
    int mem_fd;
    unsigned offset = base % PAGE_SIZE;
    base = base - offset;
+   size = size + offset;
    /* open /dev/mem */
    if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
       printf("can't open /dev/mem\nThis program should be run as root. Try prefixing command with: sudo\n");
@@ -69,6 +70,9 @@ void *mapmem(unsigned base, unsigned size)
 
 void unmapmem(void *addr, unsigned size)
 {
+   const intptr_t offset = (intptr_t)addr % PAGE_SIZE;
+   addr = (char *)addr - offset;
+   size = size + offset;
    int s = munmap(addr, size);
    if (s != 0) {
       printf("munmap error %d\n", s);