Use DEFINE_SYMBOL and the two static inline functions that come with it for comparisons and subtractions of:
__note_gnu_build_id_start, __note_gnu_build_id_end, __lock_profile_start, __lock_profile_end, __initcall_start, __initcall_end, __presmp_initcall_end, __ctors_start, __ctors_end, __end_schedulers_array, __start_schedulers_array, __start_bug_frames, __stop_bug_frames_0, __stop_bug_frames_1, __stop_bug_frames_2, __stop_bug_frames_3, Use explicit casts to uintptr_t when it is not possible to use the provided static inline functions. M3CM: Rule-18.2: Subtraction between pointers shall only be applied to pointers that address elements of the same array Since we are changing the body of is_kernel_text and friends, take the opportunity to remove the leading underscores in the local variables names, which are violationg namespace rules. Also make the local p__ variable const. https://wiki.sei.cmu.edu/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+pointers+that+do+not+refer+to+the+same+array QAVerify: 2761 Signed-off-by: Stefano Stabellini <stefa...@xilinx.com> CC: jbeul...@suse.com CC: andrew.coop...@citrix.com --- Changes in v10: - use DEFINE_SYMBOL - move changes for _start, _end, _stext, _etext, _srodata, _erodata, _sinittext, _einittext to a different patch Changes in v9: - use SYMBOLS_SUBTRACT and SYMBOLS_COMPARE --- xen/common/kernel.c | 12 ++++++++++-- xen/common/lib.c | 7 +++++-- xen/common/schedule.c | 6 ++++-- xen/common/spinlock.c | 8 +++++--- xen/common/version.c | 9 +++++---- xen/common/virtual_region.c | 4 +++- 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 5766a0f..f6c8d80 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -306,20 +306,28 @@ void add_taint(unsigned int flag) tainted |= flag; } +/* + * We cannot use DEFINE_SYMBOL because we have three variables instead + * of two + */ extern const initcall_t __initcall_start[], __presmp_initcall_end[], __initcall_end[]; void __init do_presmp_initcalls(void) { const initcall_t *call; - for ( call = __initcall_start; call < __presmp_initcall_end; call++ ) + for ( call = __initcall_start; + (uintptr_t)call < (uintptr_t)__presmp_initcall_end; + call++ ) (*call)(); } void __init do_initcalls(void) { const initcall_t *call; - for ( call = __presmp_initcall_end; call < __initcall_end; call++ ) + for ( call = __presmp_initcall_end; + (uintptr_t)call < (uintptr_t)__initcall_end; + call++ ) (*call)(); } diff --git a/xen/common/lib.c b/xen/common/lib.c index 8ebec81..0b2105a 100644 --- a/xen/common/lib.c +++ b/xen/common/lib.c @@ -492,12 +492,15 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps) } typedef void (*ctor_func_t)(void); -extern const ctor_func_t __ctors_start[], __ctors_end[]; +DEFINE_SYMBOL(ctor_func_t, ctor_func, __ctors_start, __ctors_end); void __init init_constructors(void) { const ctor_func_t *f; - for ( f = __ctors_start; f < __ctors_end; ++f ) + + for ( f = __ctors_start; + ctor_func_lt(f, __ctors_end); + ++f ) (*f)(); /* Putting this here seems as good (or bad) as any other place. */ diff --git a/xen/common/schedule.c b/xen/common/schedule.c index a957c5e..ac3f9af 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -67,8 +67,10 @@ DEFINE_PER_CPU(struct scheduler *, scheduler); /* Scratch space for cpumasks. */ DEFINE_PER_CPU(cpumask_t, cpumask_scratch); -extern const struct scheduler *__start_schedulers_array[], *__end_schedulers_array[]; -#define NUM_SCHEDULERS (__end_schedulers_array - __start_schedulers_array) +DEFINE_SYMBOL(struct scheduler *, schedulers, __start_schedulers_array, + __end_schedulers_array); +#define NUM_SCHEDULERS (schedulers_diff(__start_schedulers_array, \ + __end_schedulers_array)) #define schedulers __start_schedulers_array static struct scheduler __read_mostly ops; diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 6bc52d7..2d04bf8 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -318,8 +318,8 @@ struct lock_profile_anc { typedef void lock_profile_subfunc( struct lock_profile *, int32_t, int32_t, void *); -extern struct lock_profile *__lock_profile_start; -extern struct lock_profile *__lock_profile_end; +DEFINE_SYMBOL(struct lock_profile *, lock_profile, __lock_profile_start, + __lock_profile_end); static s_time_t lock_profile_start; static struct lock_profile_anc lock_profile_ancs[LOCKPROF_TYPE_N]; @@ -474,7 +474,9 @@ static int __init lock_prof_init(void) { struct lock_profile **q; - for ( q = &__lock_profile_start; q < &__lock_profile_end; q++ ) + for ( q = &__lock_profile_start; + lock_profile_lt(q, &__lock_profile_end); + q++ ) { (*q)->next = lock_profile_glb_q.elem_q; lock_profile_glb_q.elem_q = *q; diff --git a/xen/common/version.c b/xen/common/version.c index 223cb52..1303fe7 100644 --- a/xen/common/version.c +++ b/xen/common/version.c @@ -86,7 +86,8 @@ int xen_build_id(const void **p, unsigned int *len) #ifdef BUILD_ID /* Defined in linker script. */ -extern const Elf_Note __note_gnu_build_id_start[], __note_gnu_build_id_end[]; +DEFINE_SYMBOL(const Elf_Note, elf_note, __note_gnu_build_id_start, + __note_gnu_build_id_end); int xen_build_id_check(const Elf_Note *n, unsigned int n_sz, const void **p, unsigned int *len) @@ -147,14 +148,14 @@ static int __init xen_build_init(void) int rc; /* --build-id invoked with wrong parameters. */ - if ( __note_gnu_build_id_end <= &n[0] ) + if ( !elf_note_lt(&n[0], __note_gnu_build_id_end) ) return -ENODATA; /* Check for full Note header. */ - if ( &n[1] >= __note_gnu_build_id_end ) + if ( !elf_note_lt(&n[1], __note_gnu_build_id_end) ) return -ENODATA; - sz = (void *)__note_gnu_build_id_end - (void *)n; + sz = (uintptr_t)__note_gnu_build_id_end - (uintptr_t)n; rc = xen_build_id_check(n, sz, &build_id_p, &build_id_len); diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c index aa23918..87ef33a 100644 --- a/xen/common/virtual_region.c +++ b/xen/common/virtual_region.c @@ -119,7 +119,9 @@ void __init setup_virtual_regions(const struct exception_table_entry *start, const struct bug_frame *s; s = bug_frames[i - 1]; - sz = bug_frames[i] - s; + /* bug_frame[i] and s are pointers to different objects. */ + sz = ((uintptr_t)bug_frames[i] - (uintptr_t)s) / + sizeof(struct bug_frame); core.frame[i - 1].n_bugs = sz; core.frame[i - 1].bugs = s; -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel