treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / arm64 / kernel / crash_dump.c
blobe6e284265f19d1f7e5ffb3f9c2249f1b69f39f53
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Routines for doing kexec-based kdump
5 * Copyright (C) 2017 Linaro Limited
6 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
7 */
9 #include <linux/crash_dump.h>
10 #include <linux/errno.h>
11 #include <linux/io.h>
12 #include <linux/memblock.h>
13 #include <linux/uaccess.h>
14 #include <asm/memory.h>
16 /**
17 * copy_oldmem_page() - copy one page from old kernel memory
18 * @pfn: page frame number to be copied
19 * @buf: buffer where the copied page is placed
20 * @csize: number of bytes to copy
21 * @offset: offset in bytes into the page
22 * @userbuf: if set, @buf is in a user address space
24 * This function copies one page from old kernel memory into buffer pointed by
25 * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes
26 * copied or negative error in case of failure.
28 ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
29 size_t csize, unsigned long offset,
30 int userbuf)
32 void *vaddr;
34 if (!csize)
35 return 0;
37 vaddr = memremap(__pfn_to_phys(pfn), PAGE_SIZE, MEMREMAP_WB);
38 if (!vaddr)
39 return -ENOMEM;
41 if (userbuf) {
42 if (copy_to_user((char __user *)buf, vaddr + offset, csize)) {
43 memunmap(vaddr);
44 return -EFAULT;
46 } else {
47 memcpy(buf, vaddr + offset, csize);
50 memunmap(vaddr);
52 return csize;
55 /**
56 * elfcorehdr_read - read from ELF core header
57 * @buf: buffer where the data is placed
58 * @count: number of bytes to read
59 * @ppos: address in the memory
61 * This function reads @count bytes from elf core header which exists
62 * on crash dump kernel's memory.
64 ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
66 memcpy(buf, phys_to_virt((phys_addr_t)*ppos), count);
67 return count;