Commit 0ffaeadf authored by Michael S. Tsirkin's avatar Michael S. Tsirkin

mic_virtio: robust feature array size calculation

mic reads sizeof(vdev->features) bits from device, but in fact it stores
bits in local features variable. use sizeof(features) to make code
robust against future changes extending sizeof(vdev->features).
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>


parent e16e12be
...@@ -76,8 +76,7 @@ static u32 mic_get_features(struct virtio_device *vdev) ...@@ -76,8 +76,7 @@ static u32 mic_get_features(struct virtio_device *vdev)
u8 __iomem *in_features = mic_vq_features(desc); u8 __iomem *in_features = mic_vq_features(desc);
int feature_len = ioread8(&desc->feature_len); int feature_len = ioread8(&desc->feature_len);
bits = min_t(unsigned, feature_len, bits = min_t(unsigned, feature_len, sizeof(features)) * 8;
sizeof(vdev->features)) * 8;
for (i = 0; i < bits; i++) for (i = 0; i < bits; i++)
if (ioread8(&in_features[i / 8]) & (BIT(i % 8))) if (ioread8(&in_features[i / 8]) & (BIT(i % 8)))
features |= BIT(i); features |= BIT(i);
......
Markdown is supported
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