Skip to content

Commit e017b1f

Browse files
davidhildenbrandmstsirkin
authored andcommitted
fs/proc/vmcore: factor out allocating a vmcore range and adding it to a list
Let's factor it out into include/linux/crash_dump.h, from where we can use it also outside of vmcore.c later. Acked-by: Baoquan He <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Message-Id: <[email protected]> Acked-by: Andrew Morton <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 819403c commit e017b1f

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

fs/proc/vmcore.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,6 @@ static const struct proc_ops vmcore_proc_ops = {
709709
.proc_mmap = mmap_vmcore,
710710
};
711711

712-
static struct vmcore_range * __init get_new_element(void)
713-
{
714-
return kzalloc(sizeof(struct vmcore_range), GFP_KERNEL);
715-
}
716-
717712
static u64 get_vmcore_size(size_t elfsz, size_t elfnotesegsz,
718713
struct list_head *vc_list)
719714
{
@@ -1116,7 +1111,6 @@ static int __init process_ptload_program_headers_elf64(char *elfptr,
11161111
size_t elfnotes_sz,
11171112
struct list_head *vc_list)
11181113
{
1119-
struct vmcore_range *new;
11201114
int i;
11211115
Elf64_Ehdr *ehdr_ptr;
11221116
Elf64_Phdr *phdr_ptr;
@@ -1139,13 +1133,8 @@ static int __init process_ptload_program_headers_elf64(char *elfptr,
11391133
end = roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE);
11401134
size = end - start;
11411135

1142-
/* Add this contiguous chunk of memory to vmcore list.*/
1143-
new = get_new_element();
1144-
if (!new)
1136+
if (vmcore_alloc_add_range(vc_list, start, size))
11451137
return -ENOMEM;
1146-
new->paddr = start;
1147-
new->size = size;
1148-
list_add_tail(&new->list, vc_list);
11491138

11501139
/* Update the program header offset. */
11511140
phdr_ptr->p_offset = vmcore_off + (paddr - start);
@@ -1159,7 +1148,6 @@ static int __init process_ptload_program_headers_elf32(char *elfptr,
11591148
size_t elfnotes_sz,
11601149
struct list_head *vc_list)
11611150
{
1162-
struct vmcore_range *new;
11631151
int i;
11641152
Elf32_Ehdr *ehdr_ptr;
11651153
Elf32_Phdr *phdr_ptr;
@@ -1182,13 +1170,8 @@ static int __init process_ptload_program_headers_elf32(char *elfptr,
11821170
end = roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE);
11831171
size = end - start;
11841172

1185-
/* Add this contiguous chunk of memory to vmcore list.*/
1186-
new = get_new_element();
1187-
if (!new)
1173+
if (vmcore_alloc_add_range(vc_list, start, size))
11881174
return -ENOMEM;
1189-
new->paddr = start;
1190-
new->size = size;
1191-
list_add_tail(&new->list, vc_list);
11921175

11931176
/* Update the program header offset */
11941177
phdr_ptr->p_offset = vmcore_off + (paddr - start);

include/linux/crash_dump.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ struct vmcore_range {
121121
loff_t offset;
122122
};
123123

124+
/* Allocate a vmcore range and add it to the list. */
125+
static inline int vmcore_alloc_add_range(struct list_head *list,
126+
unsigned long long paddr, unsigned long long size)
127+
{
128+
struct vmcore_range *m = kzalloc(sizeof(*m), GFP_KERNEL);
129+
130+
if (!m)
131+
return -ENOMEM;
132+
m->paddr = paddr;
133+
m->size = size;
134+
list_add_tail(&m->list, list);
135+
return 0;
136+
}
137+
124138
#else /* !CONFIG_CRASH_DUMP */
125139
static inline bool is_kdump_kernel(void) { return false; }
126140
#endif /* CONFIG_CRASH_DUMP */

0 commit comments

Comments
 (0)