All pastes #511585 Raw Edit

Unnamed

public c v1 · immutable
#511585 ·published 2007-05-26 15:13 UTC
rendered paste body
static int test_check(struct test_region *region){        struct page **pages;        int nr_pages;        int result = 0;        int i;        int *test;        pages = kmalloc(sizeof(struct page *) * region->nr_pages, GFP_KERNEL);        if (!pages)                return -ENOMEM;        down_read(&current->mm->mmap_sem);        nr_pages = get_user_pages(current, current->mm,                                  region->addr,                                  region->nr_pages,                                  1, 0,                                  pages, NULL);        /* kmap_atomic would be faster but we want to map over a long time and want to use cache advantages */        test = (int *)kmap(*pages);        printk(KERN_ERR "TEST: check value: %d\n", *test);        kunmap(*pages);        up_read(&current->mm->mmap_sem);        if (region->nr_pages != nr_pages) {                result = -EFAULT;                goto get_err;        }        for (i = 0; i < nr_pages; i++) {                if (region->pages[i] != pages[i])                        printk(KERN_ERR "TEST: Check error <%p:%p> "                               "page <%u> of <%u>\n",                               pages[i], region->pages[i], i, nr_pages);                put_page(pages[i]);        }get_err:        kfree(pages);        return result;}