Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2cf172e authored by Ram Chandrasekar's avatar Ram Chandrasekar Committed by Gerrit - the friendly Code Review server
Browse files

msm: thermal-dev: Protect IOCTL from race condition



There is a possibility that the thermal ioctl interface can be accessed
simultaneously in a multi-threaded environment. In those cases the
calls to fetch the frequency and voltage table can result in an
undefined behavior due to race condition.

Use mutex to protect the IOCTL interface from multi-thread access race
condition.

Change-Id: I325695f38753a4d4bc732987cf514e8616273aca
Signed-off-by: default avatarRam Chandrasekar <rkumbako@codeaurora.org>
parent 8d0bafc0
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * it under the terms of the GNU General Public License version 2 and
@@ -35,6 +35,7 @@ static unsigned int freq_table_len[NR_CPUS], freq_table_set[NR_CPUS];
static unsigned int voltage_table_set[NR_CPUS];
static unsigned int voltage_table_set[NR_CPUS];
static unsigned int *freq_table_ptr[NR_CPUS];
static unsigned int *freq_table_ptr[NR_CPUS];
static uint32_t *voltage_table_ptr[NR_CPUS];
static uint32_t *voltage_table_ptr[NR_CPUS];
static DEFINE_MUTEX(ioctl_access_mutex);


static int msm_thermal_ioctl_open(struct inode *node, struct file *filep)
static int msm_thermal_ioctl_open(struct inode *node, struct file *filep)
{
{
@@ -291,8 +292,9 @@ static long msm_thermal_ioctl_process(struct file *filep, unsigned int cmd,


	ret = validate_and_copy(&cmd, &arg, &query);
	ret = validate_and_copy(&cmd, &arg, &query);
	if (ret)
	if (ret)
		goto process_exit;
		return ret;


	mutex_lock(&ioctl_access_mutex);
	switch (cmd) {
	switch (cmd) {
	case MSM_THERMAL_SET_CPU_MAX_FREQUENCY:
	case MSM_THERMAL_SET_CPU_MAX_FREQUENCY:
		ret = msm_thermal_set_frequency(query.cpu_freq.cpu_num,
		ret = msm_thermal_set_frequency(query.cpu_freq.cpu_num,
@@ -321,6 +323,7 @@ static long msm_thermal_ioctl_process(struct file *filep, unsigned int cmd,
		goto process_exit;
		goto process_exit;
	}
	}
process_exit:
process_exit:
	mutex_unlock(&ioctl_access_mutex);
	return ret;
	return ret;
}
}