From 6554e75e39e9b34f8d32b9374f9cda9025c4dfc2 Mon Sep 17 00:00:00 2001 From: Himateja Reddy Date: Fri, 3 Feb 2023 07:55:44 -0800 Subject: [PATCH] msm: ADSPRPC: Prevent mapping refcount for persistent mapping from going bad Mapping refcount goes to negative value when internal invoke fails. This prevents in hyp assigning the memory back to dsp. Change-Id: I3b0f4a80e8fd1cde43e5b6fe94030258eb01ead1 Acked-by: Abhinav Parihar Signed-off-by: Vamsi Krishna Gattupalli Signed-off-by: Himateja Reddy --- dsp/adsprpc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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;