Skip to contentSkip to conversation

Fix and enhance virtio device id matching

PATCH In review Christian Borntraeger 2 participants 7 messages May 26, 2009 – May 27, 2009

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH 1/2 virtio: fix id_matching for virtio drivers

In reply to Christian Borntraeger

From: Christian Borntraeger <[email protected]>

This bug never appeared, since all current virtio drivers use VIRTIO_DEV_ANY_ID for the vendor field. If a real vendor would be used, the check in virtio_id_match is wrong - it returns 0 if id->vendor == dev->id.vendor.

---
 drivers/virtio/virtio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio.c +1 -1
Index: linux-next/drivers/virtio/virtio.c
===================================================================
@@ -61,7 +61,7 @@ static inline int virtio_id_match(const 
 	if (id->device != dev->id.device)
 		return 0;
 
-	return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor != dev->id.vendor;
+	return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor == dev->id.vendor;
 }
 
 /* This looks through all the IDs a driver claims to support.  If any of them
#3 lore raw

PATCH 2/2 virtio: enhance id_matching for virtio drivers

In reply to Christian Borntraeger

From: Christian Borntraeger <[email protected]>

This patch allows a virtio driver to use VIRTIO_DEV_ANY_ID for the device id. This will be used by a test module that can be bound to any virtio device.

---
 drivers/virtio/virtio.c  |    2 +-
 scripts/mod/file2alias.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/virtio/virtio.c +1 -1
Index: linux-next/drivers/virtio/virtio.c
===================================================================
@@ -58,7 +58,7 @@ static struct device_attribute virtio_de
 static inline int virtio_id_match(const struct virtio_device *dev,
 				  const struct virtio_device_id *id)
 {
-	if (id->device != dev->id.device)
+	if (id->device != dev->id.device && id->device != VIRTIO_DEV_ANY_ID)
 		return 0;
 
 	return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor == dev->id.vendor;
scripts/mod/file2alias.c +1 -1
Index: linux-next/scripts/mod/file2alias.c
===================================================================
@@ -641,7 +641,7 @@ static int do_virtio_entry(const char *f
 	id->vendor = TO_NATIVE(id->vendor);
 
 	strcpy(alias, "virtio:");
-	ADD(alias, "d", 1, id->device);
+	ADD(alias, "d", id->device != VIRTIO_DEV_ANY_ID, id->device);
 	ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor);
 
 	add_wildcard(alias);
#0 lore raw

cover Fix and enhance virtio device id matching

Hello Rusty,

here are two patches that change the device matching of the virtio bus. The patches have been refreshed agains linux-next and should apply to your private virtio tree.

OK for linux-next?

Christian

#2 lore raw

PATCH 1/2 virtio: fix id_matching for virtio drivers

From: Christian Borntraeger <[email protected]>

This bug never appeared, since all current virtio drivers use VIRTIO_DEV_ANY_ID for the vendor field. If a real vendor would be used, the check in virtio_id_match is wrong - it returns 0 if id->vendor == dev->id.vendor.

---
 drivers/virtio/virtio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio.c +1 -1
Index: linux-next/drivers/virtio/virtio.c
===================================================================
@@ -61,7 +61,7 @@ static inline int virtio_id_match(const 
 	if (id->device != dev->id.device)
 		return 0;
 
-	return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor != dev->id.vendor;
+	return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor == dev->id.vendor;
 }
 
 /* This looks through all the IDs a driver claims to support.  If any of them
#4 lore raw

PATCH 2/2 virtio: enhance id_matching for virtio drivers

In reply to Christian Borntraeger

From: Christian Borntraeger <[email protected]>

This patch allows a virtio driver to use VIRTIO_DEV_ANY_ID for the device id. This will be used by a test module that can be bound to any virtio device.

---
 drivers/virtio/virtio.c  |    2 +-
 scripts/mod/file2alias.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/virtio/virtio.c +1 -1
Index: linux-next/drivers/virtio/virtio.c
===================================================================
@@ -58,7 +58,7 @@ static struct device_attribute virtio_de
 static inline int virtio_id_match(const struct virtio_device *dev,
 				  const struct virtio_device_id *id)
 {
-	if (id->device != dev->id.device)
+	if (id->device != dev->id.device && id->device != VIRTIO_DEV_ANY_ID)
 		return 0;
 
 	return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor == dev->id.vendor;
scripts/mod/file2alias.c +1 -1
Index: linux-next/scripts/mod/file2alias.c
===================================================================
@@ -641,7 +641,7 @@ static int do_virtio_entry(const char *f
 	id->vendor = TO_NATIVE(id->vendor);
 
 	strcpy(alias, "virtio:");
-	ADD(alias, "d", 1, id->device);
+	ADD(alias, "d", id->device != VIRTIO_DEV_ANY_ID, id->device);
 	ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor);
 
 	add_wildcard(alias);
#5 lore raw
In reply to Christian Borntraeger
Quoted 7 lines · Christian Borntraeger

Hello Rusty,

here are two patches that change the device matching of the virtio bus. The patches have been refreshed agains linux-next and should apply to your private virtio tree.

OK for linux-next?

Sure, added.

Thanks!
Rusty.

#6 lore raw
In reply to Christian Borntraeger
Quoted 7 lines · Christian Borntraeger

Hello Rusty,

here are two patches that change the device matching of the virtio bus. The patches have been refreshed agains linux-next and should apply to your private virtio tree.

OK for linux-next?

Sure, added.

Thanks!
Rusty.