bulk: Access existing variables initialized to &S->F when available

When a variable is initialized to &struct->field, use it
in place. Rationale: while this makes the code more concise,
this also helps static analyzers.

Mechanical change using the following Coccinelle spatch script:

 @@
 type S, F;
 identifier s, m, v;
 @@
      S *s;
      ...
      F *v = &s->m;
      <+...
 -    &s->m
 +    v
      ...+>

Inspired-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20240129164514.73104-2-philmd@linaro.org>
Acked-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
[thuth: Dropped hunks that need a rebase, and fixed sizeof() in pmu_realize()]
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Philippe Mathieu-Daudé 2024-01-29 17:44:43 +01:00 committed by Thomas Huth
parent 46ff64a826
commit ee1004bba6
15 changed files with 34 additions and 35 deletions

View File

@ -991,7 +991,7 @@ static void ati_vga_realize(PCIDevice *dev, Error **errp)
} }
vga_init(vga, OBJECT(s), pci_address_space(dev), vga_init(vga, OBJECT(s), pci_address_space(dev),
pci_address_space_io(dev), true); pci_address_space_io(dev), true);
vga->con = graphic_console_init(DEVICE(s), 0, s->vga.hw_ops, &s->vga); vga->con = graphic_console_init(DEVICE(s), 0, s->vga.hw_ops, vga);
if (s->cursor_guest_mode) { if (s->cursor_guest_mode) {
vga->cursor_invalidate = ati_cursor_invalidate; vga->cursor_invalidate = ati_cursor_invalidate;
vga->cursor_draw_line = ati_cursor_draw_line; vga->cursor_draw_line = ati_cursor_draw_line;

View File

@ -737,8 +737,7 @@ static void pmu_realize(DeviceState *dev, Error **errp)
timer_mod(s->one_sec_timer, s->one_sec_target); timer_mod(s->one_sec_timer, s->one_sec_target);
if (s->has_adb) { if (s->has_adb) {
qbus_init(&s->adb_bus, sizeof(s->adb_bus), TYPE_ADB_BUS, qbus_init(adb_bus, sizeof(*adb_bus), TYPE_ADB_BUS, dev, "adb.0");
dev, "adb.0");
adb_register_autopoll_callback(adb_bus, pmu_adb_poll, s); adb_register_autopoll_callback(adb_bus, pmu_adb_poll, s);
} }
} }

View File

@ -48,7 +48,7 @@ static void pvpanic_pci_realizefn(PCIDevice *dev, Error **errp)
PVPanicPCIState *s = PVPANIC_PCI_DEVICE(dev); PVPanicPCIState *s = PVPANIC_PCI_DEVICE(dev);
PVPanicState *ps = &s->pvpanic; PVPanicState *ps = &s->pvpanic;
pvpanic_setup_io(&s->pvpanic, DEVICE(s), 2); pvpanic_setup_io(ps, DEVICE(s), 2);
pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &ps->mr); pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &ps->mr);
} }

View File

@ -175,7 +175,7 @@ static void cxl_rp_realize(DeviceState *dev, Error **errp)
cxl_cstate->dvsec_offset = CXL_ROOT_PORT_DVSEC_OFFSET; cxl_cstate->dvsec_offset = CXL_ROOT_PORT_DVSEC_OFFSET;
cxl_cstate->pdev = pci_dev; cxl_cstate->pdev = pci_dev;
build_dvsecs(&crp->cxl_cstate); build_dvsecs(cxl_cstate);
cxl_component_register_block_init(OBJECT(pci_dev), cxl_cstate, cxl_component_register_block_init(OBJECT(pci_dev), cxl_cstate,
TYPE_CXL_ROOT_PORT); TYPE_CXL_ROOT_PORT);

View File

