diff --git a/block/dmg.c b/block/dmg.c index 900ae5a67898..6c0711f5636a 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -111,7 +111,7 @@ static void update_max_chunk_size(BDRVDMGState *s, uint32_t chunk, uncompressed_sectors = s->sectorcounts[chunk]; break; case 1: /* copy */ - uncompressed_sectors = (s->lengths[chunk] + 511) / 512; + uncompressed_sectors = DIV_ROUND_UP(s->lengths[chunk], 512); break; case 2: /* zero */ /* as the all-zeroes block may be large, it is treated specially: the diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8538533102bb..0d4824993cc1 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -61,7 +61,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, new_l1_size = 1; } while (min_size > new_l1_size) { - new_l1_size = (new_l1_size * 3 + 1) / 2; + new_l1_size = DIV_ROUND_UP(new_l1_size * 3, 2); } } diff --git a/block/vhdx-log.c b/block/vhdx-log.c index 14b724ef7bc4..0ac4863b25d4 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -902,7 +902,7 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, } sector_offset = offset % VHDX_LOG_SECTOR_SIZE; - file_offset = (offset / VHDX_LOG_SECTOR_SIZE) * VHDX_LOG_SECTOR_SIZE; + file_offset = QEMU_ALIGN_DOWN(offset, VHDX_LOG_SECTOR_SIZE); aligned_length = length; diff --git a/block/vpc.c b/block/vpc.c index 82911ebead1e..1576d7b59577 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -783,7 +783,7 @@ static int calculate_geometry(int64_t total_sectors, uint16_t* cyls, } else { *secs_per_cyl = 17; cyls_times_heads = total_sectors / *secs_per_cyl; - *heads = (cyls_times_heads + 1023) / 1024; + *heads = DIV_ROUND_UP(cyls_times_heads, 1024); if (*heads < 4) { *heads = 4; @@ -836,7 +836,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf, offset = 3 * 512; memset(buf, 0xFF, 512); - for (i = 0; i < (num_bat_entries * 4 + 511) / 512; i++) { + for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) { ret = blk_pwrite(blk, offset, buf, 512, 0); if (ret < 0) { goto fail; diff --git a/block/vvfat.c b/block/vvfat.c index a9e207f7f0a6..c54fa94651c3 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -449,7 +449,7 @@ static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename) return NULL; } - number_of_entries = (length * 2 + 25) / 26; + number_of_entries = DIV_ROUND_UP(length * 2, 26); for(i=0;idirectory)); @@ -2554,7 +2554,7 @@ static int commit_one_file(BDRVVVFATState* s, (size > offset && c >=2 && !fat_eof(s, c))); ret = vvfat_read(s->bs, cluster2sector(s, c), - (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200); + (uint8_t*)cluster, DIV_ROUND_UP(rest_size, 0x200)); if (ret < 0) { qemu_close(fd); diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c index f643b122bb10..0206f7399bd1 100644 --- a/hw/audio/pcspk.c +++ b/hw/audio/pcspk.c @@ -69,7 +69,7 @@ static inline void generate_samples(PCSpkState *s) const uint32_t n = ((uint64_t)PIT_FREQ << 32) / m; /* multiple of wavelength for gapless looping */ - s->samples = (PCSPK_BUF_LEN * PIT_FREQ / m * m / (PIT_FREQ >> 1) + 1) >> 1; + s->samples = (QEMU_ALIGN_DOWN(PCSPK_BUF_LEN * PIT_FREQ, m) / (PIT_FREQ >> 1) + 1) >> 1; for (i = 0; i < s->samples; ++i) s->sample_buf[i] = (64 & (n * i >> 25)) - 32; } else { diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index f5bc173844e4..17a1bb008a63 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -663,7 +663,7 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f) /* The ports map */ max_nr_ports = s->serial.max_virtserial_ports; - for (i = 0; i < (max_nr_ports + 31) / 32; i++) { + for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) { qemu_put_be32s(f, &s->ports_map[i]); } @@ -798,7 +798,7 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f, qemu_get_be32s(f, &tmp); max_nr_ports = s->serial.max_virtserial_ports; - for (i = 0; i < (max_nr_ports + 31) / 32; i++) { + for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) { qemu_get_be32s(f, &ports_map); if (ports_map != s->ports_map[i]) { @@ -863,7 +863,7 @@ static uint32_t find_free_port_id(VirtIOSerial *vser) unsigned int i, max_nr_ports; max_nr_ports = vser->serial.max_virtserial_ports; - for (i = 0; i < (max_nr_ports + 31) / 32; i++) { + for (i = 0; i < DIV_ROUND_UP(max_nr_ports, 32); i++) { uint32_t map, zeroes; map = vser->ports_map[i]; @@ -1075,7 +1075,7 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp) vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output); } - vser->ports_map = g_malloc0(((vser->serial.max_virtserial_ports + 31) / 32) + vser->ports_map = g_malloc0((DIV_ROUND_UP(vser->serial.max_virtserial_ports, 32)) * sizeof(vser->ports_map[0])); /* * Reserve location 0 for a console port for backward compat diff --git a/hw/display/vga.c b/hw/display/vga.c index 63421f9ee856..3433102ef3bb 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -1621,7 +1621,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update) s->line_compare, sr(s, VGA_SEQ_CLOCK_MODE)); #endif addr1 = (s->start_addr * 4); - bwidth = (width * bits + 7) / 8; + bwidth = DIV_ROUND_UP(width * bits, 8); y_start = -1; d = surface_data(surface); linesize = surface_stride(surface); diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 6aae147324e6..f0761cf18bc6 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -408,7 +408,7 @@ static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *g, } format = pixman_image_get_format(res->image); - bpp = (PIXMAN_FORMAT_BPP(format) + 7) / 8; + bpp = DIV_ROUND_UP(PIXMAN_FORMAT_BPP(format), 8); stride = pixman_image_get_stride(res->image); if (t2d.offset || t2d.r.x || t2d.r.y || @@ -570,7 +570,7 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, scanout = &g->scanout[ss.scanout_id]; format = pixman_image_get_format(res->image); - bpp = (PIXMAN_FORMAT_BPP(format) + 7) / 8; + bpp = DIV_ROUND_UP(PIXMAN_FORMAT_BPP(format), 8); offset = (ss.r.x * bpp) + ss.r.y * pixman_image_get_stride(res->image); if (!scanout->ds || surface_data(scanout->ds) != ((uint8_t *)pixman_image_get_data(res->image) + offset) || diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c index f13e23139ba3..6001f4caa29f 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -352,8 +352,7 @@ int load_multiboot(FWCfgState *fw_cfg, mb_debug(" mb_mods_count = %d\n", mbs.mb_mods_count); /* save bootinfo off the stack */ - mb_bootinfo_data = g_malloc(sizeof(bootinfo)); - memcpy(mb_bootinfo_data, bootinfo, sizeof(bootinfo)); + mb_bootinfo_data = g_memdup(bootinfo, sizeof(bootinfo)); /* Pass variables to option rom */ fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, mh_entry_addr); diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index 5a4774aab40e..a7b9f77519ba 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -1904,8 +1904,7 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp) qemu_register_reset(nic_reset, s); - s->vmstate = g_malloc(sizeof(vmstate_eepro100)); - memcpy(s->vmstate, &vmstate_eepro100, sizeof(vmstate_eepro100)); + s->vmstate = g_memdup(&vmstate_eepro100, sizeof(vmstate_eepro100)); s->vmstate->name = qemu_get_queue(s->nic)->model; vmstate_register(&pci_dev->qdev, -1, s->vmstate, s); } diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 072a04e318d2..894e131c00f9 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -140,7 +140,7 @@ static void i440fx_update_memory_mappings(PCII440FXState *d) memory_region_transaction_begin(); for (i = 0; i < 13; i++) { pam_update(&d->pam_regions[i], i, - pd->config[I440FX_PAM + ((i + 1) / 2)]); + pd->config[I440FX_PAM + (DIV_ROUND_UP(i, 2))]); } memory_region_set_enabled(&d->smram_region, !(pd->config[I440FX_SMRAM] & SMRAM_D_OPEN)); diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 0e472f2ed4c9..1ff648e80c77 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -315,7 +315,7 @@ static void mch_update_pam(MCHPCIState *mch) memory_region_transaction_begin(); for (i = 0; i < 13; i++) { pam_update(&mch->pam_regions[i], i, - pd->config[MCH_HOST_BRIDGE_PAM0 + ((i + 1) / 2)]); + pd->config[MCH_HOST_BRIDGE_PAM0 + (DIV_ROUND_UP(i, 2))]); } memory_region_transaction_commit(); } diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 5078d3dd1927..c944c02135b8 100644 --- a/hw/pci/msix.c +++ b/hw/pci/msix.c @@ -438,7 +438,7 @@ void msix_save(PCIDevice *dev, QEMUFile *f) } qemu_put_buffer(f, dev->msix_table, n * PCI_MSIX_ENTRY_SIZE); - qemu_put_buffer(f, dev->msix_pba, (n + 7) / 8); + qemu_put_buffer(f, dev->msix_pba, DIV_ROUND_UP(n, 8)); } /* Should be called after restoring the config space. */ @@ -453,7 +453,7 @@ void msix_load(PCIDevice *dev, QEMUFile *f) msix_clear_all_vectors(dev); qemu_get_buffer(f, dev->msix_table, n * PCI_MSIX_ENTRY_SIZE); - qemu_get_buffer(f, dev->msix_pba, (n + 7) / 8); + qemu_get_buffer(f, dev->msix_pba, DIV_ROUND_UP(n, 8)); msix_update_function_masked(dev); for (vector = 0; vector < n; vector++) { diff --git a/hw/timer/i8254_common.c b/hw/timer/i8254_common.c index 976d5200f1ad..ee064aa8192c 100644 --- a/hw/timer/i8254_common.c +++ b/hw/timer/i8254_common.c @@ -93,7 +93,7 @@ int64_t pit_get_next_transition_time(PITChannelState *s, int64_t current_time) } break; case 2: - base = (d / s->count) * s->count; + base = QEMU_ALIGN_DOWN(d, s->count); if ((d - base) == 0 && d != 0) { next_time = base + s->count; } else { @@ -101,7 +101,7 @@ int64_t pit_get_next_transition_time(PITChannelState *s, int64_t current_time) } break; case 3: - base = (d / s->count) * s->count; + base = QEMU_ALIGN_DOWN(d, s->count); period2 = ((s->count + 1) >> 1); if ((d - base) < period2) { next_time = base + period2; diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index e82a6a6c44b7..752e30c305a2 100644 --- a/hw/usb/dev-hub.c +++ b/hw/usb/dev-hub.c @@ -109,7 +109,7 @@ static const USBDescIface desc_iface_hub = { { .bEndpointAddress = USB_DIR_IN | 0x01, .bmAttributes = USB_ENDPOINT_XFER_INT, - .wMaxPacketSize = 1 + (NUM_PORTS + 7) / 8, + .wMaxPacketSize = 1 + DIV_ROUND_UP(NUM_PORTS, 8), .bInterval = 0xff, }, } @@ -442,14 +442,14 @@ static void usb_hub_handle_control(USBDevice *dev, USBPacket *p, data[2] = NUM_PORTS; /* fill DeviceRemovable bits */ - limit = ((NUM_PORTS + 1 + 7) / 8) + 7; + limit = DIV_ROUND_UP(NUM_PORTS + 1, 8) + 7; for (n = 7; n < limit; n++) { data[n] = 0x00; var_hub_size++; } /* fill PortPwrCtrlMask bits */ - limit = limit + ((NUM_PORTS + 7) / 8); + limit = limit + DIV_ROUND_UP(NUM_PORTS, 8); for (;n < limit; n++) { data[n] = 0xff; var_hub_size++; @@ -477,7 +477,7 @@ static void usb_hub_handle_data(USBDevice *dev, USBPacket *p) unsigned int status; uint8_t buf[4]; int i, n; - n = (NUM_PORTS + 1 + 7) / 8; + n = DIV_ROUND_UP(NUM_PORTS + 1, 8); if (p->iov.size == 1) { /* FreeBSD workaround */ n = 1; } else if (n > p->iov.size) { diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 6eddb099b02f..0049a2c0b393 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -70,7 +70,7 @@ static void vhost_dev_sync_region(struct vhost_dev *dev, uint64_t end = MIN(mlast, rlast); vhost_log_chunk_t *from = log + start / VHOST_LOG_CHUNK; vhost_log_chunk_t *to = log + end / VHOST_LOG_CHUNK + 1; - uint64_t addr = (start / VHOST_LOG_CHUNK) * VHOST_LOG_CHUNK; + uint64_t addr = QEMU_ALIGN_DOWN(start, VHOST_LOG_CHUNK); if (end < start) { return; diff --git a/include/ui/console.h b/include/ui/console.h index 7262bef6d334..8024878baea0 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -328,7 +328,7 @@ static inline int surface_bits_per_pixel(DisplaySurface *s) static inline int surface_bytes_per_pixel(DisplaySurface *s) { int bits = PIXMAN_FORMAT_BPP(s->format); - return (bits + 7) / 8; + return DIV_ROUND_UP(bits, 8); } static inline pixman_format_code_t surface_format(DisplaySurface *s) diff --git a/libdecnumber/decNumber.c b/libdecnumber/decNumber.c index c9e7807f87e7..8c197023f456 100644 --- a/libdecnumber/decNumber.c +++ b/libdecnumber/decNumber.c @@ -4775,7 +4775,7 @@ static decNumber * decDivideOp(decNumber *res, half=*up & 0x01; *up/=2; /* [shift] */ if (!half) continue; - *(up-1)+=(DECDPUNMAX+1)/2; + *(up-1)+=DIV_ROUND_UP(DECDPUNMAX, 2); } /* [accunits still describes the original remainder length] */ diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index c2824d02ba37..1930b95bcb4f 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -153,7 +153,7 @@ struct kvm_sregs { __u64 cr0, cr2, cr3, cr4, cr8; __u64 efer; __u64 apic_base; - __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64]; + __u64 interrupt_bitmap[DIV_ROUND_UP(KVM_NR_INTERRUPTS, 64)]; }; /* for KVM_GET_FPU and KVM_SET_FPU */ diff --git a/monitor.c b/monitor.c index e0f880107f28..135ec2de8ff0 100644 --- a/monitor.c +++ b/monitor.c @@ -1349,7 +1349,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, switch(format) { case 'o': - max_digits = (wsize * 8 + 2) / 3; + max_digits = DIV_ROUND_UP(wsize * 8, 3); break; default: case 'x': @@ -1357,7 +1357,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, break; case 'u': case 'd': - max_digits = (wsize * 8 * 10 + 32) / 33; + max_digits = DIV_ROUND_UP(wsize * 8 * 10, 33); break; case 'c': wsize = 1; diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c index fe0aa36932aa..e68290405223 100644 --- a/target/i386/arch_dump.c +++ b/target/i386/arch_dump.c @@ -18,6 +18,11 @@ #include "elf.h" #include "sysemu/memory_mapping.h" +#define ELF_NOTE_SIZE(hdr_size, name_size, desc_size) \ + ((DIV_ROUND_UP((hdr_size), 4) \ + + DIV_ROUND_UP((name_size), 4) \ + + DIV_ROUND_UP((desc_size), 4)) * 4) + #ifdef TARGET_X86_64 typedef struct { target_ulong r15, r14, r13, r12, rbp, rbx, r11, r10; @@ -77,16 +82,15 @@ static int x86_64_write_elf64_note(WriteCoreDumpFunction f, regs.gs = env->segs[R_GS].selector; descsz = sizeof(x86_64_elf_prstatus); - note_size = ((sizeof(Elf64_Nhdr) + 3) / 4 + (name_size + 3) / 4 + - (descsz + 3) / 4) * 4; + note_size = ELF_NOTE_SIZE(sizeof(Elf64_Nhdr), name_size, descsz); note = g_malloc0(note_size); note->n_namesz = cpu_to_le32(name_size); note->n_descsz = cpu_to_le32(descsz); note->n_type = cpu_to_le32(NT_PRSTATUS); buf = (char *)note; - buf += ((sizeof(Elf64_Nhdr) + 3) / 4) * 4; + buf += ROUND_UP(sizeof(Elf64_Nhdr), 4); memcpy(buf, name, name_size); - buf += ((name_size + 3) / 4) * 4; + buf += ROUND_UP(name_size, 4); memcpy(buf + 32, &id, 4); /* pr_pid */ buf += descsz - sizeof(x86_64_user_regs_struct)-sizeof(target_ulong); memcpy(buf, ®s, sizeof(x86_64_user_regs_struct)); @@ -156,16 +160,15 @@ static int x86_write_elf64_note(WriteCoreDumpFunction f, CPUX86State *env, x86_fill_elf_prstatus(&prstatus, env, id); descsz = sizeof(x86_elf_prstatus); - note_size = ((sizeof(Elf64_Nhdr) + 3) / 4 + (name_size + 3) / 4 + - (descsz + 3) / 4) * 4; + note_size = ELF_NOTE_SIZE(sizeof(Elf64_Nhdr), name_size, descsz); note = g_malloc0(note_size); note->n_namesz = cpu_to_le32(name_size); note->n_descsz = cpu_to_le32(descsz); note->n_type = cpu_to_le32(NT_PRSTATUS); buf = (char *)note; - buf += ((sizeof(Elf64_Nhdr) + 3) / 4) * 4; + buf += ROUND_UP(sizeof(Elf64_Nhdr), 4); memcpy(buf, name, name_size); - buf += ((name_size + 3) / 4) * 4; + buf += ROUND_UP(name_size, 4); memcpy(buf, &prstatus, sizeof(prstatus)); ret = f(note, note_size, opaque); @@ -211,16 +214,15 @@ int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, x86_fill_elf_prstatus(&prstatus, &cpu->env, cpuid); descsz = sizeof(x86_elf_prstatus); - note_size = ((sizeof(Elf32_Nhdr) + 3) / 4 + (name_size + 3) / 4 + - (descsz + 3) / 4) * 4; + note_size = ELF_NOTE_SIZE(sizeof(Elf32_Nhdr), name_size, descsz); note = g_malloc0(note_size); note->n_namesz = cpu_to_le32(name_size); note->n_descsz = cpu_to_le32(descsz); note->n_type = cpu_to_le32(NT_PRSTATUS); buf = (char *)note; - buf += ((sizeof(Elf32_Nhdr) + 3) / 4) * 4; + buf += ROUND_UP(sizeof(Elf32_Nhdr), 4); memcpy(buf, name, name_size); - buf += ((name_size + 3) / 4) * 4; + buf += ROUND_UP(name_size, 4); memcpy(buf, &prstatus, sizeof(prstatus)); ret = f(note, note_size, opaque); @@ -338,8 +340,8 @@ static inline int cpu_write_qemu_note(WriteCoreDumpFunction f, } else { note_head_size = sizeof(Elf64_Nhdr); } - note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 + - (descsz + 3) / 4) * 4; + note_size = (DIV_ROUND_UP(note_head_size, 4) + DIV_ROUND_UP(name_size, 4) + + DIV_ROUND_UP(descsz, 4)) * 4; note = g_malloc0(note_size); if (type == 0) { note32 = note; @@ -353,9 +355,9 @@ static inline int cpu_write_qemu_note(WriteCoreDumpFunction f, note64->n_type = 0; } buf = note; - buf += ((note_head_size + 3) / 4) * 4; + buf += ROUND_UP(note_head_size, 4); memcpy(buf, name, name_size); - buf += ((name_size + 3) / 4) * 4; + buf += ROUND_UP(name_size, 4); memcpy(buf, &state, sizeof(state)); ret = f(note, note_size, opaque); @@ -443,10 +445,8 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) #endif qemu_desc_size = sizeof(QEMUCPUState); - elf_note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 + - (elf_desc_size + 3) / 4) * 4; - qemu_note_size = ((note_head_size + 3) / 4 + (name_size + 3) / 4 + - (qemu_desc_size + 3) / 4) * 4; + elf_note_size = ELF_NOTE_SIZE(note_head_size, name_size, elf_desc_size); + qemu_note_size = ELF_NOTE_SIZE(note_head_size, name_size, qemu_desc_size); return (elf_note_size + qemu_note_size) * nr_cpus; } diff --git a/target/ppc/mem_helper.c b/target/ppc/mem_helper.c index e6383c6bfa83..a34e604db309 100644 --- a/target/ppc/mem_helper.c +++ b/target/ppc/mem_helper.c @@ -111,7 +111,7 @@ void helper_lswx(CPUPPCState *env, target_ulong addr, uint32_t reg, uint32_t ra, uint32_t rb) { if (likely(xer_bc != 0)) { - int num_used_regs = (xer_bc + 3) / 4; + int num_used_regs = DIV_ROUND_UP(xer_bc, 4); if (unlikely((ra != 0 && lsw_reg_in_range(reg, num_used_regs, ra)) || lsw_reg_in_range(reg, num_used_regs, rb))) { raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM, diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 01233e8b6d07..606b605ba0a4 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -2880,7 +2880,7 @@ static void gen_lswi(DisasContext *ctx) } if (nb == 0) nb = 32; - nr = (nb + 3) / 4; + nr = DIV_ROUND_UP(nb, 4); if (unlikely(lsw_reg_in_range(start, nr, ra))) { gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); return; diff --git a/tests/test-iov.c b/tests/test-iov.c index a22d71fd2c57..fa3d75aee1b2 100644 --- a/tests/test-iov.c +++ b/tests/test-iov.c @@ -167,8 +167,7 @@ static void test_io(void) } iov_from_buf(iov, niov, 0, buf, sz); - siov = g_malloc(sizeof(*iov) * niov); - memcpy(siov, iov, sizeof(*iov) * niov); + siov = g_memdup(iov, sizeof(*iov) * niov); if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) < 0) { perror("socketpair"); diff --git a/ui/cursor.c b/ui/cursor.c index 5155b392e86a..2e2fe13fa692 100644 --- a/ui/cursor.c +++ b/ui/cursor.c @@ -118,7 +118,7 @@ void cursor_put(QEMUCursor *c) int cursor_get_mono_bpl(QEMUCursor *c) { - return (c->width + 7) / 8; + return DIV_ROUND_UP(c->width, 8); } void cursor_set_mono(QEMUCursor *c, diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index 89ab12c0d808..f38aceb4da19 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -979,7 +979,7 @@ static int send_mono_rect(VncState *vs, int x, int y, } #endif - bytes = ((w + 7) / 8) * h; + bytes = (DIV_ROUND_UP(w, 8)) * h; vnc_write_u8(vs, (stream | VNC_TIGHT_EXPLICIT_FILTER) << 4); vnc_write_u8(vs, VNC_TIGHT_FILTER_PALETTE); diff --git a/ui/vnc.c b/ui/vnc.c index 651cbb860612..fd43f9b983c2 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2624,8 +2624,8 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y) int stx = x / VNC_STAT_RECT; int has_dirty = 0; - y = y / VNC_STAT_RECT * VNC_STAT_RECT; - x = x / VNC_STAT_RECT * VNC_STAT_RECT; + y = QEMU_ALIGN_DOWN(y, VNC_STAT_RECT); + x = QEMU_ALIGN_DOWN(x, VNC_STAT_RECT); QTAILQ_FOREACH(vs, &vd->clients, next) { int j; @@ -2714,8 +2714,8 @@ double vnc_update_freq(VncState *vs, int x, int y, int w, int h) double total = 0; int num = 0; - x = (x / VNC_STAT_RECT) * VNC_STAT_RECT; - y = (y / VNC_STAT_RECT) * VNC_STAT_RECT; + x = QEMU_ALIGN_DOWN(x, VNC_STAT_RECT); + y = QEMU_ALIGN_DOWN(y, VNC_STAT_RECT); for (j = y; j <= y + h; j += VNC_STAT_RECT) { for (i = x; i <= x + w; i += VNC_STAT_RECT) { @@ -2781,7 +2781,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd) PIXMAN_FORMAT_BPP(pixman_image_get_format(vd->guest.fb)); guest_row0 = (uint8_t *)pixman_image_get_data(vd->guest.fb); guest_stride = pixman_image_get_stride(vd->guest.fb); - guest_ll = pixman_image_get_width(vd->guest.fb) * ((guest_bpp + 7) / 8); + guest_ll = pixman_image_get_width(vd->guest.fb) * (DIV_ROUND_UP(guest_bpp, 8)); } line_bytes = MIN(server_stride, guest_ll);