From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32116C433FB for ; Mon, 20 Jul 2020 16:05:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1649206E9 for ; Mon, 20 Jul 2020 16:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595261130; bh=jJTY4CpwJBiOsJxX+eJrLO3bhqUPTbK7A8zPNtjrGbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=P1LW6ud6CY7znJAYk/vxfUUwCaXkPkc7/0DPpet3DueGsOI1ToBsVWmOs4GFr89HV Y242dBhL1iflU8tpA8Bu4KtYR8WOhCez/RvrbkDMVvSbslyEMcBDNlcwjIKxSu9bh5 8lD2Kpjbwz+rV1rnNO54HUyvgEvWSfQj0tLHmdlw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732983AbgGTQF3 (ORCPT ); Mon, 20 Jul 2020 12:05:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:40786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732966AbgGTQFV (ORCPT ); Mon, 20 Jul 2020 12:05:21 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 51DCA2064B; Mon, 20 Jul 2020 16:05:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595261120; bh=jJTY4CpwJBiOsJxX+eJrLO3bhqUPTbK7A8zPNtjrGbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LIyjtARgfgDUrv3+kw/O91V5Cu/Di17KbQdlbTpehHdOf8SwK+r8jTweYZ8QF4eJ5 THNePQ7Rs6jp9s6sIw4HwXRG1LrgT3FOYSgb5XGKYislsrZR3q50IKs9hb/79ld7UJ OiqryfVDEo3szuTmma6qfOEEWn4soHbgQmPBW0/I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Finley Xiao , Viresh Kumar , Amit Kucheria , Daniel Lezcano Subject: [PATCH 5.4 198/215] thermal/drivers/cpufreq_cooling: Fix wrong frequency converted from power Date: Mon, 20 Jul 2020 17:38:00 +0200 Message-Id: <20200720152829.583394765@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200720152820.122442056@linuxfoundation.org> References: <20200720152820.122442056@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Finley Xiao commit 371a3bc79c11b707d7a1b7a2c938dc3cc042fffb upstream. The function cpu_power_to_freq is used to find a frequency and set the cooling device to consume at most the power to be converted. For example, if the power to be converted is 80mW, and the em table is as follow. struct em_cap_state table[] = { /* KHz mW */ { 1008000, 36, 0 }, { 1200000, 49, 0 }, { 1296000, 59, 0 }, { 1416000, 72, 0 }, { 1512000, 86, 0 }, }; The target frequency should be 1416000KHz, not 1512000KHz. Fixes: 349d39dc5739 ("thermal: cpu_cooling: merge frequency and power tables") Cc: # v4.13+ Signed-off-by: Finley Xiao Acked-by: Viresh Kumar Reviewed-by: Amit Kucheria Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20200619090825.32747-1-finley.xiao@rock-chips.com Signed-off-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/cpu_cooling.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -210,11 +210,11 @@ static u32 cpu_power_to_freq(struct cpuf int i; struct freq_table *freq_table = cpufreq_cdev->freq_table; - for (i = 1; i <= cpufreq_cdev->max_level; i++) - if (power > freq_table[i].power) + for (i = 0; i < cpufreq_cdev->max_level; i++) + if (power >= freq_table[i].power) break; - return freq_table[i - 1].frequency; + return freq_table[i].frequency; } /**