@ -1265,11 +1265,11 @@ static void pnv_chip_power8_realize(DeviceState *dev, Error **errp)
} }
/* Processor Service Interface (PSI) Host Bridge */ /* Processor Service Interface (PSI) Host Bridge */
object_property_set_int(OBJECT(&chip8->psi), "bar", PNV_PSIHB_BASE(chip), object_property_set_int(OBJECT(psi8), "bar", PNV_PSIHB_BASE(chip),
&error_fatal); &error_fatal);
object_property_set_link(OBJECT(&chip8->psi), ICS_PROP_XICS, object_property_set_link(OBJECT(psi8), ICS_PROP_XICS,
OBJECT(chip8->xics), &error_abort); OBJECT(chip8->xics), &error_abort);
if (!qdev_realize(DEVICE(&chip8->psi), NULL, errp)) { if (!qdev_realize(DEVICE(psi8), NULL, errp)) {
return; return;
} }
pnv_xscom_add_subregion(chip, PNV_XSCOM_PSIHB_BASE, pnv_xscom_add_subregion(chip, PNV_XSCOM_PSIHB_BASE,
@ -1300,7 +1300,7 @@ static void pnv_chip_power8_realize(DeviceState *dev, Error **errp)
} }
pnv_xscom_add_subregion(chip, PNV_XSCOM_OCC_BASE, &chip8->occ.xscom_regs); pnv_xscom_add_subregion(chip, PNV_XSCOM_OCC_BASE, &chip8->occ.xscom_regs);
qdev_connect_gpio_out(DEVICE(&chip8->occ), 0, qdev_connect_gpio_out(DEVICE(&chip8->occ), 0,
qdev_get_gpio_in(DEVICE(&chip8->psi), PSIHB_IRQ_OCC)); qdev_get_gpio_in(DEVICE(psi8), PSIHB_IRQ_OCC));
/* OCC SRAM model */ /* OCC SRAM model */
memory_region_add_subregion(get_system_memory(), PNV_OCC_SENSOR_BASE(chip), memory_region_add_subregion(get_system_memory(), PNV_OCC_SENSOR_BASE(chip),
@ -1553,12 +1553,12 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp)
&chip9->xive.xscom_regs); &chip9->xive.xscom_regs);
/* Processor Service Interface (PSI) Host Bridge */ /* Processor Service Interface (PSI) Host Bridge */
object_property_set_int(OBJECT(&chip9->psi), "bar", PNV9_PSIHB_BASE(chip), object_property_set_int(OBJECT(psi9), "bar", PNV9_PSIHB_BASE(chip),
&error_fatal); &error_fatal);
/* This is the only device with 4k ESB pages */ /* This is the only device with 4k ESB pages */
object_property_set_int(OBJECT(&chip9->psi), "shift", XIVE_ESB_4K, object_property_set_int(OBJECT(psi9), "shift", XIVE_ESB_4K,
&error_fatal); &error_fatal);
if (!qdev_realize(DEVICE(&chip9->psi), NULL, errp)) { if (!qdev_realize(DEVICE(psi9), NULL, errp)) {
return; return;
} }
pnv_xscom_add_subregion(chip, PNV9_XSCOM_PSIHB_BASE, pnv_xscom_add_subregion(chip, PNV9_XSCOM_PSIHB_BASE,
@ -1594,7 +1594,7 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp)
} }
pnv_xscom_add_subregion(chip, PNV9_XSCOM_OCC_BASE, &chip9->occ.xscom_regs); pnv_xscom_add_subregion(chip, PNV9_XSCOM_OCC_BASE, &chip9->occ.xscom_regs);
qdev_connect_gpio_out(DEVICE(&chip9->occ), 0, qdev_get_gpio_in( qdev_connect_gpio_out(DEVICE(&chip9->occ), 0, qdev_get_gpio_in(
DEVICE(&chip9->psi), PSIHB9_IRQ_OCC)); DEVICE(psi9), PSIHB9_IRQ_OCC));
/* OCC SRAM model */ /* OCC SRAM model */
memory_region_add_subregion(get_system_memory(), PNV9_OCC_SENSOR_BASE(chip), memory_region_add_subregion(get_system_memory(), PNV9_OCC_SENSOR_BASE(chip),
@ -1609,7 +1609,7 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp)
pnv_xscom_add_subregion(chip, PNV9_XSCOM_SBE_MBOX_BASE, pnv_xscom_add_subregion(chip, PNV9_XSCOM_SBE_MBOX_BASE,
&chip9->sbe.xscom_mbox_regs); &chip9->sbe.xscom_mbox_regs);
qdev_connect_gpio_out(DEVICE(&chip9->sbe), 0, qdev_get_gpio_in( qdev_connect_gpio_out(DEVICE(&chip9->sbe), 0, qdev_get_gpio_in(
DEVICE(&chip9->psi), PSIHB9_IRQ_PSU)); DEVICE(psi9), PSIHB9_IRQ_PSU));
/* HOMER */ /* HOMER */
object_property_set_link(OBJECT(&chip9->homer), "chip", OBJECT(chip), object_property_set_link(OBJECT(&chip9->homer), "chip", OBJECT(chip),
@ -1650,7 +1650,7 @@ static void pnv_chip_power9_realize(DeviceState *dev, Error **errp)
PNV9_XSCOM_I2CM_SIZE, PNV9_XSCOM_I2CM_SIZE,
&chip9->i2c[i].xscom_regs); &chip9->i2c[i].xscom_regs);
qdev_connect_gpio_out(DEVICE(&chip9->i2c[i]), 0, qdev_connect_gpio_out(DEVICE(&chip9->i2c[i]), 0,
qdev_get_gpio_in(DEVICE(&chip9->psi), qdev_get_gpio_in(DEVICE(psi9),
PSIHB9_IRQ_SBE_I2C)); PSIHB9_IRQ_SBE_I2C));
} }
} }

