Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp98379ybt; Thu, 18 Jun 2020 19:30:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnfu5Hnq65WBHqz5vYbUD/q5HJAAAqdCAdoIzisINkJ/c5R9l5+WOMgMFCsWD97z88lSSH X-Received: by 2002:a50:a68f:: with SMTP id e15mr1111040edc.285.1592533849361; Thu, 18 Jun 2020 19:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592533849; cv=none; d=google.com; s=arc-20160816; b=aPrEagrw9NVIE3imHkfxe6YA0p36rt3BYD02BxwkkmaPqgXkO5ldsxlfnN8dCv25lx kBXg6kwR9upuGKUuG8NbgEX7nC84a1BFMOiCBeW1XkNy/LsWfuO2olt9oXW6Xctq3Noq 5ZAAfRCIlJ9ev7tgjSJ1xf1DDX2kZxuOuWisLRvGcW/rM3VBhDnNWMrhCA82pmoOltJJ mCIB1o2+xs8pk3+ucBuLdRLh1AbPEVTkXtX1ug2erAUIriul1sDRPU/03Eea0Gbhpz4R vhaoTDNh67lVYtogttM0E9H+HWiaUAOV3eCXwnOEoeIVUz6EcXcqOXpvdmdBiUxcgdCR sFsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=gpioeVHT90jdfCvZQAX/M0SDr1w0JijGSnfsY8TFmk8=; b=R+6n6V1eJkR0ppf7EzgxRqlF8cg88/hLRgxj1jkd+rzQ3qPawWA6YpiFkisp0cgZDg ieiqxPjjJ4jy91asaBP7cxTMG28stUCM4quXJhX+8mXmoRDexnLVGps0jX8HjJDLH6sw O6HFqFx9d2IMGj2uPNi2MV6rEi9BtcFJsktpKAS42cMeae50CKNlIadr+N/NGC2ykYGc j89Tw1a7BcX5gzOCdXjBprlbPY/cNHAfzhDXjamYyrukubcobBBDEFTucLd9HgxZFJZf m0LW9XsArdgLgA1W6lyxUDY7HAFhOC+STeQYBSm67aF7eyfkh0nt4DDIyy7tZcTiVaRi TjTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lx2si2779371ejb.284.2020.06.18.19.30.27; Thu, 18 Jun 2020 19:30:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728961AbgFSBv7 (ORCPT + 99 others); Thu, 18 Jun 2020 21:51:59 -0400 Received: from lucky1.263xmail.com ([211.157.147.130]:57270 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbgFSBv6 (ORCPT ); Thu, 18 Jun 2020 21:51:58 -0400 Received: from localhost (unknown [192.168.167.69]) by lucky1.263xmail.com (Postfix) with ESMTP id ABE87CA699; Fri, 19 Jun 2020 09:51:52 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P15426T140189185066752S1592531511027415_; Fri, 19 Jun 2020 09:51:52 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: X-RL-SENDER: finley.xiao@rock-chips.com X-SENDER: xf@rock-chips.com X-LOGIN-NAME: finley.xiao@rock-chips.com X-FST-TO: xf@rock-chips.com X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: Finley Xiao To: xf@rock-chips.com, heiko@sntech.de, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, javi.merino@kernel.org, rui.zhang@intel.com, amit.kucheria@verdurent.com Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, huangtao@rock-chips.com, tony.xie@rock-chips.com, cl@rock-chips.com, Finley Xiao Subject: [PATCH] thermal/drivers/cpufreq_cooling: Fix wrong frequency converted from power Date: Fri, 19 Jun 2020 09:51:26 +0800 Message-Id: <20200619015126.15002-1-finley.xiao@rock-chips.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: Finley Xiao --- drivers/thermal/cpufreq_cooling.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c index 9e124020519f..6c0e1b053126 100644 --- a/drivers/thermal/cpufreq_cooling.c +++ b/drivers/thermal/cpufreq_cooling.c @@ -123,12 +123,12 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, { int i; - for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { - if (power > cpufreq_cdev->em->table[i].power) + for (i = cpufreq_cdev->max_level; i >= 0; i--) { + if (power >= cpufreq_cdev->em->table[i].power) break; } - return cpufreq_cdev->em->table[i + 1].frequency; + return cpufreq_cdev->em->table[i].frequency; } /** -- 2.11.0