PTY: Need to free PTMX minor number is slave is unlinked
This commit is contained in:
parent
e50646336b
commit
14c216107a
@ -202,38 +202,6 @@ static int ptmx_minor_allocate(void)
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ptmx_minor_free
|
||||
*
|
||||
* Description:
|
||||
* De-allocate a PTY minor number.
|
||||
*
|
||||
* Assumptions:
|
||||
* Caller hold the px_exclsem
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void ptmx_minor_free(uint8_t minor)
|
||||
{
|
||||
int index;
|
||||
int bitno;
|
||||
|
||||
/* Free the address by clearing the associated bit in the px_alloctab[]; */
|
||||
|
||||
index = minor >> 5;
|
||||
bitno = minor & 31;
|
||||
|
||||
DEBUGASSERT((g_ptmx.px_alloctab[index] |= (1 << bitno)) != 0);
|
||||
g_ptmx.px_alloctab[index] &= ~(1 << bitno);
|
||||
|
||||
/* Reset the next pointer if the one just released has a lower value */
|
||||
|
||||
if (minor < g_ptmx.px_next)
|
||||
{
|
||||
g_ptmx.px_next = minor;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ptmx_open
|
||||
****************************************************************************/
|
||||
@ -341,3 +309,35 @@ int ptmx_register(void)
|
||||
|
||||
return register_driver("/dev/ptmx", &g_ptmx_fops, 0666, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ptmx_minor_free
|
||||
*
|
||||
* Description:
|
||||
* De-allocate a PTY minor number.
|
||||
*
|
||||
* Assumptions:
|
||||
* Caller hold the px_exclsem
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void ptmx_minor_free(uint8_t minor)
|
||||
{
|
||||
int index;
|
||||
int bitno;
|
||||
|
||||
/* Free the address by clearing the associated bit in the px_alloctab[]; */
|
||||
|
||||
index = minor >> 5;
|
||||
bitno = minor & 31;
|
||||
|
||||
DEBUGASSERT((g_ptmx.px_alloctab[index] |= (1 << bitno)) != 0);
|
||||
g_ptmx.px_alloctab[index] &= ~(1 << bitno);
|
||||
|
||||
/* Reset the next pointer if the one just released has a lower value */
|
||||
|
||||
if (minor < g_ptmx.px_next)
|
||||
{
|
||||
g_ptmx.px_next = minor;
|
||||
}
|
||||
}
|
||||
|
@ -182,6 +182,12 @@ static void pty_destroy(FAR struct pty_devpair_s *devpair)
|
||||
(void)file_close_detached(&devpair->pp_slave.pd_src);
|
||||
(void)file_close_detached(&devpair->pp_slave.pd_sink);
|
||||
|
||||
#ifdef CONFIG_PSEUDOTERM_SUSV1
|
||||
/* Free this minor number so that it can be reused */
|
||||
|
||||
ptmx_minor_free(devpair->pp_minor);
|
||||
#endif
|
||||
|
||||
/* And free the device structure */
|
||||
|
||||
sem_destroy(&devpair->pp_exclsem);
|
||||
|
@ -54,6 +54,21 @@ extern "C"
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ptmx_minor_free
|
||||
*
|
||||
* Description:
|
||||
* De-allocate a PTY minor number.
|
||||
*
|
||||
* Assumptions:
|
||||
* Caller hold the px_exclsem
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_PSEUDOTERM_SUSV1
|
||||
void ptmx_minor_free(uint8_t minor);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pty_register
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user