There is no need to take a lock when nothing is done. Lock after checking whether userspace provides sane data. Signed-off-by: Thomas Renninger <trenn@xxxxxxx> --- drivers/cpufreq/cpufreq_conservative.c | 19 +++++++------------ drivers/cpufreq/cpufreq_ondemand.c | 18 ++++++++---------- 2 files changed, 15 insertions(+), 22 deletions(-) Index: linux-2.6.29-master/drivers/cpufreq/cpufreq_conservative.c =================================================================== --- linux-2.6.29-master.orig/drivers/cpufreq/cpufreq_conservative.c +++ linux-2.6.29-master/drivers/cpufreq/cpufreq_conservative.c @@ -264,13 +264,11 @@ static ssize_t store_up_threshold(struct int ret; ret = sscanf(buf, "%u", &input); - mutex_lock(&dbs_mutex); if (ret != 1 || input > 100 || - input <= dbs_tuners_ins.down_threshold) { - mutex_unlock(&dbs_mutex); + input <= dbs_tuners_ins.down_threshold) return -EINVAL; - } + mutex_lock(&dbs_mutex); dbs_tuners_ins.up_threshold = input; mutex_unlock(&dbs_mutex); @@ -284,14 +282,12 @@ static ssize_t store_down_threshold(stru int ret; ret = sscanf(buf, "%u", &input); - mutex_lock(&dbs_mutex); /* cannot be lower than 11 otherwise freq will not fall */ if (ret != 1 || input < 11 || input > 100 || - input >= dbs_tuners_ins.up_threshold) { - mutex_unlock(&dbs_mutex); + input >= dbs_tuners_ins.up_threshold) return -EINVAL; - } + mutex_lock(&dbs_mutex); dbs_tuners_ins.down_threshold = input; mutex_unlock(&dbs_mutex); @@ -313,11 +309,10 @@ static ssize_t store_ignore_nice_load(st if (input > 1) input = 1; - mutex_lock(&dbs_mutex); - if (input == dbs_tuners_ins.ignore_nice) { /* nothing to do */ - mutex_unlock(&dbs_mutex); + if (input == dbs_tuners_ins.ignore_nice) /* nothing to do */ return count; - } + + mutex_lock(&dbs_mutex); dbs_tuners_ins.ignore_nice = input; /* we need to re-evaluate prev_cpu_idle */ Index: linux-2.6.29-master/drivers/cpufreq/cpufreq_ondemand.c =================================================================== --- linux-2.6.29-master.orig/drivers/cpufreq/cpufreq_ondemand.c +++ linux-2.6.29-master/drivers/cpufreq/cpufreq_ondemand.c @@ -266,11 +266,10 @@ static ssize_t store_sampling_rate(struc int ret; ret = sscanf(buf, "%u", &input); - mutex_lock(&dbs_mutex); - if (ret != 1) { - mutex_unlock(&dbs_mutex); + if (ret != 1) return -EINVAL; - } + + mutex_lock(&dbs_mutex); dbs_tuners_ins.sampling_rate = max(input, minimum_sampling_rate()); mutex_unlock(&dbs_mutex); @@ -284,13 +283,12 @@ static ssize_t store_up_threshold(struct int ret; ret = sscanf(buf, "%u", &input); - mutex_lock(&dbs_mutex); + if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD || - input < MIN_FREQUENCY_UP_THRESHOLD) { - mutex_unlock(&dbs_mutex); + input < MIN_FREQUENCY_UP_THRESHOLD) return -EINVAL; - } + mutex_lock(&dbs_mutex); dbs_tuners_ins.up_threshold = input; mutex_unlock(&dbs_mutex); @@ -312,11 +310,11 @@ static ssize_t store_ignore_nice_load(st if (input > 1) input = 1; - mutex_lock(&dbs_mutex); if (input == dbs_tuners_ins.ignore_nice) { /* nothing to do */ - mutex_unlock(&dbs_mutex); return count; } + + mutex_lock(&dbs_mutex); dbs_tuners_ins.ignore_nice = input; /* we need to re-evaluate prev_cpu_idle */ -- To unsubscribe from this list: send the line "unsubscribe cpufreq" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html