Skip to content

Commit

Permalink
xen: Don't pass MemoryListener around by value
Browse files Browse the repository at this point in the history
Coverity points out (CID 1513106, 1513107) that MemoryListener is a
192 byte struct which we are passing around by value.  Switch to
passing a const pointer into xen_register_ioreq() and then to
xen_do_ioreq_register().  We can also make the file-scope
MemoryListener variables const, since nothing changes them.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230718101057.1110979-1-peter.maydell@linaro.org>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
  • Loading branch information
pm215 authored and anthonyper-ctx committed Aug 1, 2023
1 parent f4f7136 commit bcb40db
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions hw/arm/xen_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#define TYPE_XEN_ARM MACHINE_TYPE_NAME("xenpvh")
OBJECT_DECLARE_SIMPLE_TYPE(XenArmState, XEN_ARM)

static MemoryListener xen_memory_listener = {
static const MemoryListener xen_memory_listener = {
.region_add = xen_region_add,
.region_del = xen_region_del,
.log_start = NULL,
Expand Down Expand Up @@ -108,7 +108,7 @@ static void xen_arm_init(MachineState *machine)

xam->state = g_new0(XenIOState, 1);

xen_register_ioreq(xam->state, machine->smp.cpus, xen_memory_listener);
xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener);

#ifdef CONFIG_TPM
if (xam->cfg.tpm_base_addr) {
Expand Down
4 changes: 2 additions & 2 deletions hw/i386/xen/xen-hvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ static void xen_log_global_stop(MemoryListener *listener)
xen_in_migration = false;
}

static MemoryListener xen_memory_listener = {
static const MemoryListener xen_memory_listener = {
.name = "xen-memory",
.region_add = xen_region_add,
.region_del = xen_region_del,
Expand Down Expand Up @@ -582,7 +582,7 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegion **ram_memory)

state = g_new0(XenIOState, 1);

xen_register_ioreq(state, max_cpus, xen_memory_listener);
xen_register_ioreq(state, max_cpus, &xen_memory_listener);

QLIST_INIT(&xen_physmap);
xen_read_physmap(state);
Expand Down
8 changes: 4 additions & 4 deletions hw/xen/xen-hvm-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ void xen_shutdown_fatal_error(const char *fmt, ...)
}

static void xen_do_ioreq_register(XenIOState *state,
unsigned int max_cpus,
MemoryListener xen_memory_listener)
unsigned int max_cpus,
const MemoryListener *xen_memory_listener)
{
int i, rc;

Expand Down Expand Up @@ -824,7 +824,7 @@ static void xen_do_ioreq_register(XenIOState *state,

qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state);

state->memory_listener = xen_memory_listener;
state->memory_listener = *xen_memory_listener;
memory_listener_register(&state->memory_listener, &address_space_memory);

state->io_listener = xen_io_listener;
Expand All @@ -842,7 +842,7 @@ static void xen_do_ioreq_register(XenIOState *state,
}

void xen_register_ioreq(XenIOState *state, unsigned int max_cpus,
MemoryListener xen_memory_listener)
const MemoryListener *xen_memory_listener)
{
int rc;

Expand Down
2 changes: 1 addition & 1 deletion include/hw/xen/xen-hvm-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void xen_device_unrealize(DeviceListener *listener, DeviceState *dev);

void xen_hvm_change_state_handler(void *opaque, bool running, RunState rstate);
void xen_register_ioreq(XenIOState *state, unsigned int max_cpus,
MemoryListener xen_memory_listener);
const MemoryListener *xen_memory_listener);

void cpu_ioreq_pio(ioreq_t *req);
#endif /* HW_XEN_HVM_COMMON_H */

0 comments on commit bcb40db

Please sign in to comment.