Mailing List Archive

[PATCH] x86/PVH: Use unsigned int for dom0 e820 index
Switch to unsigned int for the dom0 e820 index. This eliminates the
potential for array underflows, and the compiler might be able to
generate better code.

Requested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
---
xen/arch/x86/hvm/dom0_build.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c
index d158f4d241..ac71d43a6b 100644
--- a/xen/arch/x86/hvm/dom0_build.c
+++ b/xen/arch/x86/hvm/dom0_build.c
@@ -569,7 +569,7 @@ static paddr_t __init find_kernel_memory(
{
paddr_t kernel_size = elf->dest_size;
unsigned int align;
- int i;
+ unsigned int i;

if ( parms->phys_align != UNSET_ADDR32 )
align = parms->phys_align;
@@ -579,7 +579,7 @@ static paddr_t __init find_kernel_memory(
align = MB(2);

/* Search backwards to find the highest address. */
- for ( i = d->arch.nr_e820 - 1; i >= 0 ; i-- )
+ for ( i = d->arch.nr_e820; i--; )
{
paddr_t start = d->arch.e820[i].addr;
paddr_t end = start + d->arch.e820[i].size;
--
2.44.0
Re: [PATCH] x86/PVH: Use unsigned int for dom0 e820 index [ In reply to ]
On 18.04.2024 18:07, Jason Andryuk wrote:
> Switch to unsigned int for the dom0 e820 index. This eliminates the
> potential for array underflows, and the compiler might be able to
> generate better code.
>
> Requested-by: Jan Beulich <jbeulich@suse.com>
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>

Acked-by: Jan Beulich <jbeulich@suse.com>