]> www.infradead.org Git - users/willy/xarray.git/commitdiff
optee: Convert supp to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 22:43:00 +0000 (17:43 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:18 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/tee/optee/optee_private.h
drivers/tee/optee/supp.c

index d9c5037b4e03e9175861ad1c6049699c38f1f547..c16a17953108fda98b8b6c1185407ed41a18724d 100644 (file)
@@ -49,8 +49,7 @@ struct optee_wait_queue {
  * @req_id:            current request id if supplicant is doing synchronous
  *                     communication, else -1
  * @reqs:              queued request not yet retrieved by supplicant
- * @idr:               IDR holding all requests currently being processed
- *                     by supplicant
+ * @requests:          All requests currently being processed by supplicant
  * @reqs_c:            completion used by supplicant when waiting for a
  *                     request to be queued.
  */
@@ -61,7 +60,7 @@ struct optee_supp {
 
        int req_id;
        struct list_head reqs;
-       struct idr idr;
+       struct xarray requests;
        struct completion reqs_c;
 };
 
index 322a543b8c278abbb493724b7c717690fbeed972..b75894dc97fdf0ea37ab87ba1142fa73d18ae4db 100644 (file)
@@ -24,7 +24,7 @@ void optee_supp_init(struct optee_supp *supp)
        memset(supp, 0, sizeof(*supp));
        mutex_init(&supp->mutex);
        init_completion(&supp->reqs_c);
-       idr_init(&supp->idr);
+       xa_init_flags(&supp->requests, XA_FLAGS_ALLOC1);
        INIT_LIST_HEAD(&supp->reqs);
        supp->req_id = -1;
 }
@@ -32,20 +32,19 @@ void optee_supp_init(struct optee_supp *supp)
 void optee_supp_uninit(struct optee_supp *supp)
 {
        mutex_destroy(&supp->mutex);
-       idr_destroy(&supp->idr);
 }
 
 void optee_supp_release(struct optee_supp *supp)
 {
-       int id;
+       unsigned long id;
        struct optee_supp_req *req;
        struct optee_supp_req *req_tmp;
 
        mutex_lock(&supp->mutex);
 
        /* Abort all request retrieved by supplicant */
-       idr_for_each_entry(&supp->idr, req, id) {
-               idr_remove(&supp->idr, id);
+       xa_for_each(&supp->requests, id, req) {
+               xa_erase(&supp->requests, id);
                req->ret = TEEC_ERROR_COMMUNICATION;
                complete(&req->c);
        }
@@ -153,6 +152,7 @@ static struct optee_supp_req  *supp_pop_entry(struct optee_supp *supp,
                                              int num_params, int *id)
 {
        struct optee_supp_req *req;
+       int ret;
 
        if (supp->req_id != -1) {
                /*
@@ -172,8 +172,8 @@ static struct optee_supp_req  *supp_pop_entry(struct optee_supp *supp,
                return ERR_PTR(-EINVAL);
        }
 
-       *id = idr_alloc(&supp->idr, req, 1, 0, GFP_KERNEL);
-       if (*id < 0)
+       ret = xa_alloc(&supp->requests, id, req, xa_limit_31b, GFP_KERNEL);
+       if (ret < 0)
                return ERR_PTR(-ENOMEM);
 
        list_del(&req->link);
@@ -312,14 +312,14 @@ static struct optee_supp_req *supp_pop_req(struct optee_supp *supp,
                nm = 0;
        }
 
-       req = idr_find(&supp->idr, id);
+       req = xa_load(&supp->requests, id);
        if (!req)
                return ERR_PTR(-ENOENT);
 
        if ((num_params - nm) != req->num_params)
                return ERR_PTR(-EINVAL);
 
-       idr_remove(&supp->idr, id);
+       xa_erase(&supp->requests, id);
        supp->req_id = -1;
        *num_meta = nm;