]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
xen: Fix warning by adding KERNBASE to modlist_paddr before casting
authorDimitry Andric <dim@FreeBSD.org>
Sun, 29 Aug 2021 14:02:31 +0000 (16:02 +0200)
committerDimitry Andric <dim@FreeBSD.org>
Thu, 2 Sep 2021 23:30:34 +0000 (01:30 +0200)
commitcc110974c4edae799e2682afcd32cbfc094e6237
treeab229c003eb78f415c3223b3f72cbef65e49a86f
parentf4fed768bba45a406f73ed1491d7e52fd1a8711d
xen: Fix warning by adding KERNBASE to modlist_paddr before casting

Clang 13 produces the following warning for hammer_time_xen():

sys/x86/xen/pv.c:183:19: error: the pointer incremented by -2147483648 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements) [-Werror,-Warray-bounds]
                    (vm_paddr_t)start_info->modlist_paddr + KERNBASE;
                                ^                               ~~~~~~~~
sys/xen/interface/arch-x86/hvm/start_info.h:131:5: note: array 'modlist_paddr' declared here
    uint64_t modlist_paddr;         /* Physical address of an array of           */
    ^

This is because the expression first casts start_info->modlist_paddr to
struct hvm_modlist_entry * (via vmpaddr_t), and *then* adds KERNBASE,
which is then interpreted as KERNBASE * sizeof(struct
hvm_modlist_entry).

Instead, parenthesize the addition to get the intended result, and cast
it to struct hvm_modlist_entry * afterwards. Also remove the cast to
vmpaddr_t since it is not necessary.

Reviewed by: royger
Differential Revision: https://reviews.freebsd.org/D31711

(cherry picked from commit 8e3c56d6b676a175e974bad4c20797fb35017db8)
sys/x86/xen/pv.c