From patchwork Thu Jan 24 15:24:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu1 X-Patchwork-Id: 2032681 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 7311EDF264 for ; Thu, 24 Jan 2013 15:35:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753181Ab3AXPfA (ORCPT ); Thu, 24 Jan 2013 10:35:00 -0500 Received: from mail-wi0-f173.google.com ([209.85.212.173]:41490 "EHLO mail-wi0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751207Ab3AXPe7 (ORCPT ); Thu, 24 Jan 2013 10:34:59 -0500 Received: by mail-wi0-f173.google.com with SMTP id hn17so552702wib.6 for ; Thu, 24 Jan 2013 07:34:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer; bh=SlSjy1P5EqmE/A1mCC1zisjb3i+VLfbRFsonhRWsbXs=; b=M5GDmO1B9P6L2AppzFnJeb8yItqTZLFzd+kpCjEiyzNyUHAdKk3FIXu/Jlm86+s+8I 2yu3jRSvTcodmUj4LHOc8pJv6gNdMHvdTxK+db7puGVOD2VjSbvznpJ3gKv9ZbDda2ik 9WX9o9d9wXHC9k+KZboxjT/7aQ+UuUPccHZfWKyf8jzPsRjhIu8/Y2jSi56oakMx4AZK mtHwTenwVXAhPWdoDnmC5FW0IWFeMwWPktliJfc4/CRVrrXEgqZDM41eF1rjIMasu4CK ztFPTq7NvBXqNH2k2cYQqF3iehXdcgfa7j/zSlPrJ5sN+PEc7xnZZP7RaUBKgZBp/DzO Z3ww== X-Received: by 10.194.76.165 with SMTP id l5mr3873400wjw.14.1359041300160; Thu, 24 Jan 2013 07:28:20 -0800 (PST) Received: from Axagore.lan (ip-239.net-81-220-145.rev.numericable.fr. [81.220.145.239]) by mx.google.com with ESMTPS id bw9sm2768460wib.5.2013.01.24.07.28.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Jan 2013 07:28:19 -0800 (PST) From: Gu1 To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Amit Daniel Kachhap Cc: Gu1 Subject: [PATCH] Thermal: fix iteration over CPU frequency list Date: Thu, 24 Jan 2013 16:24:05 +0100 Message-Id: <1359041045-24341-1-git-send-email-gu1@aeroxteam.fr> X-Mailer: git-send-email 1.8.1.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In different places in the Thermal code, the CPU frequency list is iterated in an incorrect way, leading to endless loops when the frequency list contains a CPUFREQ_TABLE_INVALID entry, which is the case by default in the the Exynos 4x12 cpufreq driver, for example. The frequency list is iterated with a while loop, and when a CPUFREQ_TABLE_INVALID entry is encountered, the continue; statement is used to skip it, but the index is not incremented, causing an endless loop. A similar bug was fixed by hongbo.zhang in commit: Thermal: fix bug of counting cpu frequencies Signed-off-by: Gu1 Reviewed-by: Amit Daniel Kachhap --- drivers/thermal/cpu_cooling.c | 8 +++----- drivers/thermal/exynos_thermal.c | 9 +++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 836828e..51acd26 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -123,7 +123,7 @@ static int is_cpufreq_valid(int cpu) */ static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level) { - int ret = 0, i = 0; + int ret = 0, i; unsigned long level_index; bool descend = false; struct cpufreq_frequency_table *table = @@ -131,7 +131,7 @@ static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level) if (!table) return ret; - while (table[i].frequency != CPUFREQ_TABLE_END) { + for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { if (table[i].frequency == CPUFREQ_ENTRY_INVALID) continue; @@ -145,7 +145,6 @@ static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level) /*return if level matched and table in descending order*/ if (descend && i == level) return table[i].frequency; - i++; } i--; @@ -154,13 +153,12 @@ static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level) level_index = i - level; /*Scan the table in reverse order and match the level*/ - while (i >= 0) { + for (; i >= 0; i--) { if (table[i].frequency == CPUFREQ_ENTRY_INVALID) continue; /*return if level matched*/ if (i == level_index) return table[i].frequency; - i--; } return ret; } diff --git a/drivers/thermal/exynos_thermal.c b/drivers/thermal/exynos_thermal.c index 224751e..fa9e1d7 100644 --- a/drivers/thermal/exynos_thermal.c +++ b/drivers/thermal/exynos_thermal.c @@ -233,7 +233,8 @@ static int exynos_get_crit_temp(struct thermal_zone_device *thermal, static int exynos_get_frequency_level(unsigned int cpu, unsigned int freq) { - int i = 0, ret = -EINVAL; + int i, ret = -EINVAL; + unsigned int count = 0; struct cpufreq_frequency_table *table = NULL; #ifdef CONFIG_CPU_FREQ table = cpufreq_frequency_get_table(cpu); @@ -241,12 +242,12 @@ static int exynos_get_frequency_level(unsigned int cpu, unsigned int freq) if (!table) return ret; - while (table[i].frequency != CPUFREQ_TABLE_END) { + for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { if (table[i].frequency == CPUFREQ_ENTRY_INVALID) continue; if (table[i].frequency == freq) - return i; - i++; + return count; + count++; } return ret; }