aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-08-31 15:52:43 +0100
committerPeter Maydell <peter.maydell@linaro.org>2017-08-31 15:52:43 +0100
commit223cd0e13f2e46078d7b573f0b8402bfbee339be (patch)
treefc141300eae2e20ea36d235f776e91353365c8c0 /hw
parent1d2a8e0690a8b26833346c6e84e91773da66fbf4 (diff)
parente4d67e4f2e06128bc7f07263afe9acc2e2242fdc (diff)
downloadqemu-223cd0e13f2e46078d7b573f0b8402bfbee339be.zip
qemu-223cd0e13f2e46078d7b573f0b8402bfbee339be.tar.gz
qemu-223cd0e13f2e46078d7b573f0b8402bfbee339be.tar.bz2
Merge remote-tracking branch 'remotes/elmarco/tags/tidy-pull-request' into staging
# gpg: Signature made Thu 31 Aug 2017 11:29:33 BST # gpg: using RSA key 0xDAE8E10975969CE5 # gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" # gpg: aka "Marc-André Lureau <marcandre.lureau@gmail.com>" # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: 87A9 BD93 3F87 C606 D276 F62D DAE8 E109 7596 9CE5 * remotes/elmarco/tags/tidy-pull-request: (29 commits) eepro100: replace g_malloc()+memcpy() with g_memdup() test-iov: replace g_malloc()+memcpy() with g_memdup() i386: replace g_malloc()+memcpy() with g_memdup() i386: introduce ELF_NOTE_SIZE macro decnumber: use DIV_ROUND_UP kvm: use DIV_ROUND_UP i386/dump: use DIV_ROUND_UP ppc: use DIV_ROUND_UP msix: use DIV_ROUND_UP usb-hub: use DIV_ROUND_UP q35: use DIV_ROUND_UP piix: use DIV_ROUND_UP virtio-serial: use DIV_ROUND_UP console: use DIV_ROUND_UP monitor: use DIV_ROUND_UP virtio-gpu: use DIV_ROUND_UP vga: use DIV_ROUND_UP ui: use DIV_ROUND_UP vnc: use DIV_ROUND_UP vvfat: use DIV_ROUND_UP ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/audio/pcspk.c2
-rw-r--r--hw/char/virtio-serial-bus.c8
-rw-r--r--hw/display/vga.c2
-rw-r--r--hw/display/virtio-gpu.c4
-rw-r--r--hw/i386/multiboot.c3
-rw-r--r--hw/net/eepro100.c3
-rw-r--r--hw/pci-host/piix.c2
-rw-r--r--hw/pci-host/q35.c2
-rw-r--r--hw/pci/msix.c4
-rw-r--r--hw/timer/i8254_common.c4
-rw-r--r--hw/usb/dev-hub.c8
-rw-r--r--hw/virtio/vhost.c2
12 files changed, 21 insertions, 23 deletions
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index f643b12..0206f73 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 f5bc173..17a1bb0 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 63421f9..3433102 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 6aae147..f0761cf 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 f13e231..6001f4c 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 5a4774a..a7b9f77 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 072a04e..894e131 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 0e472f2..1ff648e 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 5078d3d..c944c02 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 976d520..ee064aa 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 e82a6a6..752e30c 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 6eddb09..0049a2c 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;