From 26fb02b5ae59b48b51ca788be91510d8df48ab0a Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Tue, 5 Mar 2019 14:29:51 -0800 Subject: [PATCH] xen: explicit casts when DECLARE_BOUNDS cannot be used Sometimes the static inline functions provided by DECLARE_BOUNDS cannot be used. This patch uses explicit casts to uintptr_t in those cases. M3CM: Rule-18.2: Subtraction between pointers shall only be applied to pointers that address elements of the same array 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 CC: JBeulich@suse.com CC: andrew.cooper3@citrix.com --- xen/arch/x86/setup.c | 3 ++- xen/common/virtual_region.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 2ac7f62546..cb45b68f3f 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -976,7 +976,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) * respective reserve_e820_ram() invocation below. */ mod[mbi->mods_count].mod_start = virt_to_mfn(_stext); - mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext; + mod[mbi->mods_count].mod_end = (uintptr_t)__2M_rwdata_end - + (uintptr_t) _stext; } modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end); diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c index aa23918bce..87ef33a832 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; -- 2.39.5