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 d258cdb279f16f2e73888c4fa348fc84506b28b2 Author: hujun5 <[email protected]> AuthorDate: Mon Jan 12 16:15:23 2026 +0800 idr: Support pointer-to-pointer mapping Extend the IDR interface to support pointer-to-pointer mappings required by the OP-TEE changes and update affected users. Signed-off-by: hujun5 <[email protected]> --- drivers/misc/optee.c | 14 ++++++--- drivers/misc/optee_supplicant.c | 9 +++--- fs/v9fs/client.c | 5 +-- include/nuttx/idr.h | 14 ++++----- libs/libc/misc/lib_idr.c | 67 ++++++++++++++++++++--------------------- 5 files changed, 56 insertions(+), 53 deletions(-) diff --git a/drivers/misc/optee.c b/drivers/misc/optee.c index 6150bbc8fea..323415d91cc 100644 --- a/drivers/misc/optee.c +++ b/drivers/misc/optee.c @@ -621,7 +621,7 @@ static int optee_close(FAR struct file *filep) { FAR struct optee_priv_data *priv = filep->f_priv; FAR struct optee_shm *shm; - int id = 0; + unsigned long id = 0; idr_for_each_entry(priv->shms, shm, id) { @@ -1016,6 +1016,7 @@ optee_shm_register_supplicant(FAR struct optee_priv_data *priv, { FAR struct optee_shm *shm; uintptr_t page_list_pa = 0; + unsigned long id; int ret = 0; shm = kmm_zalloc(sizeof(struct optee_shm)); @@ -1032,15 +1033,16 @@ optee_shm_register_supplicant(FAR struct optee_priv_data *priv, shm->flags = TEE_SHM_REGISTER | TEE_SHM_SUPP; shm->page_list = optee_shm_to_page_list(shm, &page_list_pa); shm->paddr = page_list_pa; - shm->id = idr_alloc(priv->shms, shm, 0, 0); + ret = idr_alloc(priv->shms, shm, 0, 0, &id); - if (shm->id < 0) + if (ret < 0) { kmm_free(shm->page_list); kmm_free(shm); return -ENOMEM; } + shm->id = id; return ret; } #endif @@ -1432,6 +1434,7 @@ int optee_shm_alloc(FAR struct optee_priv_data *priv, FAR void *addr, FAR struct optee_shm **shmp) { FAR struct optee_shm *shm; + unsigned long id; FAR void *ptr; int ret = -ENOMEM; @@ -1468,13 +1471,14 @@ int optee_shm_alloc(FAR struct optee_priv_data *priv, FAR void *addr, shm->paddr = shm->vaddr ? optee_va_to_pa((FAR void *)shm->vaddr) : 0; shm->length = size; shm->flags = flags; - shm->id = idr_alloc(priv->shms, shm, 0, 0); + ret = idr_alloc(priv->shms, shm, 0, 0, &id); - if (shm->id < 0) + if (ret < 0) { goto err; } + shm->id = id; if (flags & TEE_SHM_REGISTER) { ret = optee_shm_register(priv, shm); diff --git a/drivers/misc/optee_supplicant.c b/drivers/misc/optee_supplicant.c index 7296e88cc15..3537db6e289 100644 --- a/drivers/misc/optee_supplicant.c +++ b/drivers/misc/optee_supplicant.c @@ -87,9 +87,10 @@ static struct optee_supplicant g_optee_supp; ****************************************************************************/ static FAR struct optee_supplicant_req *pop_entry(uint32_t num_params, - FAR int *id) + FAR unsigned long *id) { FAR struct optee_supplicant_req *req; + int ret; if (g_optee_supp.req_id != -1) { @@ -112,8 +113,8 @@ static FAR struct optee_supplicant_req *pop_entry(uint32_t num_params, return NULL; } - *id = idr_alloc(g_optee_supp.idr, req, 0, INT32_MAX); - if (*id < 0) + ret = idr_alloc(g_optee_supp.idr, req, 0, 0, id); + if (ret < 0) { return NULL; } @@ -261,7 +262,7 @@ int optee_supplicant_recv(FAR uint32_t *func, FAR uint32_t *num_params, FAR struct tee_ioctl_param *params) { FAR struct optee_supplicant_req *req = NULL; - int id; + unsigned long id; int n; uint8_t num_meta = (params->attr == TEE_IOCTL_PARAM_ATTR_META); diff --git a/fs/v9fs/client.c b/fs/v9fs/client.c index 290c8f1f949..ec375216a7c 100644 --- a/fs/v9fs/client.c +++ b/fs/v9fs/client.c @@ -558,6 +558,7 @@ static int v9fs_fid_create(FAR struct v9fs_client_s *client, FAR const char *relpath) { FAR struct v9fs_fid_s *fid; + unsigned long id; size_t len; int ret; @@ -570,12 +571,12 @@ static int v9fs_fid_create(FAR struct v9fs_client_s *client, fid->refcount = 1; nxmutex_lock(&client->lock); - ret = idr_alloc(client->fids, fid, 0, 0); + ret = idr_alloc(client->fids, fid, 0, INT_MAX, &id); nxmutex_unlock(&client->lock); if (ret >= 0) { memcpy(fid->relpath, relpath, len + 1); - return ret; + return (int)id; } /* Failed to initialize fid */ diff --git a/include/nuttx/idr.h b/include/nuttx/idr.h index 0309bde1e84..9c81d623908 100644 --- a/include/nuttx/idr.h +++ b/include/nuttx/idr.h @@ -42,13 +42,13 @@ struct idr_s; * Public Function Prototypes ****************************************************************************/ -FAR void *idr_find(FAR struct idr_s *idr, unsigned int id); -FAR void *idr_get_next(FAR struct idr_s *idr, FAR int *id); -FAR struct idr_s *idr_init_base(int base); +FAR void *idr_find(FAR struct idr_s *idr, unsigned long id); +FAR void *idr_get_next(FAR struct idr_s *idr, FAR unsigned long *id); +FAR struct idr_s *idr_init_base(unsigned long base); void idr_destroy(FAR struct idr_s *idr); -int idr_alloc_u32(FAR struct idr_s *idr, FAR void *ptr, FAR uint32_t *result, - uint32_t max); -int idr_alloc(FAR struct idr_s *idr, FAR void *ptr, int start, int end); -FAR void *idr_remove(FAR struct idr_s *idr, unsigned int id); +int idr_alloc(FAR struct idr_s *idr, FAR void *ptr, + unsigned long start, + unsigned long end, unsigned long *id); +FAR void *idr_remove(FAR struct idr_s *idr, unsigned long id); #endif diff --git a/libs/libc/misc/lib_idr.c b/libs/libc/misc/lib_idr.c index 275176243d8..f7a890572ce 100644 --- a/libs/libc/misc/lib_idr.c +++ b/libs/libc/misc/lib_idr.c @@ -37,15 +37,15 @@ RB_HEAD(idr_tree_s, idr_node_s); struct idr_node_s { RB_ENTRY(idr_node_s) link; - unsigned int id; + unsigned long id; FAR void *data; }; struct idr_s { mutex_t lock; - unsigned int lastid; - unsigned int base; + unsigned long lastid; + unsigned long base; struct idr_tree_s alloced; struct idr_tree_s removed; }; @@ -63,14 +63,24 @@ static int idr_compare(FAR struct idr_node_s *node, { /* When node < root, it should be placed on the left side of the tree */ - return node->id - root->id; + if (node->id == root->id) + { + return 0; + } + else if(node->id < root->id) + { + return -1; + } + + return 1; } /**************************************************************************** * Name: idr_create_node ****************************************************************************/ -FAR static struct idr_node_s *idr_create_node(FAR void *ptr, unsigned int id) +FAR static +struct idr_node_s *idr_create_node(FAR void *ptr, unsigned long id) { FAR struct idr_node_s *node; @@ -99,7 +109,7 @@ RB_GENERATE_STATIC(idr_tree_s, idr_node_s, link, idr_compare) * Name: idr_find ****************************************************************************/ -FAR void *idr_find(FAR struct idr_s *idr, unsigned int id) +FAR void *idr_find(FAR struct idr_s *idr, unsigned long id) { FAR struct idr_node_s *node; struct idr_node_s search; @@ -121,7 +131,7 @@ FAR void *idr_find(FAR struct idr_s *idr, unsigned int id) * Name: idr_get_next ****************************************************************************/ -FAR void *idr_get_next(FAR struct idr_s *idr, FAR int *id) +FAR void *idr_get_next(FAR struct idr_s *idr, FAR unsigned long *id) { FAR struct idr_node_s *node; struct idr_node_s search; @@ -146,7 +156,7 @@ FAR void *idr_get_next(FAR struct idr_s *idr, FAR int *id) * Name: idr_remove ****************************************************************************/ -FAR void *idr_remove(FAR struct idr_s *idr, unsigned int id) +FAR void *idr_remove(FAR struct idr_s *idr, unsigned long id) { FAR struct idr_node_s *node; struct idr_node_s search; @@ -178,16 +188,26 @@ FAR void *idr_remove(FAR struct idr_s *idr, unsigned int id) } /**************************************************************************** - * Name: idr_alloc_u32 + * Name: idr_alloc ****************************************************************************/ -int idr_alloc_u32(FAR struct idr_s *idr, FAR void *ptr, FAR uint32_t *result, - uint32_t max) +int idr_alloc(FAR struct idr_s *idr, FAR void *ptr, + unsigned long start, + unsigned long end, unsigned long *result) { FAR struct idr_node_s *node; FAR struct idr_node_s *temp; struct idr_node_s search; + unsigned long max; + + *result = start; + if (end < start) + { + return -EINVAL; + } + + max = end > 0 ? end - 1 : ULONG_MAX; nxmutex_lock(&idr->lock); /* Check ID Value */ @@ -271,34 +291,11 @@ out: return OK; } -/**************************************************************************** - * Name: idr_alloc - ****************************************************************************/ - -int idr_alloc(FAR struct idr_s *idr, FAR void *ptr, int start, int end) -{ - uint32_t id = start; - int ret; - - if (start < 0) - { - return -EINVAL; - } - - ret = idr_alloc_u32(idr, ptr, &id, end > 0 ? end - 1 : INT32_MAX); - if (ret < 0) - { - return ret; - } - - return id; -} - /**************************************************************************** * Name: idr_init_base ****************************************************************************/ -FAR struct idr_s *idr_init_base(int base) +FAR struct idr_s *idr_init_base(unsigned long base) { FAR struct idr_s *idr;
