From patchwork Tue Apr 9 21:59:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Bresticker X-Patchwork-Id: 2417961 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 265ECDF25A for ; Tue, 9 Apr 2013 21:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934757Ab3DIV7W (ORCPT ); Tue, 9 Apr 2013 17:59:22 -0400 Received: from mail-ob0-f202.google.com ([209.85.214.202]:34865 "EHLO mail-ob0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934324Ab3DIV7V (ORCPT ); Tue, 9 Apr 2013 17:59:21 -0400 Received: by mail-ob0-f202.google.com with SMTP id va7so756022obc.3 for ; Tue, 09 Apr 2013 14:59:21 -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=v7V90ZYAouBt9j0vdfWJHSzW8jyVB+seKX+LHkG4Kw0=; b=TPZq0P+a3GvW54iCXtWgAebof9AE2Hkwe/HZwl3GeFfsDLjGp+KPll0RAFI+NQPC/o Rq5NBeSo8kiUOdQjDvg5zrPFiastT/t6aJsEjb3+AIucHT0JFs/9oOVbPBfcaW9Pby4s Eqk9TwD3tmdstyWrx7HSLBPUaK1u7Xw1RqaSQi+6HPwMmICslRfy0a1n05M+M+f78OsN XwKd+uNfbINN55sYKORrVb2drBEJ5QrlXa4cLBh0xF9EBTC0JTHtPGUK4tyjIXTCiYFD PfWmAZ2F1g8SMrBVZAcYjE5urBx0ni6e1ls0vsCmN5TXHPkf+gnur29cGHLoXEi/gltL dDBw== X-Received: by 10.50.45.168 with SMTP id o8mr13665946igm.5.1365544761038; Tue, 09 Apr 2013 14:59:21 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id j7si2342174igc.3.2013.04.09.14.59.20 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Tue, 09 Apr 2013 14:59:21 -0700 (PDT) Received: from abrestic.mtv.corp.google.com (abrestic.mtv.corp.google.com [172.22.72.111]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 52D9531C15F; Tue, 9 Apr 2013 14:59:20 -0700 (PDT) Received: by abrestic.mtv.corp.google.com (Postfix, from userid 137652) id E009C221471; Tue, 9 Apr 2013 14:59:19 -0700 (PDT) From: Andrew Bresticker To: Zhang Rui , Eduardo Valentin , Kukjin Kim Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Andrew Bresticker Subject: [PATCH] thermal: exynos: fix handling of invalid frequency table entries Date: Tue, 9 Apr 2013 14:59:18 -0700 Message-Id: <1365544758-15245-1-git-send-email-abrestic@chromium.org> X-Mailer: git-send-email 1.8.1.3 X-Gm-Message-State: ALoCoQnOKENtRrMWbu7MaTeKjZ3LXMSeNHQCsJuBrNMwgz/r28G7Em1drNMNshQgNR8zoNVTTH5MB61QkdLLcOKaFR8YuN5cBjGqO7AEv2ztGKlOWqxv2Z0Yp6FFY0k8dejmrm4K6+rCjYjGxwnJxYVyBAejNa7JjUrxVEgFJ1ZCqczQVOth3c5TtuBpawkVY9CViq6Z26RT Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Similar to the error described in "thermal: cpu_cooling: fix handling of invalid frequency table entries," exynos_get_frequency_level() will enter an infinite loop if any CPU frequency table entries are invalid. This patch fixes the handling of invalid frequency entries so that there is no infinite loop and the correct level is returned. Signed-off-by: Andrew Bresticker --- drivers/thermal/exynos_thermal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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; }