driver/vhost: Check driver isn't NULL before calling remove

since the device mayn't bind to the driver yet

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2024-10-05 19:30:43 +08:00 committed by Alan C. Assis
parent 0f918c8d4d
commit bad1627759
1 changed files with 13 additions and 21 deletions

View File

@ -150,25 +150,6 @@ static void vhost_defered_probe_work(FAR void *arg)
nxmutex_unlock(&g_vhost_bus.lock);
}
/****************************************************************************
* Name: vhost_remove_device
****************************************************************************/
static void vhost_remove_device(FAR struct vhost_device_item_s *item)
{
/* Call driver remove and mark item->driver NULL to indicate
* the device unmatched.
*/
item->driver->remove(item->device);
item->driver = NULL;
/* Remove the device from the device list and free memory */
list_delete(&item->node);
kmm_free(item);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -352,7 +333,17 @@ int vhost_unregister_device(FAR struct vhost_device *device)
{
if (item->device == device)
{
vhost_remove_device(item);
/* Call driver remove */
if (item->driver)
{
item->driver->remove(item->device);
}
/* Remove the device from the device list and free memory */
list_delete(&item->node);
kmm_free(item);
goto out;
}
}
@ -362,7 +353,8 @@ int vhost_unregister_device(FAR struct vhost_device *device)
{
if (item->device == device)
{
vhost_remove_device(item);
list_delete(&item->node);
kmm_free(item);
goto out;
}
}