Skip to content

Commit

Permalink
virtio/vhost: assign the virtio/vhost_drvier to device->priv before p…
Browse files Browse the repository at this point in the history
…robe

So the driver can get the driver pointer by vdev/hdev->priv,
and later vdev/hdev->priv can be used to store other data such as the
virtio/vhost drivers' private data.

Signed-off-by: Bowen Wang <[email protected]>
  • Loading branch information
CV-Bowen authored and xiaoxiang781216 committed Oct 3, 2024
1 parent c42576e commit 51d6e8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions drivers/vhost/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ static void vhost_defered_probe_work(FAR void *arg)
{
if (item->device->id.device == driver->device)
{
item->device->priv = driver;
if (driver->probe(item->device) >= 0)
{
vhosterr("device probe success device=%p\n", item->device);
item->driver = driver;
break;
}

break;
}
}
}
Expand Down Expand Up @@ -207,6 +207,7 @@ int vhost_register_driver(FAR struct vhost_driver *driver)
* matched.
*/

item->device->priv = driver;
if (driver->probe(item->device) >= 0)
{
item->driver = driver;
Expand Down
7 changes: 4 additions & 3 deletions drivers/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,14 @@ int virtio_register_driver(FAR struct virtio_driver *driver)
FAR struct virtio_device_item_s *item =
container_of(node, struct virtio_device_item_s, node);
FAR struct virtio_device *device = item->device;
if (driver->device == device->id.device)
if (item->driver == NULL && driver->device == device->id.device)
{
/* If found the device in the device list, call driver probe,
* if probe success, assign item->driver to indicate the device
* matched.
*/

device->priv = driver;
if (driver->probe(device) >= 0)
{
item->driver = driver;
Expand Down Expand Up @@ -327,12 +328,12 @@ int virtio_register_device(FAR struct virtio_device *device)
* matched.
*/

device->priv = driver;
if (driver->probe(device) >= 0)
{
item->driver = driver;
break;
}

break;
}
}

Expand Down

0 comments on commit 51d6e8f

Please sign in to comment.