Skip to content

Commit 51dbd92

Browse files
Hari Bathinitorvalds
authored andcommitted
ia64: reuse append_elf_note() and final_note() functions
Get rid of multiple definitions of append_elf_note() & final_note() functions. Reuse these functions compiled under CONFIG_CRASH_CORE Also, define Elf_Word and use it instead of generic u32 or the more specific Elf64_Word. Link: http://lkml.kernel.org/r/149035342324.6881.11667840929850361402.stgit@hbathini.in.ibm.com Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com> Acked-by: Dave Young <dyoung@redhat.com> Acked-by: Tony Luck <tony.luck@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 692f66f commit 51dbd92

5 files changed

Lines changed: 20 additions & 70 deletions

File tree

‎arch/ia64/kernel/crash.c‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,6 @@ static int kdump_freeze_monarch;
2727
static int kdump_on_init = 1;
2828
static int kdump_on_fatal_mca = 1;
2929

30-
static inline Elf64_Word
31-
*append_elf_note(Elf64_Word *buf, char *name, unsigned type, void *data,
32-
size_t data_len)
33-
{
34-
struct elf_note *note = (struct elf_note *)buf;
35-
note->n_namesz = strlen(name) + 1;
36-
note->n_descsz = data_len;
37-
note->n_type = type;
38-
buf += (sizeof(*note) + 3)/4;
39-
memcpy(buf, name, note->n_namesz);
40-
buf += (note->n_namesz + 3)/4;
41-
memcpy(buf, data, data_len);
42-
buf += (data_len + 3)/4;
43-
return buf;
44-
}
45-
46-
static void
47-
final_note(void *buf)
48-
{
49-
memset(buf, 0, sizeof(struct elf_note));
50-
}
51-
5230
extern void ia64_dump_cpu_regs(void *);
5331

5432
static DEFINE_PER_CPU(struct elf_prstatus, elf_prstatus);

‎include/linux/crash_core.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
5555
extern size_t vmcoreinfo_size;
5656
extern size_t vmcoreinfo_max_size;
5757

58+
Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
59+
void *data, size_t data_len);
60+
void final_note(Elf_Word *buf);
61+
5862
int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
5963
unsigned long long *crash_size, unsigned long long *crash_base);
6064
int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,

‎include/linux/elf.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern Elf32_Dyn _DYNAMIC [];
2929
#define elf_note elf32_note
3030
#define elf_addr_t Elf32_Off
3131
#define Elf_Half Elf32_Half
32+
#define Elf_Word Elf32_Word
3233

3334
#else
3435

@@ -39,6 +40,7 @@ extern Elf64_Dyn _DYNAMIC [];
3940
#define elf_note elf64_note
4041
#define elf_addr_t Elf64_Off
4142
#define Elf_Half Elf64_Half
43+
#define Elf_Word Elf64_Word
4244

4345
#endif
4446

‎kernel/crash_core.c‎

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -291,32 +291,26 @@ int __init parse_crashkernel_low(char *cmdline,
291291
"crashkernel=", suffix_tbl[SUFFIX_LOW]);
292292
}
293293

294-
static u32 *append_elf_note(u32 *buf, char *name, unsigned int type,
295-
void *data, size_t data_len)
294+
Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
295+
void *data, size_t data_len)
296296
{
297-
struct elf_note note;
298-
299-
note.n_namesz = strlen(name) + 1;
300-
note.n_descsz = data_len;
301-
note.n_type = type;
302-
memcpy(buf, &note, sizeof(note));
303-
buf += (sizeof(note) + 3)/4;
304-
memcpy(buf, name, note.n_namesz);
305-
buf += (note.n_namesz + 3)/4;
306-
memcpy(buf, data, note.n_descsz);
307-
buf += (note.n_descsz + 3)/4;
297+
struct elf_note *note = (struct elf_note *)buf;
298+
299+
note->n_namesz = strlen(name) + 1;
300+
note->n_descsz = data_len;
301+
note->n_type = type;
302+
buf += DIV_ROUND_UP(sizeof(*note), sizeof(Elf_Word));
303+
memcpy(buf, name, note->n_namesz);
304+
buf += DIV_ROUND_UP(note->n_namesz, sizeof(Elf_Word));
305+
memcpy(buf, data, data_len);
306+
buf += DIV_ROUND_UP(data_len, sizeof(Elf_Word));
308307

309308
return buf;
310309
}
311310

312-
static void final_note(u32 *buf)
311+
void final_note(Elf_Word *buf)
313312
{
314-
struct elf_note note;
315-
316-
note.n_namesz = 0;
317-
note.n_descsz = 0;
318-
note.n_type = 0;
319-
memcpy(buf, &note, sizeof(note));
313+
memset(buf, 0, sizeof(struct elf_note));
320314
}
321315

322316
static void update_vmcoreinfo_note(void)

‎kernel/kexec_core.c‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -990,34 +990,6 @@ int crash_shrink_memory(unsigned long new_size)
990990
return ret;
991991
}
992992

993-
static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data,
994-
size_t data_len)
995-
{
996-
struct elf_note note;
997-
998-
note.n_namesz = strlen(name) + 1;
999-
note.n_descsz = data_len;
1000-
note.n_type = type;
1001-
memcpy(buf, &note, sizeof(note));
1002-
buf += (sizeof(note) + 3)/4;
1003-
memcpy(buf, name, note.n_namesz);
1004-
buf += (note.n_namesz + 3)/4;
1005-
memcpy(buf, data, note.n_descsz);
1006-
buf += (note.n_descsz + 3)/4;
1007-
1008-
return buf;
1009-
}
1010-
1011-
static void final_note(u32 *buf)
1012-
{
1013-
struct elf_note note;
1014-
1015-
note.n_namesz = 0;
1016-
note.n_descsz = 0;
1017-
note.n_type = 0;
1018-
memcpy(buf, &note, sizeof(note));
1019-
}
1020-
1021993
void crash_save_cpu(struct pt_regs *regs, int cpu)
1022994
{
1023995
struct elf_prstatus prstatus;

0 commit comments

Comments
 (0)