diff --git a/dsp/adsprpc.c b/dsp/adsprpc.c index 231764498c..0c98bd18b2 100644 --- a/dsp/adsprpc.c +++ b/dsp/adsprpc.c @@ -1049,6 +1049,12 @@ static inline bool fastrpc_get_persistent_map(size_t len, struct fastrpc_mmap ** map->is_persistent && !map->in_use) { *pers_map = map; map->in_use = true; + /* + * Incrementing map reference count when getting + * the map to avoid negative reference count when + * freeing the map. + */ + map->refs++; found = true; break; } @@ -4741,6 +4747,11 @@ static int fastrpc_mmap_remove_ssr(struct fastrpc_file *fl, int locked) } spin_lock_irqsave(&me->hlock, irq_flags); map->in_use = false; + /* + * decrementing refcount for persistent mappings + * as incrementing it in fastrpc_get_persistent_map + */ + map->refs--; } if (map->is_persistent) { match = NULL;