VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint8_t val;
- k->get_config(vdev, vdev->config);
-
- if (addr > (vdev->config_len - sizeof(val)))
+ if (addr + sizeof(val) > vdev->config_len) {
return (uint32_t)-1;
+ }
+
+ k->get_config(vdev, vdev->config);
val = ldub_p(vdev->config + addr);
return val;
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint16_t val;
- k->get_config(vdev, vdev->config);
-
- if (addr > (vdev->config_len - sizeof(val)))
+ if (addr + sizeof(val) > vdev->config_len) {
return (uint32_t)-1;
+ }
+
+ k->get_config(vdev, vdev->config);
val = lduw_p(vdev->config + addr);
return val;
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint32_t val;
- k->get_config(vdev, vdev->config);
-
- if (addr > (vdev->config_len - sizeof(val)))
+ if (addr + sizeof(val) > vdev->config_len) {
return (uint32_t)-1;
+ }
+
+ k->get_config(vdev, vdev->config);
val = ldl_p(vdev->config + addr);
return val;
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint8_t val = data;
- if (addr > (vdev->config_len - sizeof(val)))
+ if (addr + sizeof(val) > vdev->config_len) {
return;
+ }
stb_p(vdev->config + addr, val);
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint16_t val = data;
- if (addr > (vdev->config_len - sizeof(val)))
+ if (addr + sizeof(val) > vdev->config_len) {
return;
+ }
stw_p(vdev->config + addr, val);
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint32_t val = data;
- if (addr > (vdev->config_len - sizeof(val)))
+ if (addr + sizeof(val) > vdev->config_len) {
return;
+ }
stl_p(vdev->config + addr, val);