View File

@ -56,9 +56,9 @@ static int vu_scmi_start(VirtIODevice *vdev)
goto err_host_notifiers; goto err_host_notifiers;
} }
vhost_ack_features(&scmi->vhost_dev, feature_bits, vdev->guest_features); vhost_ack_features(vhost_dev, feature_bits, vdev->guest_features);
ret = vhost_dev_start(&scmi->vhost_dev, vdev, true); ret = vhost_dev_start(vhost_dev, vdev, true);
if (ret < 0) { if (ret < 0) {
error_report("Error starting vhost-user-scmi: %d", ret); error_report("Error starting vhost-user-scmi: %d", ret);
goto err_guest_notifiers; goto err_guest_notifiers;
@ -71,7 +71,7 @@ static int vu_scmi_start(VirtIODevice *vdev)
* enabling/disabling irqfd. * enabling/disabling irqfd.
*/ */
for (i = 0; i < scmi->vhost_dev.nvqs; i++) { for (i = 0; i < scmi->vhost_dev.nvqs; i++) {
vhost_virtqueue_mask(&scmi->vhost_dev, vdev, i, false); vhost_virtqueue_mask(vhost_dev, vdev, i, false);
} }
return 0; return 0;

View File

@ -1929,7 +1929,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; bool modern_pio = proxy->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY;
uint8_t *config; uint8_t *config;
uint32_t size; uint32_t size;
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); VirtIODevice *vdev = virtio_bus_get_device(bus);
/* /*
* Virtio capabilities present without * Virtio capabilities present without

View File

@ -711,7 +711,7 @@ static void xen_pt_destroy(PCIDevice *d) {
uint8_t intx; uint8_t intx;
int rc; int rc;
if (machine_irq && !xen_host_pci_device_closed(&s->real_device)) { if (machine_irq && !xen_host_pci_device_closed(host_dev)) {
intx = xen_pt_pci_intx(s); intx = xen_pt_pci_intx(s);
rc = xc_domain_unbind_pt_irq(xen_xc, xen_domid, machine_irq, rc = xc_domain_unbind_pt_irq(xen_xc, xen_domid, machine_irq,
PT_IRQ_TYPE_PCI, PT_IRQ_TYPE_PCI,
@ -760,8 +760,8 @@ static void xen_pt_destroy(PCIDevice *d) {
memory_listener_unregister(&s->io_listener); memory_listener_unregister(&s->io_listener);
s->listener_set = false; s->listener_set = false;
} }
if (!xen_host_pci_device_closed(&s->real_device)) { if (!xen_host_pci_device_closed(host_dev)) {
xen_host_pci_device_put(&s->real_device); xen_host_pci_device_put(host_dev);
} }
} }
/* init */ /* init */

View File

@ -75,7 +75,7 @@ static int zlib_send_setup(MultiFDSendParams *p, Error **errp)
err_free_zbuff: err_free_zbuff:
g_free(z->zbuff); g_free(z->zbuff);
err_deflate_end: err_deflate_end:
deflateEnd(&z->zs); deflateEnd(zs);
err_free_z: err_free_z:
g_free(z); g_free(z);
error_setg(errp, "multifd %u: %s", p->id, err_msg); error_setg(errp, "multifd %u: %s", p->id, err_msg);

View File

@ -2095,7 +2095,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
* We rely on no XScale CPU having VFP so we can use the same bits in the * We rely on no XScale CPU having VFP so we can use the same bits in the
* TB flags field for VECSTRIDE and XSCALE_CPAR. * TB flags field for VECSTRIDE and XSCALE_CPAR.
*/ */
assert(arm_feature(&cpu->env, ARM_FEATURE_AARCH64) || assert(arm_feature(env, ARM_FEATURE_AARCH64) ||
!cpu_isar_feature(aa32_vfp_simd, cpu) || !cpu_isar_feature(aa32_vfp_simd, cpu) ||
!arm_feature(env, ARM_FEATURE_XSCALE)); !arm_feature(env, ARM_FEATURE_XSCALE));
@ -2145,7 +2145,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
} }
if (cpu->cfgend) { if (cpu->cfgend) {
if (arm_feature(&cpu->env, ARM_FEATURE_V7)) { if (arm_feature(env, ARM_FEATURE_V7)) {
cpu->reset_sctlr |= SCTLR_EE; cpu->reset_sctlr |= SCTLR_EE;
} else { } else {
cpu->reset_sctlr |= SCTLR_B; cpu->reset_sctlr |= SCTLR_B;

View File

@ -1888,7 +1888,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
cpu->psci_version = QEMU_PSCI_VERSION_0_2; cpu->psci_version = QEMU_PSCI_VERSION_0_2;
cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2; cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
} }
if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { if (!arm_feature(env, ARM_FEATURE_AARCH64)) {
cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_EL1_32BIT; cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_EL1_32BIT;
} }
if (!kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PMU_V3)) { if (!kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PMU_V3)) {

View File

@ -773,7 +773,7 @@ static int cpu_pre_load(void *opaque)
env->irq_line_state = UINT32_MAX; env->irq_line_state = UINT32_MAX;
if (!kvm_enabled()) { if (!kvm_enabled()) {
pmu_op_start(&cpu->env); pmu_op_start(env);
} }
return 0; return 0;
@ -871,11 +871,11 @@ static int cpu_post_load(void *opaque, int version_id)
} }
if (!kvm_enabled()) { if (!kvm_enabled()) {
pmu_op_finish(&cpu->env); pmu_op_finish(env);
} }
if (tcg_enabled()) { if (tcg_enabled()) {
arm_rebuild_hflags(&cpu->env); arm_rebuild_hflags(env);
} }
return 0; return 0;

