From 33c5793bd92b85b0d3666f35e44cef855b48e76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: vhost: use QEMU_ALIGN_DOWN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Michael S. Tsirkin Reviewed-by: Richard Henderson --- hw/virtio/vhost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 6eddb099b0..0049a2c0b3 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; -- cgit v1.2.3 From ec34748507c3eb812fe38afc59cc19a3bb713466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: i8254: use QEMU_ALIGN_DOWN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/timer/i8254_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/timer/i8254_common.c b/hw/timer/i8254_common.c index 976d5200f1..ee064aa819 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; -- cgit v1.2.3 From 668c2d1f91f467ae718fc3e03cffed25ade8bfce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: pcspk: use QEMU_ALIGN_DOWN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Richard Henderson --- hw/audio/pcspk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c index f643b122bb..0206f7399b 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 { -- cgit v1.2.3 From 2c23ce22c611a0cdddf9e7fdd3e8144da74744b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: vga: use DIV_ROUND_UP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Richard Henderson --- hw/display/vga.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/display/vga.c b/hw/display/vga.c index 63421f9ee8..3433102ef3 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); -- cgit v1.2.3 From e5f99037481ba405cd6c3b2beaa2b786a5c68100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: virtio-gpu: use DIV_ROUND_UP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/display/virtio-gpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 6aae147324..f0761cf18b 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) || -- cgit v1.2.3 From 7b9a27cdbb5b510c7826b816f20259131169f9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: virtio-serial: use DIV_ROUND_UP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Amit Shah --- hw/char/virtio-serial-bus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'hw') diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index f5bc173844..17a1bb008a 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 -- cgit v1.2.3 From f9406b84ba3f081dd0cd38bc28db4b8cd9134398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: piix: use DIV_ROUND_UP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/pci-host/piix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 072a04e318..894e131c00 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)); -- cgit v1.2.3 From fa141081b9e2b6c4ae963604fcb5b994ff322936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: q35: use DIV_ROUND_UP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Richard Henderson --- hw/pci-host/q35.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 0e472f2ed4..1ff648e80c 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(); } -- cgit v1.2.3 From 54ac85ef0d5c76503548cec29e4e0b556e3cf00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: usb-hub: use DIV_ROUND_UP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Richard Henderson --- hw/usb/dev-hub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'hw') diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index e82a6a6c44..752e30c305 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) { -- cgit v1.2.3 From 0ef1efcf944fcc950840f068da5513311ee55a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 22 Jun 2017 13:04:16 +0200 Subject: msix: use DIV_ROUND_UP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used the clang-tidy qemu-round check to generate the fix: https://github.com/elmarco/clang-tools-extra Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/pci/msix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/pci/msix.c b/hw/pci/msix.c index 5078d3dd19..c944c02135 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++) { -- cgit v1.2.3 From ad2c19937e0b80f8037e411f72e6d6078fe673ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 7 Jun 2017 00:45:43 +0400 Subject: i386: replace g_malloc()+memcpy() with g_memdup() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I found these pattern via grepping the source tree. I don't have a coccinelle script for it! Signed-off-by: Marc-André Lureau Reviewed-by: Eduardo Habkost Reviewed-by: Richard Henderson --- hw/i386/multiboot.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c index f13e23139b..6001f4caa2 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); -- cgit v1.2.3 From e4d67e4f2e06128bc7f07263afe9acc2e2242fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 7 Jun 2017 00:45:43 +0400 Subject: eepro100: replace g_malloc()+memcpy() with g_memdup() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I found these pattern via grepping the source tree. I don't have a coccinelle script for it! Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Weil Reviewed-by: Jason Wang Reviewed-by: Richard Henderson --- hw/net/eepro100.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index 5a4774aab4..a7b9f77519 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); } -- cgit v1.2.3