Skip to content

Commit

Permalink
msm: adsprpc: Fix race condition in internal_control
Browse files Browse the repository at this point in the history
Protect add and update qos request with mutex to
avoid race condition when multiple threads try to add
or update request simultaneously.

Change-Id: Id33b81bf85246ec69c72bad59cca068e627bb21d
Acked-by: Deepika Singh <[email protected]>
Signed-off-by: Jeya R <[email protected]>
  • Loading branch information
Jeya R authored and Gerrit - the friendly Code Review server committed Jun 29, 2021
1 parent 43c703c commit 01aa9c5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/char/adsprpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ struct fastrpc_file {
struct mutex perf_mutex;
struct pm_qos_request pm_qos_req;
int qos_request;
struct mutex pm_qos_mutex;
struct mutex map_mutex;
struct mutex internal_map_mutex;
/* Identifies the device (MINOR_NUM_DEV / MINOR_NUM_SECURE_DEV) */
Expand Down Expand Up @@ -3078,6 +3079,7 @@ static int fastrpc_file_free(struct fastrpc_file *fl)
mutex_destroy(&fl->perf_mutex);
mutex_destroy(&fl->map_mutex);
mutex_destroy(&fl->internal_map_mutex);
mutex_destroy(&fl->pm_qos_mutex);
kfree(fl);
return 0;
}
Expand Down Expand Up @@ -3426,6 +3428,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp)
hlist_add_head(&fl->hn, &me->drivers);
spin_unlock(&me->hlock);
mutex_init(&fl->perf_mutex);
mutex_init(&fl->pm_qos_mutex);
return 0;
}

Expand Down Expand Up @@ -3539,12 +3542,14 @@ static int fastrpc_internal_control(struct fastrpc_file *fl,
VERIFY(err, latency != 0);
if (err)
goto bail;
mutex_lock(&fl->pm_qos_mutex);
if (!fl->qos_request) {
pm_qos_add_request(&fl->pm_qos_req,
PM_QOS_CPU_DMA_LATENCY, latency);
fl->qos_request = 1;
} else
pm_qos_update_request(&fl->pm_qos_req, latency);
mutex_unlock(&fl->pm_qos_mutex);
break;
case FASTRPC_CONTROL_KALLOC:
cp->kalloc.kalloc_support = 1;
Expand Down

0 comments on commit 01aa9c5

Please sign in to comment.