uprobes: Change __copy_insn() to use copy_from_page()

Change __copy_insn() to use copy_from_page() and simplify the code.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Anton Arapov <anton@redhat.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
This commit is contained in:
Oleg Nesterov 2013-03-24 18:37:48 +01:00
parent ab0d805c7b
commit 2edb7b5574

View File

@ -500,30 +500,21 @@ __copy_insn(struct address_space *mapping, struct file *filp, char *insn,
unsigned long nbytes, loff_t offset) unsigned long nbytes, loff_t offset)
{ {
struct page *page; struct page *page;
void *vaddr;
unsigned long off;
pgoff_t idx;
if (!filp) if (!filp)
return -EINVAL; return -EINVAL;
if (!mapping->a_ops->readpage) if (!mapping->a_ops->readpage)
return -EIO; return -EIO;
idx = offset >> PAGE_CACHE_SHIFT;
off = offset & ~PAGE_MASK;
/* /*
* Ensure that the page that has the original instruction is * Ensure that the page that has the original instruction is
* populated and in page-cache. * populated and in page-cache.
*/ */
page = read_mapping_page(mapping, idx, filp); page = read_mapping_page(mapping, offset >> PAGE_CACHE_SHIFT, filp);
if (IS_ERR(page)) if (IS_ERR(page))
return PTR_ERR(page); return PTR_ERR(page);
vaddr = kmap_atomic(page); copy_from_page(page, offset, insn, nbytes);
memcpy(insn, vaddr + off, nbytes);
kunmap_atomic(vaddr);
page_cache_release(page); page_cache_release(page);
return 0; return 0;