This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e9550783d32205a4888285b62817d2f8bc6e85e9 Author: anjiahao <anjia...@xiaomi.com> AuthorDate: Wed Jul 10 20:49:28 2024 +0800 modlib:add new api to uninitialize modp Signed-off-by: anjiahao <anjia...@xiaomi.com> --- include/nuttx/lib/modlib.h | 10 +++++ libs/libc/modlib/modlib_remove.c | 95 ++++++++++++++++++++++++---------------- 2 files changed, 68 insertions(+), 37 deletions(-) diff --git a/include/nuttx/lib/modlib.h b/include/nuttx/lib/modlib.h index f55521e07f..f70491406a 100644 --- a/include/nuttx/lib/modlib.h +++ b/include/nuttx/lib/modlib.h @@ -691,6 +691,16 @@ FAR void *modlib_insert(FAR const char *filename, FAR const char *modname); FAR const void *modlib_getsymbol(FAR void *handle, FAR const char *name); +/**************************************************************************** + * Name: modlib_uninit + * + * Description: + * Uninitialize module resources. + * + ****************************************************************************/ + +int modlib_uninit(FAR struct module_s *modp); + /**************************************************************************** * Name: modlib_remove * diff --git a/libs/libc/modlib/modlib_remove.c b/libs/libc/modlib/modlib_remove.c index 765b85ee31..1f6c864fe2 100644 --- a/libs/libc/modlib/modlib_remove.c +++ b/libs/libc/modlib/modlib_remove.c @@ -36,50 +36,26 @@ ****************************************************************************/ /**************************************************************************** - * Name: modlib_remove + * Name: modlib_uninit * * Description: - * Remove a previously installed module from memory. - * - * Input Parameters: - * handle - The module handler previously returned by modlib_insert(). - * - * Returned Value: - * Zero (OK) on success. On any failure, -1 (ERROR) is returned the - * errno value is set appropriately. + * Uninitialize module resources. * ****************************************************************************/ -int modlib_remove(FAR void *handle) +int modlib_uninit(FAR struct module_s *modp) { - FAR struct module_s *modp = (FAR struct module_s *)handle; FAR void (**array)(void); - int ret; + int ret = OK; int i; - DEBUGASSERT(modp != NULL); - - /* Get exclusive access to the module registry */ - - modlib_registry_lock(); - - /* Verify that the module is in the registry */ - - ret = modlib_registry_verify(modp); - if (ret < 0) - { - berr("ERROR: Failed to verify module: %d\n", ret); - goto errout_with_lock; - } - #if CONFIG_MODLIB_MAXDEPEND > 0 /* Refuse to remove any module that other modules may depend upon. */ if (modp->dependents > 0) { berr("ERROR: Module has dependents: %d\n", modp->dependents); - ret = -EBUSY; - goto errout_with_lock; + return -EBUSY; } #endif @@ -102,7 +78,7 @@ int modlib_remove(FAR void *handle) if (ret < 0) { berr("ERROR: Failed to uninitialize the module: %d\n", ret); - goto errout_with_lock; + return ret; } modlib_freesymtab(modp); @@ -183,6 +159,57 @@ int modlib_remove(FAR void *handle) #endif } +#if CONFIG_MODLIB_MAXDEPEND > 0 + /* Eliminate any dependencies that this module has on other modules */ + + modlib_undepend(modp); +#endif + + return ret; +} + +/**************************************************************************** + * Name: modlib_remove + * + * Description: + * Remove a previously installed module from memory. + * + * Input Parameters: + * handle - The module handler previously returned by modlib_insert(). + * + * Returned Value: + * Zero (OK) on success. On any failure, -1 (ERROR) is returned the + * errno value is set appropriately. + * + ****************************************************************************/ + +int modlib_remove(FAR void *handle) +{ + FAR struct module_s *modp = (FAR struct module_s *)handle; + int ret; + + DEBUGASSERT(modp != NULL); + + /* Get exclusive access to the module registry */ + + modlib_registry_lock(); + + /* Verify that the module is in the registry */ + + ret = modlib_registry_verify(modp); + if (ret < 0) + { + berr("ERROR: Failed to verify module: %d\n", ret); + goto errout_with_lock; + } + + ret = modlib_uninit(modp); + if (ret < 0) + { + berr("ERROR: Failed to uninitialize module %d\n", ret); + goto errout_with_lock; + } + /* Remove the module from the registry */ ret = modlib_registry_del(modp); @@ -193,17 +220,11 @@ int modlib_remove(FAR void *handle) goto errout_with_lock; } -#if CONFIG_MODLIB_MAXDEPEND > 0 - /* Eliminate any dependencies that this module has on other modules */ - - modlib_undepend(modp); -#endif modlib_registry_unlock(); /* And free the registry entry */ - lib_free(modp); - return OK; + return ret; errout_with_lock: modlib_registry_unlock();