This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6f291e2dea0266b690ab7dde5f1e6473e57c050f Author: wangyongrong <[email protected]> AuthorDate: Mon Apr 27 20:26:55 2026 +0800 drivers/rptun: release an rptun instance on unlink Nothing could undo rptun_initialize(): the instance, its remoteproc and its /dev/rptun/<cpuname> node stayed until reboot. Add an unlink callback that stops the remote core, takes the instance off the global list, removes the remoteproc, cancels the pending work and frees the instance. While the instance is still being started, rptun_dev_stop() returns -EBUSY and unlink fails with it. Add rptun_uninitialize(cpuname) as the counterpart of rptun_initialize(); it unregisters /dev/rptun/<cpuname>, which runs the same callback. Signed-off-by: wangyongrong <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- drivers/rptun/rptun.c | 44 ++++++++++++++++++++++++++++++++++++++------ include/nuttx/rptun/rptun.h | 1 + 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index ce973a889cf..fd499443608 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -132,6 +132,9 @@ static int rptun_dev_start(FAR struct rptun_priv_s *priv); static int rptun_dev_stop(FAR struct remoteproc *rproc); static int rptun_dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static int rptun_dev_unlink(FAR struct inode *inode); +#endif #ifdef CONFIG_RPTUN_LOADER static int rptun_store_open(FAR void *store_, FAR const char *path, @@ -185,12 +188,10 @@ static const struct remoteproc_ops g_rptun_ops = static const struct file_operations g_rptun_fops = { - 0, /* open */ - 0, /* close */ - 0, /* read */ - 0, /* write */ - 0, /* seek */ - rptun_dev_ioctl, /* ioctl */ + .ioctl = rptun_dev_ioctl, +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + .unlink = rptun_dev_unlink, +#endif }; #ifdef CONFIG_RPTUN_LOADER @@ -1373,6 +1374,29 @@ static int rptun_do_ioctl(FAR struct rptun_priv_s *priv, int cmd, return ret; } +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +static int rptun_dev_unlink(FAR struct inode *inode) +{ + FAR struct rptun_priv_s *priv = inode->i_private; + int ret; + + ret = rptun_dev_stop(&priv->rproc); + if (ret < 0) + { + return ret; + } + + nxrmutex_lock(&g_rptun_lock); + dq_rem(&priv->entry, &g_rptun_priv); + nxrmutex_unlock(&g_rptun_lock); + + remoteproc_remove(&priv->rproc); + work_cancel_sync(HPWORK, &priv->work); + kmm_free(priv); + return OK; +} +#endif + static int rptun_dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { @@ -1733,6 +1757,14 @@ void rptun_dump_resource(FAR const struct resource_table *rsc) } } +int rptun_uninitialize(FAR const char *cpuname) +{ + char name[32]; + + snprintf(name, sizeof(name), "/dev/rptun/%s", cpuname); + return unregister_driver(name); +} + int rptun_boot(FAR const char *cpuname) { return rptun_ioctl_foreach(cpuname, RPTUNIOC_START, 0); diff --git a/include/nuttx/rptun/rptun.h b/include/nuttx/rptun/rptun.h index 08a123adae7..9640c884468 100644 --- a/include/nuttx/rptun/rptun.h +++ b/include/nuttx/rptun/rptun.h @@ -355,6 +355,7 @@ int rptun_initialize(FAR struct rptun_dev_s *dev); void rptun_dump_resource(FAR const struct resource_table *rsc); int rptun_boot(FAR const char *cpuname); int rptun_poweroff(FAR const char *cpuname); +int rptun_uninitialize(FAR const char *cpuname); int rptun_reset(FAR const char *cpuname, unsigned long value); #ifdef __cplusplus
