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 039e2f2e68d7188914af33bda0bc5af0d0998b53 Author: wangshaoxin <[email protected]> AuthorDate: Mon Mar 9 15:04:44 2026 +0800 drivers/misc/rpmsgdev: add rpmsgdev_unregister() Add rpmsgdev_unregister() to undo rpmsgdev_register(): it unregisters the local device node and the rpmsg callbacks and frees the device. Signed-off-by: wangshaoxin <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- drivers/misc/rpmsgdev.c | 63 ++++++++++++++++++++++++++++++++++++++++ include/nuttx/drivers/rpmsgdev.h | 1 + 2 files changed, 64 insertions(+) diff --git a/drivers/misc/rpmsgdev.c b/drivers/misc/rpmsgdev.c index 22b00342547..141839d655d 100644 --- a/drivers/misc/rpmsgdev.c +++ b/drivers/misc/rpmsgdev.c @@ -1414,3 +1414,66 @@ fail: return ret; } + +/**************************************************************************** + * Name: rpmsgdev_unregister + * + * Description: + * Rpmsg-device client uninitialize function, the client cpu should call + * this function to unregister the rpmsg device. + * + * Parameters: + * localpath - the device path which bindded to the rpmsg device + * + * Returned Values: + * OK on success; A negated errno value is returned on any failure. + * + ****************************************************************************/ + +int rpmsgdev_unregister(FAR const char *localpath) +{ + FAR struct rpmsgdev_s *dev; + struct file file; + int ret; + + if (localpath == NULL) + { + return -EINVAL; + } + + /* Open the device to get the inode reference */ + + ret = file_open(&file, localpath, O_RDWR); + if (ret < 0) + { + rpmsgdeverr("Failed to open %s, ret=%d\n", localpath, ret); + return ret; + } + + /* Get the private data from the inode */ + + dev = file.f_inode->i_private; + file_close(&file); + + /* Unregister the driver */ + + ret = unregister_driver(localpath); + if (ret < 0) + { + rpmsgdeverr("unregister driver failed, ret=%d\n", ret); + return ret; + } + + /* Unregister the rpmsg callback */ + + rpmsg_unregister_callback(dev, + rpmsgdev_device_created, + rpmsgdev_device_destroy, + NULL, + NULL); + + nxsem_destroy(&dev->wait); + kmm_free(dev); + return ret; +} + diff --git a/include/nuttx/drivers/rpmsgdev.h b/include/nuttx/drivers/rpmsgdev.h index 84d91ce7b33..e002a50b5b2 100644 --- a/include/nuttx/drivers/rpmsgdev.h +++ b/include/nuttx/drivers/rpmsgdev.h @@ -101,6 +101,7 @@ int rpmsgdev_export_with_prefix(FAR const char *remotecpu, #ifdef CONFIG_DEV_RPMSG int rpmsgdev_register(FAR const char *remotecpu, FAR const char *remotepath, FAR const char *localpath); +int rpmsgdev_unregister(FAR const char *localpath); #endif #if defined(__cplusplus)
