From patchwork Mon Apr 8 23:54:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Bresticker X-Patchwork-Id: 2412431 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 3F5193FD1A for ; Mon, 8 Apr 2013 23:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936214Ab3DHXyy (ORCPT ); Mon, 8 Apr 2013 19:54:54 -0400 Received: from mail-ia0-f201.google.com ([209.85.210.201]:57033 "EHLO mail-ia0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936172Ab3DHXyx (ORCPT ); Mon, 8 Apr 2013 19:54:53 -0400 Received: by mail-ia0-f201.google.com with SMTP id k25so518518iah.4 for ; Mon, 08 Apr 2013 16:54:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=8ucj+FcA4dbBoDWs1Uf1ArsWqYXB5mxSXUI0si7iDu4=; b=ppfcb4qzAIQoW9JpnfQsoCYdwggDYHRSFM3jkbcD1hQ3e4bbuZ7lfpF5zd+ilYMLlI yJrDzRlHJfDXzDfpjxikgny8t1X969q56tKzFnMcQIWzMmqI0aut/tpbGCWH76tWohKQ 77BsgIdHnuaLXlGYgjlwFHHdgEEMcXh452Kvo0uJEKDZJCJIZuz3+yrepzb1UXnhP4l7 t3T5YdqYgQOoclQYohIMIozgZbDPUDoNGNcAN/ruSW2a/a+q1nmdEROkrt6mYOC9UtB7 8kkeYadLPAYFUIHqZkwRj7VO05U9drdEBhIY3ss29LwSMo9E0MkxZbIgWqohMzAw92II hczg== X-Received: by 10.42.158.1 with SMTP id f1mr17526621icx.6.1365465293058; Mon, 08 Apr 2013 16:54:53 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id dl10si2451317igb.0.2013.04.08.16.54.52 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Mon, 08 Apr 2013 16:54:53 -0700 (PDT) Received: from abrestic01.mtv.corp.google.com (abrestic01.mtv.corp.google.com [172.22.83.3]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 699305A4335; Mon, 8 Apr 2013 16:54:52 -0700 (PDT) Received: by abrestic01.mtv.corp.google.com (Postfix, from userid 137652) id 00A22100A0B; Mon, 8 Apr 2013 16:54:51 -0700 (PDT) From: Andrew Bresticker To: Zhang Rui Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Bresticker Subject: [PATCH] thermal: fix frequency table lookup bugs Date: Mon, 8 Apr 2013 16:54:47 -0700 Message-Id: <1365465287-24530-1-git-send-email-abrestic@chromium.org> X-Mailer: git-send-email 1.8.1.3 X-Gm-Message-State: ALoCoQkLkVjDP3Ol0IyhRVz9PzpQqSOXGLAaBzFkzQnE42C/MUgEHSmMS0VnF4/Kinn723xbeLX2lwsj8CDf5d6RHf2J4jZFgpe/jzP58dYMyaLxTfu4QcSdGnJ65aON4XQUGVRt/Y+yRtmFlvsFgLQFSK7KtXPjbhNt+3fxwr2EhzatucRG2O1nguXpZgvNs9pP7p0NAC7m Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The loops which are used to perform lookups in CPU frequency tables in cpu_cooling and the Exynos thermal driver do not update the loop counter if they encounter an invalid table entry, leading to an infinite loop in that case. Signed-off-by: Andrew Bresticker --- drivers/thermal/cpu_cooling.c | 19 ++++++++++--------- drivers/thermal/exynos_thermal.c | 8 ++++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 836828e..e6db441 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -124,14 +124,14 @@ static int is_cpufreq_valid(int cpu) static unsigned int get_cpu_frequency(unsigned int cpu, unsigned long level) { int ret = 0, i = 0; - unsigned long level_index; + unsigned long level_index = 0; bool descend = false; struct cpufreq_frequency_table *table = cpufreq_frequency_get_table(cpu); 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; @@ -143,24 +143,25 @@ 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) + if (descend && level_index == level) return table[i].frequency; - i++; + level_index++; } i--; + level_index--; - if (level > i || descend) + if (level > level_index || descend) return ret; - level_index = i - level; + level = level_index - 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) + if (level_index == level) return table[i].frequency; - i--; + level_index--; } return ret; } diff --git a/drivers/thermal/exynos_thermal.c b/drivers/thermal/exynos_thermal.c index d5e6267..524b2a0 100644 --- a/drivers/thermal/exynos_thermal.c +++ b/drivers/thermal/exynos_thermal.c @@ -237,7 +237,7 @@ 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, level = 0, ret = -EINVAL; struct cpufreq_frequency_table *table = NULL; #ifdef CONFIG_CPU_FREQ table = cpufreq_frequency_get_table(cpu); @@ -245,12 +245,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 level; + level++; } return ret; }