浏览代码

virtio: simplify feature bit handling

Now that we use u64 for bits, we can simply & them together.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Michael S. Tsirkin 10 年之前
父节点
当前提交
c102659d69
共有 1 个文件被更改,包括 6 次插入4 次删除
  1. 6 4
      drivers/virtio/virtio.c

+ 6 - 4
drivers/virtio/virtio.c

@@ -160,6 +160,7 @@ static int virtio_dev_probe(struct device *_d)
 	struct virtio_device *dev = dev_to_virtio(_d);
 	struct virtio_device *dev = dev_to_virtio(_d);
 	struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
 	struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
 	u64 device_features;
 	u64 device_features;
+	u64 driver_features;
 	unsigned status;
 	unsigned status;
 
 
 	/* We have a driver! */
 	/* We have a driver! */
@@ -168,15 +169,16 @@ static int virtio_dev_probe(struct device *_d)
 	/* Figure out what features the device supports. */
 	/* Figure out what features the device supports. */
 	device_features = dev->config->get_features(dev);
 	device_features = dev->config->get_features(dev);
 
 
-	/* Features supported by both device and driver into dev->features. */
-	dev->features = 0;
+	/* Figure out what features the driver supports. */
+	driver_features = 0;
 	for (i = 0; i < drv->feature_table_size; i++) {
 	for (i = 0; i < drv->feature_table_size; i++) {
 		unsigned int f = drv->feature_table[i];
 		unsigned int f = drv->feature_table[i];
 		BUG_ON(f >= 64);
 		BUG_ON(f >= 64);
-		if (device_features & (1ULL << f))
-			__virtio_set_bit(dev, f);
+		driver_features |= (1ULL << f);
 	}
 	}
 
 
+	dev->features = driver_features & device_features;
+
 	/* Transport features always preserved to pass to finalize_features. */
 	/* Transport features always preserved to pass to finalize_features. */
 	for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
 	for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
 		if (device_features & (1ULL << i))
 		if (device_features & (1ULL << i))