From patchwork Wed Oct 24 11:58:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 12459 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id C010823FB8 for ; Wed, 24 Oct 2012 11:59:15 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 67ACDA18788 for ; Wed, 24 Oct 2012 11:59:15 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so480011iej.11 for ; Wed, 24 Oct 2012 04:59:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=znmQu1xm4Ygpf3X88YQny8tx1Cb1UMeroVwqDUAGpBE=; b=XSwP1G/iHr8NUoBZyv2oZTYJuhjndJosru1QH53f83+WTOg/+/eSNJDgb9rKIRLuNi 74RTfY87RWHd0bJAwAQlvz7H358/pmbzfN2OvGfo9xaHa4svsjzeoIaO5iL8tAZCcUhY TxgJ5t2rcwLNuThi2GMAdmnzZmrzzwWGUZSSi1GXujDH5bu7Tc+d008ie1A+122rM6jG 2L8KJXGSG1JKC7s7mZDem4QXGkVvx9+yVX/86n5wQu9VnVALhPi6wd5OvOlpYrWHOLTj xNDHxEIHNezkPdbovk/7u4469LgpDLK2kdasLsa8GnVwWFmxm6tWN4KMIW1yNntyHe3e Mgew== Received: by 10.50.46.226 with SMTP id y2mr2013444igm.62.1351079955144; Wed, 24 Oct 2012 04:59:15 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp601510igt; Wed, 24 Oct 2012 04:59:14 -0700 (PDT) Received: by 10.68.201.6 with SMTP id jw6mr48820351pbc.149.1351079954641; Wed, 24 Oct 2012 04:59:14 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id vy7si21432314pbc.336.2012.10.24.04.59.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Oct 2012 04:59:14 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of hongbo.zhang@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of hongbo.zhang@linaro.org) smtp.mail=hongbo.zhang@linaro.org Received: by mail-pb0-f50.google.com with SMTP id md4so1275239pbc.37 for ; Wed, 24 Oct 2012 04:59:14 -0700 (PDT) Received: by 10.66.84.131 with SMTP id z3mr43463766pay.34.1351079954418; Wed, 24 Oct 2012 04:59:14 -0700 (PDT) Received: from stebjsxu0148.bjs.st.com ([124.127.135.94]) by mx.google.com with ESMTPS id nm2sm9357200pbc.43.2012.10.24.04.59.08 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Oct 2012 04:59:13 -0700 (PDT) From: "hongbo.zhang" To: linaro-dev@lists.linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, STEricsson_nomadik_linux@list.st.com, kernel@igloocommunity.org, "hongbo.zhang" Subject: [PATCH V2 3/6] Thermal: fix bug of counting cpu frequencies. Date: Wed, 24 Oct 2012 19:58:17 +0800 Message-Id: <1351079900-32236-4-git-send-email-hongbo.zhang@linaro.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1351079900-32236-1-git-send-email-hongbo.zhang@linaro.com> References: <1350387889-15324-1-git-send-email-hongbo.zhang@linaro.com> <1351079900-32236-1-git-send-email-hongbo.zhang@linaro.com> X-Gm-Message-State: ALoCoQmynJuJY6fsNb1sHhAzpWig5C+XL94e1fuJT31PtQjXwCYS0d8YBEJmTpd62d/4g0d+IJ/y From: "hongbo.zhang" In the while loop for counting cpu frequencies, if table[i].frequency equals CPUFREQ_ENTRY_INVALID, index i won't be increased, so this leads to an endless loop, what's more the index i cannot be referred as cpu frequencies number if there is CPUFREQ_ENTRY_INVALID case. Signed-off-by: hongbo.zhang Reviewed-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 7519a0b..415b041 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -245,6 +245,7 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, struct cpumask *maskPtr; unsigned int cpu; struct cpufreq_frequency_table *table; + unsigned long count = 0; mutex_lock(&cooling_cpufreq_lock); list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) { @@ -263,13 +264,14 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, goto return_get_max_state; } - 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; - i++; + count++; } - if (i > 0) { - *state = --i; + + if (count > 0) { + *state = --count; ret = 0; }