diff --git a/drivers/video/video.c b/drivers/video/video.c index a3ba606b01e04..7d4b676ae377e 100644 --- a/drivers/video/video.c +++ b/drivers/video/video.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -1015,6 +1017,18 @@ static void cleanup_resources(FAR video_mng_t *vmng) cleanup_scenes_parameter(vmng); } +static void cleanup_private_data(FAR struct inode *inode) +{ + FAR video_mng_t *priv = inode->i_private; + + nxmutex_unlock(&priv->lock_open_num); + nxmutex_destroy(&priv->lock_open_num); + unregister_driver(priv->devpath); + kmm_free(priv->devpath); + kmm_free(priv); + inode->i_private = NULL; +} + static bool is_sem_waited(FAR sem_t *sem) { int semcount; @@ -1094,11 +1108,7 @@ static int video_close(FAR struct file *filep) #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS if (priv->unlinked) { - nxmutex_unlock(&priv->lock_open_num); - nxmutex_destroy(&priv->lock_open_num); - kmm_free(priv->devpath); - kmm_free(priv); - inode->i_private = NULL; + cleanup_private_data(inode); return OK; } @@ -1128,11 +1138,7 @@ static int video_unlink(FAR struct inode *inode) nxmutex_lock(&priv->lock_open_num); if (priv->open_num == 0) { - nxmutex_unlock(&priv->lock_open_num); - nxmutex_destroy(&priv->lock_open_num); - kmm_free(priv->devpath); - kmm_free(priv); - inode->i_private = NULL; + cleanup_private_data(inode); } else { @@ -3488,7 +3494,16 @@ int video_register(FAR const char *devpath, int video_unregister(FAR const char *devpath) { - return unregister_driver(devpath); + int ret; + struct stat buf; + + ret = nx_stat(devpath, &buf, 1); + if (ret == 0) + { + ret = nx_unlink(devpath); + } + + return ret; } int imgsensor_register(FAR struct imgsensor_s *sensor)