Skip to content

Commit

Permalink
staging: mmal-vchiq: Replace spinlock protecting context_map with mutex
Browse files Browse the repository at this point in the history
950fd86 staging: bcm2835-camera: Replace open-coded idr with a struct idr.
replaced an internal implementation of an idr with the standard functions
and a spinlock.
idr_alloc(GFP_KERNEL) can sleep whilst calling kmem_cache_alloc to allocate
the new node, but this is not valid whilst in an atomic context due to the
spinlock.

There is no need for this to be a spinlock as a standard mutex is
sufficient.

Signed-off-by: Dave Stevenson <[email protected]>
  • Loading branch information
6by9 authored and popcornmix committed May 21, 2019
1 parent e2dccdc commit b2e514a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ struct vchiq_mmal_instance {
void *bulk_scratch;

struct idr context_map;
spinlock_t context_map_lock;
/* protect accesses to context_map */
struct mutex context_map_lock;

/* component to use next */
int component_idx;
Expand All @@ -184,10 +185,10 @@ get_msg_context(struct vchiq_mmal_instance *instance)
* that when we service the VCHI reply, we can look up what
* message is being replied to.
*/
spin_lock(&instance->context_map_lock);
mutex_lock(&instance->context_map_lock);
handle = idr_alloc(&instance->context_map, msg_context,
0, 0, GFP_KERNEL);
spin_unlock(&instance->context_map_lock);
mutex_unlock(&instance->context_map_lock);

if (handle < 0) {
kfree(msg_context);
Expand All @@ -211,9 +212,9 @@ release_msg_context(struct mmal_msg_context *msg_context)
{
struct vchiq_mmal_instance *instance = msg_context->instance;

spin_lock(&instance->context_map_lock);
mutex_lock(&instance->context_map_lock);
idr_remove(&instance->context_map, msg_context->handle);
spin_unlock(&instance->context_map_lock);
mutex_unlock(&instance->context_map_lock);
kfree(msg_context);
}

Expand Down Expand Up @@ -1849,7 +1850,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)

instance->bulk_scratch = vmalloc(PAGE_SIZE);

spin_lock_init(&instance->context_map_lock);
mutex_init(&instance->context_map_lock);
idr_init_base(&instance->context_map, 1);

params.callback_param = instance;
Expand Down

0 comments on commit b2e514a

Please sign in to comment.