[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v9 5/5] xen/common: use SYMBOLS_SUBTRACT and SYMBOLS_COMPARE as required
Use SYMBOLS_SUBTRACT and SYMBOLS_COMPARE in cases of comparisons and subtractions of: _start, _end, _stext, _etext, _srodata, _erodata, _sinittext, _einittext, __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, as by the C standard [1]. 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. [1] 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 <stefanos@xxxxxxxxxx> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx> CC: JBeulich@xxxxxxxx CC: andrew.cooper3@xxxxxxxxxx --- Changes in v9: - use SYMBOLS_SUBTRACT and SYMBOLS_COMPARE --- xen/common/kernel.c | 8 ++++++-- xen/common/lib.c | 5 ++++- xen/common/schedule.c | 6 ++++-- xen/common/spinlock.c | 4 +++- xen/common/version.c | 6 +++--- xen/common/virtual_region.c | 3 ++- xen/include/xen/kernel.h | 28 ++++++++++++++++------------ 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/xen/common/kernel.c b/xen/common/kernel.c index 5766a0f..b1122a1 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -312,14 +312,18 @@ extern const initcall_t __initcall_start[], __presmp_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; + SYMBOLS_COMPARE(call, __presmp_initcall_end) < 0; + 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; + SYMBOLS_COMPARE(call, __initcall_end) < 0; + call++ ) (*call)(); } diff --git a/xen/common/lib.c b/xen/common/lib.c index 8ebec81..ea32367 100644 --- a/xen/common/lib.c +++ b/xen/common/lib.c @@ -497,7 +497,10 @@ extern const ctor_func_t __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; + SYMBOLS_COMPARE(f, __ctors_end) < 0; + ++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..0181275 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) +extern const struct scheduler *__start_schedulers_array[], + *__end_schedulers_array[]; +#define NUM_SCHEDULERS (SYMBOLS_SUBTRACT(__end_schedulers_array, \ + __start_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..1fe292f 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -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; + SYMBOLS_COMPARE(q, &__lock_profile_end) < 0; + 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..cdf2e56 100644 --- a/xen/common/version.c +++ b/xen/common/version.c @@ -147,14 +147,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 ( SYMBOLS_COMPARE(__note_gnu_build_id_end, &n[0]) <= 0 ) return -ENODATA; /* Check for full Note header. */ - if ( &n[1] >= __note_gnu_build_id_end ) + if ( SYMBOLS_COMPARE(&n[1], __note_gnu_build_id_end) >= 0 ) return -ENODATA; - sz = (void *)__note_gnu_build_id_end - (void *)n; + sz = SYMBOLS_SUBTRACT(__note_gnu_build_id_end, (void *)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..b3afcb9 100644 --- a/xen/common/virtual_region.c +++ b/xen/common/virtual_region.c @@ -119,7 +119,8 @@ 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 = SYMBOLS_SUBTRACT(bug_frames[i], s); core.frame[i - 1].n_bugs = sz; core.frame[i - 1].bugs = s; diff --git a/xen/include/xen/kernel.h b/xen/include/xen/kernel.h index 548b64d..826fc32 100644 --- a/xen/include/xen/kernel.h +++ b/xen/include/xen/kernel.h @@ -66,27 +66,31 @@ }) extern char _start[], _end[], start[]; -#define is_kernel(p) ({ \ - char *__p = (char *)(unsigned long)(p); \ - (__p >= _start) && (__p < _end); \ +#define is_kernel(p) ({ \ + const char *p__ = (const char *)(unsigned long)(p); \ + (SYMBOLS_COMPARE(p__, _start) >= 0 && \ + SYMBOLS_COMPARE(p__, _end) < 0); \ }) extern char _stext[], _etext[]; -#define is_kernel_text(p) ({ \ - char *__p = (char *)(unsigned long)(p); \ - (__p >= _stext) && (__p < _etext); \ +#define is_kernel_text(p) ({ \ + const char *p__ = (const char *)(unsigned long)(p); \ + (SYMBOLS_COMPARE(p__, _stext) >= 0 && \ + SYMBOLS_COMPARE(p__, _etext) < 0); \ }) extern const char _srodata[], _erodata[]; -#define is_kernel_rodata(p) ({ \ - const char *__p = (const char *)(unsigned long)(p); \ - (__p >= _srodata) && (__p < _erodata); \ +#define is_kernel_rodata(p) ({ \ + const char *p__ = (const char *)(unsigned long)(p); \ + (SYMBOLS_COMPARE(p__, _srodata) >= 0 && \ + SYMBOLS_COMPARE(p__, _erodata) < 0); \ }) extern char _sinittext[], _einittext[]; -#define is_kernel_inittext(p) ({ \ - char *__p = (char *)(unsigned long)(p); \ - (__p >= _sinittext) && (__p < _einittext); \ +#define is_kernel_inittext(p) ({ \ + const char *p__ = (const char *)(unsigned long)(p); \ + (SYMBOLS_COMPARE(p__, _sinittext) >= 0 && \ + SYMBOLS_COMPARE(p__, _einittext) < 0); \ }) extern enum system_state { -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |