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 fd17c8d2485e5514eac4adaf74c63125f7493149 Author: wangshaoxin <[email protected]> AuthorDate: Sun Nov 17 14:01:58 2024 +0800 drivers/mtd/rpmsgmtd: add rpmsgmtd_unregister() There was no way to remove an rpmsg MTD client once registered. Add rpmsgmtd_unregister(): it unregisters the MTD driver at localpath, unregisters the rpmsg callbacks, which destroys the endpoint, and frees the device. Signed-off-by: wangshaoxin <[email protected]> --- drivers/mtd/rpmsgmtd.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ include/nuttx/mtd/mtd.h | 19 +++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/drivers/mtd/rpmsgmtd.c b/drivers/mtd/rpmsgmtd.c index 1f5e1f153ee..2cda3befd31 100644 --- a/drivers/mtd/rpmsgmtd.c +++ b/drivers/mtd/rpmsgmtd.c @@ -1194,3 +1194,60 @@ fail: kmm_free(dev); return ret; } + +/**************************************************************************** + * Name: rpmsgmtd_unregister + * + * Description: + * Rpmsg-mtd client unregister function, the client cpu should call + * this function in the board uninitialize process. + * + * Parameters: + * localpath - the device name + * + * Returned Values: + * OK on success; A negated errno value is returned on any failure. + * + ****************************************************************************/ + +int rpmsgmtd_unregister(FAR const char *localpath) +{ + FAR struct rpmsgmtd_s *dev; + FAR struct inode *inode; + int ret; + + ret = find_mtddriver(localpath, &inode); + if (ret < 0) + { + ferr("ERROR: Failed to find mtddriver, ret=%d\n", ret); + return ret; + } + + dev = inode->i_private; + ret = close_mtddriver(inode); + if (ret < 0) + { + ferr("ERROR: Failed to close mtddriver, ret=%d\n", ret); + return ret; + } + + ret = unregister_mtddriver(localpath); + if (ret < 0) + { + ferr("ERROR: unregister driver failed, ret=%d\n", ret); + return ret; + } + + /* Unregister the rpmsg callback */ + + rpmsg_unregister_callback(dev, + rpmsgmtd_device_created, + rpmsgmtd_device_destroy, + NULL, + NULL); + + nxsem_destroy(&dev->wait); + nxmutex_destroy(&dev->geolock); + kmm_free(dev); + return ret; +} diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 64dddcdc0be..64bdbf79095 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -851,6 +851,25 @@ int rpmsgmtd_register(FAR const char *remotecpu, FAR const char *remotepath, FAR const char *localpath); #endif +/**************************************************************************** + * Name: rpmsgmtd_unregister + * + * Description: + * Rpmsg-mtd client unregister function, the client cpu should call + * this function in the board uninitialize process. + * + * Parameters: + * localpath - the device name + * + * Returned Values: + * OK on success; A negated errno value is returned on any failure. + * + ****************************************************************************/ + +#ifdef CONFIG_RPMSGMTD +int rpmsgmtd_unregister(FAR const char *localpath); +#endif + /**************************************************************************** * Name: rpmsgmtd_server_init *
