This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0a1834de81b189f445064beb483d3c1c9c2cad47 Author: wangjianyu3 <[email protected]> AuthorDate: Fri Nov 20 15:31:27 2026 +0800 drivers/misc/ramdisk: defer unregister release ramdisk_unregister() releases the ramdisk descriptor unconditionally, even when unregister_blockdriver() reports -EBUSY because the device is still open: the open reference then keeps a dangling inode->i_private. It also bypasses rd_destroy(), so the buffer of a device registered with RDFLAG_FUNLINK is never released. Treat -EBUSY as success and let the last close release the resources, as rd_unlink() already does. When CONFIG_DISABLE_PSEUDOFS_OPERATIONS is set there is no open reference to defer to, so the descriptor is kept instead of being freed under an open device. Assisted-by: OpenCode:claude-sonnet-5 Co-authored-by: multica-agent <[email protected]> Signed-off-by: wangjianyu3 <[email protected]> --- drivers/misc/ramdisk.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/misc/ramdisk.c b/drivers/misc/ramdisk.c index 52f83fe1723..9dd67c35262 100644 --- a/drivers/misc/ramdisk.c +++ b/drivers/misc/ramdisk.c @@ -521,15 +521,28 @@ int ramdisk_unregister(FAR const char *path) } ret = unregister_blockdriver(path); - if (ret < 0) + if (ret < 0 && ret != -EBUSY) { ferr("ERROR: unregister driver failed, ret=%d\n", ret); return ret; } - /* Release the driver space */ + /* Release the driver space, or defer it to the last close */ + +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + RDFLAG_UNLINK(dev->rd_flags); + if (dev->rd_crefs == 0) + { + rd_destroy(dev); + } +#else + if (ret == -EBUSY) + { + return -EBUSY; + } kmm_free(dev); +#endif - return ret; + return OK; }
