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:
parent
3b79363041
commit
e0c18c05e8
@ -285,32 +285,21 @@ static int pty_open(FAR struct file *filep)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If one side of the driver has been unlinked, then refuse further
|
/* First open? */
|
||||||
* opens.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (devpair->pp_unlinked)
|
if (devpair->pp_nopen == 0)
|
||||||
{
|
{
|
||||||
ret = -EIDRM;
|
/* Yes, create the internal pipe */
|
||||||
|
|
||||||
|
ret = pty_pipe(devpair);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
/* Increment the count of open references on the driver */
|
||||||
|
|
||||||
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
/* First open? */
|
devpair->pp_nopen++;
|
||||||
|
DEBUGASSERT(devpair->pp_nopen > 0);
|
||||||
if (devpair->pp_nopen == 0)
|
|
||||||
{
|
|
||||||
/* Yes, create the internal pipe */
|
|
||||||
|
|
||||||
ret = pty_pipe(devpair);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Increment the count of open references on the driver */
|
|
||||||
|
|
||||||
if (ret >= 0)
|
|
||||||
{
|
|
||||||
devpair->pp_nopen++;
|
|
||||||
DEBUGASSERT(devpair->pp_nopen > 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nxmutex_unlock(&devpair->pp_lock);
|
nxmutex_unlock(&devpair->pp_lock);
|
||||||
@ -318,7 +307,7 @@ static int pty_open(FAR struct file *filep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: pty_open
|
* Name: pty_close
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int pty_close(FAR struct file *filep)
|
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) */
|
/* Yes.. Free the device pair now (without freeing the semaphore) */
|
||||||
|
|
||||||
|
nxmutex_unlock(&devpair->pp_lock);
|
||||||
pty_destroy(devpair);
|
pty_destroy(devpair);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -961,6 +951,7 @@ static int pty_unlink(FAR struct inode *inode)
|
|||||||
|
|
||||||
if (devpair->pp_nopen == 0)
|
if (devpair->pp_nopen == 0)
|
||||||
{
|
{
|
||||||
|
nxmutex_unlock(&devpair->pp_lock);
|
||||||
pty_destroy(devpair);
|
pty_destroy(devpair);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,16 @@ int unregister_driver(FAR const char *path)
|
|||||||
{
|
{
|
||||||
int ret;
|
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();
|
ret = inode_lock();
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user