Use indexing in preference to pointer arithmetic.
Change-Id: Ia90714e95af1e545f626bd5b6c99e40622e37286
diff --git a/src/api.c b/src/api.c
index 947982c..8195ad6 100644
--- a/src/api.c
+++ b/src/api.c
@@ -79,12 +79,12 @@
return HF_VCPU_RUN_RESPONSE(HF_VCPU_RUN_WAIT_FOR_INTERRUPT, 0);
}
- vm = secondary_vm + vm_idx;
+ vm = &secondary_vm[vm_idx];
if (vcpu_idx >= vm->vcpu_count) {
return HF_VCPU_RUN_RESPONSE(HF_VCPU_RUN_WAIT_FOR_INTERRUPT, 0);
}
- vcpu = vm->vcpus + vcpu_idx;
+ vcpu = &vm->vcpus[vcpu_idx];
sl_lock(&vcpu->lock);
if (vcpu->state != vcpu_state_ready) {
@@ -224,7 +224,7 @@
return -1;
}
- to = secondary_vm + vm_idx;
+ to = &secondary_vm[vm_idx];
sl_lock(&to->lock);
if (to->rpc.state != rpc_state_idle || !to->rpc.recv) {
diff --git a/src/cpu.c b/src/cpu.c
index cec490e..185d993 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -10,13 +10,13 @@
#include "hf/vm.h"
/* The stack to be used by the CPUs. */
-alignas(2 * sizeof(size_t)) static char callstacks[STACK_SIZE * MAX_CPUS];
+alignas(2 * sizeof(size_t)) static char callstacks[MAX_CPUS][STACK_SIZE];
/* State of all supported CPUs. The stack of the first one is initialized. */
struct cpu cpus[MAX_CPUS] = {
{
.is_on = 1,
- .stack_bottom = callstacks + STACK_SIZE,
+ .stack_bottom = &callstacks[0][STACK_SIZE],
},
};
@@ -26,10 +26,10 @@
/* Initialize all CPUs. */
for (i = 0; i < MAX_CPUS; i++) {
- struct cpu *c = cpus + i;
+ struct cpu *c = &cpus[i];
cpu_init(c);
c->id = i; /* TODO: Initialize ID based on fdt. */
- c->stack_bottom = callstacks + STACK_SIZE * (i + 1);
+ c->stack_bottom = &callstacks[i][STACK_SIZE];
}
}
@@ -74,7 +74,7 @@
sl_unlock(&c->lock);
if (!prev) {
- struct vcpu *vcpu = primary_vm.vcpus + cpu_index(c);
+ struct vcpu *vcpu = &primary_vm.vcpus[cpu_index(c)];
arch_regs_init(&vcpu->regs, entry, arg);
vcpu_on(vcpu);
}
@@ -101,7 +101,7 @@
for (i = 0; i < MAX_CPUS; i++) {
if (cpus[i].id == id) {
- return cpus + i;
+ return &cpus[i];
}
}
diff --git a/src/dlog.c b/src/dlog.c
index 7f4e935..7128a7b 100644
--- a/src/dlog.c
+++ b/src/dlog.c
@@ -82,7 +82,7 @@
static const char *digits_upper = "0123456789ABCDEFX";
const char *d = (flags & FLAG_UPPER) ? digits_upper : digits_lower;
char buf[51];
- char *ptr = buf + sizeof(buf) - 1;
+ char *ptr = &buf[sizeof(buf) - 1];
char *num;
*ptr = '\0';
do {
diff --git a/src/fdt.c b/src/fdt.c
index 6383164..599fca4 100644
--- a/src/fdt.c
+++ b/src/fdt.c
@@ -50,7 +50,7 @@
static void fdt_tokenizer_align(struct fdt_tokenizer *t)
{
- t->cur = (char *)(((size_t)t->cur + 3) & ~3);
+ t->cur = (char *)(((uintptr_t)t->cur + 3) & ~3);
}
static bool fdt_tokenizer_uint32(struct fdt_tokenizer *t, uint32_t *res)
diff --git a/src/load.c b/src/load.c
index cd81237..6ed2d1b 100644
--- a/src/load.c
+++ b/src/load.c
@@ -206,7 +206,7 @@
continue;
}
- if (!vm_init(secondary_vm + count, count + 1, cpu)) {
+ if (!vm_init(&secondary_vm[count], count + 1, cpu)) {
dlog("Unable to initialise vm %u\n", count);
continue;
}
@@ -239,7 +239,7 @@
dlog("Loaded VM%u with %u vcpus, entry at 0x%x\n", count, cpu,
pa_addr(*mem_end));
- vm_start_vcpu(secondary_vm + count, 0, secondary_entry, 0);
+ vm_start_vcpu(&secondary_vm[count], 0, secondary_entry, 0);
}
secondary_vm_count = count;
diff --git a/src/main.c b/src/main.c
index e6ba2f1..7326cb0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -128,5 +128,5 @@
vm_set_current(&primary_vm);
- return primary_vm.vcpus + cpu_index(c);
+ return &primary_vm.vcpus[cpu_index(c)];
}
diff --git a/src/mm.c b/src/mm.c
index 9c708cf..51331be 100644
--- a/src/mm.c
+++ b/src/mm.c
@@ -162,7 +162,7 @@
static bool mm_map_level(ptable_addr_t begin, ptable_addr_t end, paddr_t pa,
uint64_t attrs, pte_t *table, int level, int flags)
{
- pte_t *pte = table + mm_index(begin, level);
+ pte_t *pte = &table[mm_index(begin, level)];
ptable_addr_t level_end = mm_level_end(begin, level);
size_t entry_size = mm_entry_size(level);
bool commit = flags & MAP_FLAG_COMMIT;
@@ -308,7 +308,7 @@
addr = pa_addr(pa);
for (i = arch_mm_max_level(mode); i > 0; i--) {
- table = mm_populate_table_pte(table + mm_index(addr, i), i,
+ table = mm_populate_table_pte(&table[mm_index(addr, i)], i,
sync);
if (!table) {
return false;
diff --git a/src/vm.c b/src/vm.c
index d03aba8..d2beeb0 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -16,7 +16,7 @@
/* Do basic initialization of vcpus. */
for (i = 0; i < vcpu_count; i++) {
- vcpu_init(vm->vcpus + i, vm);
+ vcpu_init(&vm->vcpus[i], vm);
}
return mm_ptable_init(&vm->ptable, 0);
@@ -25,7 +25,7 @@
/* TODO: Shall we use index or id here? */
void vm_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry, size_t arg)
{
- struct vcpu *vcpu = vm->vcpus + index;
+ struct vcpu *vcpu = &vm->vcpus[index];
if (index < vm->vcpu_count) {
arch_regs_init(&vcpu->regs, entry, arg);
vcpu_on(vcpu);