Commit eaeaf608 authored by Andre Przywara's avatar Andre Przywara Committed by Will Deacon
Browse files

virtio/blk: Avoid taking pointer to packed struct

clang and GCC9 refuse to compile virtio/blk.c with the following message:
virtio/blk.c:161:37: error: taking address of packed member 'geometry' of class
      or structure 'virtio_blk_config' may result in an unaligned pointer value
        struct virtio_blk_geometry *geo = &conf->geometry;

Since struct virtio_blk_geometry is in a kernel header, we can't do much
about the packed attribute, but as Peter pointed out, the solution is
rather simple: just get rid of the convenience variable and use the
original struct member directly.

Reviewed-by: Jean-Philippe Brucker's avatarJean-Philippe Brucker <>
Suggested-by: default avatarPeter Maydell <>
Signed-off-by: Andre Przywara's avatarAndre Przywara <>
Signed-off-by: default avatarWill Deacon <>
parent a3704b91
......@@ -161,7 +161,6 @@ static void set_guest_features(struct kvm *kvm, void *dev, u32 features)
struct blk_dev *bdev = dev;
struct virtio_blk_config *conf = &bdev->blk_config;
struct virtio_blk_geometry *geo = &conf->geometry;
bdev->features = features;
......@@ -170,7 +169,8 @@ static void set_guest_features(struct kvm *kvm, void *dev, u32 features)
conf->seg_max = virtio_host_to_guest_u32(&bdev->vdev, conf->seg_max);
/* Geometry */
geo->cylinders = virtio_host_to_guest_u16(&bdev->vdev, geo->cylinders);
conf->geometry.cylinders = virtio_host_to_guest_u16(&bdev->vdev,
conf->blk_size = virtio_host_to_guest_u32(&bdev->vdev, conf->blk_size);
conf->min_io_size = virtio_host_to_guest_u16(&bdev->vdev, conf->min_io_size);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment