]> www.infradead.org Git - users/willy/xarray.git/commitdiff
bcm2835-camera: Convert context_map to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 22:36:36 +0000 (17:36 -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/staging/vc04_services/bcm2835-camera/mmal-vchiq.c

index 1c180ead4a20b58416f765ad811d425d2c32e94d..e074b39ca8e753c9102e022866d40a4aab4c7f6a 100644 (file)
@@ -111,7 +111,7 @@ struct vchiq_mmal_instance;
 struct mmal_msg_context {
        struct vchiq_mmal_instance *instance;
 
-       /* Index in the context_map idr so that we can find the
+       /* Index in the context_map so that we can find the
         * mmal_msg_context again when servicing the VCHI reply.
         */
        int handle;
@@ -163,9 +163,7 @@ struct vchiq_mmal_instance {
        /* vmalloc page to receive scratch bulk xfers into */
        void *bulk_scratch;
 
-       struct idr context_map;
-       /* protect accesses to context_map */
-       struct mutex context_map_lock;
+       struct xarray context_map;
 
        /* component to use next */
        int component_idx;
@@ -179,7 +177,7 @@ static struct mmal_msg_context *
 get_msg_context(struct vchiq_mmal_instance *instance)
 {
        struct mmal_msg_context *msg_context;
-       int handle;
+       int err;
 
        /* todo: should this be allocated from a pool to avoid kzalloc */
        msg_context = kzalloc(sizeof(*msg_context), GFP_KERNEL);
@@ -187,30 +185,27 @@ get_msg_context(struct vchiq_mmal_instance *instance)
        if (!msg_context)
                return ERR_PTR(-ENOMEM);
 
-       /* Create an ID that will be passed along with our message so
+       msg_context->instance = instance;
+
+       /*
+        * Create an ID that will be passed along with our message so
         * that when we service the VCHI reply, we can look up what
         * message is being replied to.
         */
-       mutex_lock(&instance->context_map_lock);
-       handle = idr_alloc(&instance->context_map, msg_context,
-                          0, 0, GFP_KERNEL);
-       mutex_unlock(&instance->context_map_lock);
-
-       if (handle < 0) {
+       err = xa_alloc(&instance->context_map, &msg_context->handle,
+                       msg_context, xa_limit_32b, GFP_KERNEL);
+       if (err < 0) {
                kfree(msg_context);
-               return ERR_PTR(handle);
+               return ERR_PTR(err);
        }
 
-       msg_context->instance = instance;
-       msg_context->handle = handle;
-
        return msg_context;
 }
 
 static struct mmal_msg_context *
 lookup_msg_context(struct vchiq_mmal_instance *instance, int handle)
 {
-       return idr_find(&instance->context_map, handle);
+       return xa_load(&instance->context_map, handle);
 }
 
 static void
@@ -218,9 +213,7 @@ release_msg_context(struct mmal_msg_context *msg_context)
 {
        struct vchiq_mmal_instance *instance = msg_context->instance;
 
-       mutex_lock(&instance->context_map_lock);
-       idr_remove(&instance->context_map, msg_context->handle);
-       mutex_unlock(&instance->context_map_lock);
+       xa_erase(&instance->context_map, msg_context->handle);
        kfree(msg_context);
 }
 
@@ -1803,8 +1796,6 @@ int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
 
        vfree(instance->bulk_scratch);
 
-       idr_destroy(&instance->context_map);
-
        kfree(instance);
 
        return status;
@@ -1858,8 +1849,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
 
        instance->bulk_scratch = vmalloc(PAGE_SIZE);
 
-       mutex_init(&instance->context_map_lock);
-       idr_init_base(&instance->context_map, 1);
+       xa_init_flags(&instance->context_map, XA_FLAGS_ALLOC1);
 
        params.callback_param = instance;