Cleanup for xen/common/kexec.c
PATCH 1/1 Cleanup for xen/common/kexec.c
Hi!
Attached patch avoids void * arithmetic in xen/common/kexec.c
Christoph
xen/common/kexec.c +8 -8
@@ -27,7 +27,7 @@ typedef long ret_t;typedef long ret_t ;#define ELFNOTE_ALIGN (_n_) (((_n_)+3)&~3) -#define ELFNOTE_NAME (_n_) ((void*)(_n_) + sizeof(*(_n_))) +#define ELFNOTE_NAME (_n_) ((char*)(_n_) + sizeof(*(_n_)))#define ELFNOTE_DESC (_n_) (ELFNOTE_NAME(_n_) + ELFNOTE_ALIGN((_n_)->namesz))#define ELFNOTE_NEXT (_n_) (ELFNOTE_DESC(_n_) + ELFNOTE_ALIGN((_n_)->descsz))
@@ -75,10 +75,10 @@ void kexec_crash_save_cpu(void)if (cpu_test_and_set (cpu, crash_saved_cpus) )return ; - prstatus =ELFNOTE_DESC (note); - - note =ELFNOTE_NEXT (note); - xencore =ELFNOTE_DESC (note); + prstatus = (ELF_Prstatus *)ELFNOTE_DESC (note); + + note = (Elf_Note *)ELFNOTE_NEXT (note); + xencore = (crash_xen_core_t *)ELFNOTE_DESC (note);elf_core_save_regs (&prstatus->pr_reg, xencore); }
@@ -87,7 +87,7 @@ crash_xen_info_t *kexec_crash_save_info(crash_xen_info_t *kexec_crash_save_info (void ) {int cpu =smp_processor_id (); -crash_xen_info_t *info =ELFNOTE_DESC (xen_crash_note); +crash_xen_info_t *info = (crash_xen_info_t *)ELFNOTE_DESC (xen_crash_note);BUG_ON (!cpu_test_and_set (cpu, crash_saved_cpus));
@@ -191,13 +191,13 @@ static int kexec_get(cpu)(xen_kexec_rangsetup_note (note,"CORE" ,NT_PRSTATUS ,sizeof (ELF_Prstatus));/* Setup Xen CORE note. */ - note =ELFNOTE_NEXT (note); + note = (Elf_Note *)ELFNOTE_NEXT (note);setup_note (note,"Xen" ,XEN_ELFNOTE_CRASH_REGS ,sizeof (crash_xen_core_t));if (nr ==0 ) {/* Setup system wide Xen info note. */ - xen_crash_note = note =ELFNOTE_NEXT (note); + xen_crash_note = note = (Elf_Note *)ELFNOTE_NEXT (note);setup_note (note,"Xen" ,XEN_ELFNOTE_CRASH_INFO ,sizeof (crash_xen_info_t)); } }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 7 lines · Christoph Egger
#define
ELFNOTE_ALIGN(_n_)(((_n_)+3)&~3)xen/common/kexec.c +1
-1-#define ELFNOTE_NAME (_n_) ((void*)(_n_) + sizeof(*(_n_))) +#define ELFNOTE_NAME (_n_) ((char*)(_n_) + sizeof(*(_n_)))#define ELFNOTE_DESC (_n_) (ELFNOTE_NAME(_n_) + ELFNOTE_ALIGN((_n_)->namesz))#define ELFNOTE_NEXT (_n_) (ELFNOTE_DESC(_n_) + ELFNOTE_ALIGN((_n_)->descsz))
xen/common/kexec.c void kexec_crash_save_cpu(void) · line 80
Quoted 10 lines
xen/common/kexec.c +3
-4@@ -75,10 +75,10 @@ void kexec_crash_save_cpu(void)if (cpu_test_and_set (cpu, crash_saved_cpus) )return ; - prstatus =ELFNOTE_DESC (note); - - note =ELFNOTE_NEXT (note); - xencore =ELFNOTE_DESC (note); + prstatus = (ELF_Prstatus *)ELFNOTE_DESC (note); + + note = (Elf_Note *)ELFNOTE_NEXT (note);
Perhaps you could include the cast in the ELFNOTE_NEXT() macro instead of repeating it everywhere it is used?
Also, could the elfnote macros could be moved to a header? They are used in xen/common/elf.c too.
Ian.
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Christoph Egger
#define
ELFNOTE_ALIGN(_n_)(((_n_)+3)&~3)(quoted diff) +1
-1-#define ELFNOTE_NAME(_n_) ((void*)(_n_) + sizeof(*(_n_))) +#define ELFNOTE_NAME(_n_) ((char*)(_n_) + sizeof(*(_n_))) #define ELFNOTE_DESC(_n_) (ELFNOTE_NAME(_n_) +ELFNOTE_ALIGN((_n_)->namesz)) #define
ELFNOTE_NEXT(_n_)(ELFNOTE_DESC(_n_)+ ELFNOTE_ALIGN((_n_)->descsz))(quoted diff) +0
-0@@ -75,10 +75,10 @@ void kexec_crash_save_cpu(void) if ( cpu_test_and_set(cpu, crash_saved_cpus) ) return;
Quoted 10 lines
Review void kexec_crash_save_cpu(void) · line 80
Quoted 7 lines
(quoted diff) +3
-4- prstatus = ELFNOTE_DESC(note); - - note = ELFNOTE_NEXT(note); - xencore = ELFNOTE_DESC(note); + prstatus = (ELF_Prstatus *)ELFNOTE_DESC(note); + + note = (Elf_Note *)ELFNOTE_NEXT(note);Perhaps you could include the cast in the
ELFNOTE_NEXT()macro instead of repeating it everywhere it is used?
Here we go. Patch attached.
Quoted 2 lines
Also, could the elfnote macros could be moved to a header? They are used in
xen/common/elf.ctoo.
They are similar but not equal.
Christoph
xen/common/kexec.c +5 -5
@@ -27,9 +27,9 @@ typedef long ret_t;typedef long ret_t ;#define ELFNOTE_ALIGN (_n_) (((_n_)+3)&~3) -#define ELFNOTE_NAME (_n_) ((void*)(_n_) + sizeof(*(_n_))) +#define ELFNOTE_NAME (_n_) ((char*)(_n_) + sizeof(*(_n_)))#define ELFNOTE_DESC (_n_) (ELFNOTE_NAME(_n_) + ELFNOTE_ALIGN((_n_)->namesz)) -#define ELFNOTE_NEXT (_n_) (ELFNOTE_DESC(_n_) + ELFNOTE_ALIGN((_n_)->descsz)) +#define ELFNOTE_NEXT (_n_) ((Elf_Note *)(ELFNOTE_DESC(_n_) + ELFNOTE_ALIGN((_n_)->descsz))) static DEFINE_PER_CPU(void *, crash_notes);
@@ -75,10 +75,10 @@ void kexec_crash_save_cpu(void)if (cpu_test_and_set (cpu, crash_saved_cpus) )return ; - prstatus =ELFNOTE_DESC (note); + prstatus = (ELF_Prstatus *)ELFNOTE_DESC (note); note =ELFNOTE_NEXT (note); - xencore =ELFNOTE_DESC (note); + xencore = (crash_xen_core_t *)ELFNOTE_DESC (note);elf_core_save_regs (&prstatus->pr_reg, xencore); }
@@ -87,7 +87,7 @@ crash_xen_info_t *kexec_crash_save_info(crash_xen_info_t *kexec_crash_save_info (void ) {int cpu =smp_processor_id (); -crash_xen_info_t *info =ELFNOTE_DESC (xen_crash_note); +crash_xen_info_t *info = (crash_xen_info_t *)ELFNOTE_DESC (xen_crash_note);BUG_ON (!cpu_test_and_set (cpu, crash_saved_cpus));
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Ian Campbell
AppliedQuoted 5 lines · Christoph Egger
Quoted 2 lines · Ian Campbell
Perhaps you could include the cast in the
ELFNOTE_NEXT()macro instead of repeating it everywhere it is used?Here we go. Patch attached.
Thanks, applied.
Quoted 5 lines
Quoted 3 lines
Also, could the elfnote macros could be moved to a header? They are used in
xen/common/elf.ctoo.They are similar but not equal.
They were roughly equivalent, the one in kexec.c had just further abstracted ELFNOTE_ALIGN and the one in elf.c had an extra const on ELFNOTE_NAME.
I moved them into xen/elf.h.
Ian.