From: Matthew Wilcox Date: Mon, 18 Feb 2019 22:36:36 +0000 (-0500) Subject: bcm2835-camera: Convert context_map to XArray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=8672bbe52f39c6ad6cf841f8e5ad1bac2da88d5a;p=users%2Fwilly%2Fxarray.git bcm2835-camera: Convert context_map to XArray Signed-off-by: Matthew Wilcox --- diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c index 1c180ead4a20..e074b39ca8e7 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c @@ -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;