fs/driver: using nx_unlink to call unlink ops to release some resource

if driver complete unlink ops, we need to call it to release some resource,
otherwise, it will only remove inode.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-12-22 11:06:12 +08:00 committed by Xiang Xiao
parent 3b79363041
commit e0c18c05e8
2 changed files with 24 additions and 23 deletions

View File

@ -285,16 +285,6 @@ static int pty_open(FAR struct file *filep)
}
}
/* If one side of the driver has been unlinked, then refuse further
* opens.
*/
if (devpair->pp_unlinked)
{
ret = -EIDRM;
}
else
{
/* First open? */
if (devpair->pp_nopen == 0)
@ -311,14 +301,13 @@ static int pty_open(FAR struct file *filep)
devpair->pp_nopen++;
DEBUGASSERT(devpair->pp_nopen > 0);
}
}
nxmutex_unlock(&devpair->pp_lock);
return ret;
}
/****************************************************************************
* Name: pty_open
* Name: pty_close
****************************************************************************/
static int pty_close(FAR struct file *filep)
@ -372,6 +361,7 @@ static int pty_close(FAR struct file *filep)
{
/* Yes.. Free the device pair now (without freeing the semaphore) */
nxmutex_unlock(&devpair->pp_lock);
pty_destroy(devpair);
return OK;
}
@ -961,6 +951,7 @@ static int pty_unlink(FAR struct inode *inode)
if (devpair->pp_nopen == 0)
{
nxmutex_unlock(&devpair->pp_lock);
pty_destroy(devpair);
return OK;
}

View File

@ -44,6 +44,16 @@ int unregister_driver(FAR const char *path)
{
int ret;
/* Call unlink to release driver resource and inode. */
ret = nx_unlink(path);
if (ret >= 0)
{
return ret;
}
/* If unlink failed, only remove inode. */
ret = inode_lock();
if (ret >= 0)
{