View File

@ -408,7 +408,7 @@ bool hvf_inject_interrupts(CPUState *cs)
if (!(env->hflags & HF_INHIBIT_IRQ_MASK) && if (!(env->hflags & HF_INHIBIT_IRQ_MASK) &&
(cs->interrupt_request & CPU_INTERRUPT_HARD) && (cs->interrupt_request & CPU_INTERRUPT_HARD) &&
(env->eflags & IF_MASK) && !(info & VMCS_INTR_VALID)) { (env->eflags & IF_MASK) && !(info & VMCS_INTR_VALID)) {
int line = cpu_get_pic_interrupt(&x86cpu->env); int line = cpu_get_pic_interrupt(env);
cs->interrupt_request &= ~CPU_INTERRUPT_HARD; cs->interrupt_request &= ~CPU_INTERRUPT_HARD;
if (line >= 0) { if (line >= 0) {
wvmcs(cs->accel->fd, VMCS_ENTRY_INTR_INFO, line | wvmcs(cs->accel->fd, VMCS_ENTRY_INTR_INFO, line |

View File

@ -984,7 +984,7 @@ bool m68k_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
access_type |= ACCESS_SUPER; access_type |= ACCESS_SUPER;
} }
ret = get_physical_address(&cpu->env, &physical, &prot, ret = get_physical_address(env, &physical, &prot,
address, access_type, &page_size); address, access_type, &page_size);
if (likely(ret == 0)) { if (likely(ret == 0)) {
tlb_set_page(cs, address & TARGET_PAGE_MASK, tlb_set_page(cs, address & TARGET_PAGE_MASK,

View File

@ -635,8 +635,8 @@ static int kvm_put_fp(CPUState *cs)
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
uint64_t vsr[2]; uint64_t vsr[2];
uint64_t *fpr = cpu_fpr_ptr(&cpu->env, i); uint64_t *fpr = cpu_fpr_ptr(env, i);
uint64_t *vsrl = cpu_vsrl_ptr(&cpu->env, i); uint64_t *vsrl = cpu_vsrl_ptr(env, i);
#if HOST_BIG_ENDIAN #if HOST_BIG_ENDIAN
vsr[0] = float64_val(*fpr); vsr[0] = float64_val(*fpr);
@ -704,8 +704,8 @@ static int kvm_get_fp(CPUState *cs)
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
uint64_t vsr[2]; uint64_t vsr[2];
uint64_t *fpr = cpu_fpr_ptr(&cpu->env, i); uint64_t *fpr = cpu_fpr_ptr(env, i);
uint64_t *vsrl = cpu_vsrl_ptr(&cpu->env, i); uint64_t *vsrl = cpu_vsrl_ptr(env, i);
reg.addr = (uintptr_t) &vsr; reg.addr = (uintptr_t) &vsr;
reg.id = vsx ? KVM_REG_PPC_VSR(i) : KVM_REG_PPC_FPR(i); reg.id = vsx ? KVM_REG_PPC_VSR(i) : KVM_REG_PPC_FPR(i);