From patchwork Wed Apr 19 05:28:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97592 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159209qgf; Tue, 18 Apr 2017 22:31:07 -0700 (PDT) X-Received: by 10.99.154.9 with SMTP id o9mr1178041pge.54.1492579867774; Tue, 18 Apr 2017 22:31:07 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si1294599pfb.367.2017.04.18.22.31.07; Tue, 18 Apr 2017 22:31:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759879AbdDSFay (ORCPT + 17 others); Wed, 19 Apr 2017 01:30:54 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:32872 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759846AbdDSFas (ORCPT ); Wed, 19 Apr 2017 01:30:48 -0400 Received: by mail-pf0-f182.google.com with SMTP id a188so7013078pfa.0 for ; Tue, 18 Apr 2017 22:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=pWdZ+GVLjCCntIzI1bUyY81hDwAEgzUBqUO8N1c67CY=; b=XxEHo6QXmj/VM6E2UyPfeZQ+0yuWHYugxbO6NkslC+Z/PONlwwvLtFdJGhQvgCfQv0 MYXPb4RweS9dvArU8g3Ci6XuqqHekCcgqL61xUXDA4WZQUQJeNIOKXcBO/Vb04GbvjUS rQXfY9Io5rLN3oJwcYx/qFDkdV7cf27xwwVWo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=pWdZ+GVLjCCntIzI1bUyY81hDwAEgzUBqUO8N1c67CY=; b=fp5pbZQNvBRaE5sloQoEDgR7CpVtLVYfb3UdFlt74xexDT7di58XjP4HgDfsWSQ0XX COkVAL7nWNCaY9ouhUW3wkb3bHSVp9NW6Gs9l/mykUbSO7CaxZYfIgmSPI8Zt7j9VwL2 73ekW10NW/Bd9ch9gAOWk4EXtSBkgSV3HWYaiEvCwd7S24ydt7fUwdiYLJ0xjG1B5s3+ Ih01YZV6lNKxhgs2BjezcWF7hyjexQ+wfgB/CelEtaccjQORGt1BHTXYm/3E7SJo0Mbi MujR3I8t1ks3VCrhBB5/iLtTfTqQZ5F/4Cc3UbAndhd1uz3YwB9In3uCbwgQ2cE74qqi Qgqg== X-Gm-Message-State: AN3rC/6dZ77BQdiHF10jup7tkhtLFvmNipW8nLCGMX+6V8v+2V06YUIi AaWcJ8HYErX0vuQE X-Received: by 10.98.96.65 with SMTP id u62mr1229698pfb.186.1492579847364; Tue, 18 Apr 2017 22:30:47 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id s65sm1663604pgb.34.2017.04.18.22.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:30:46 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V3 04/17] thermal: cpu_cooling: replace cool_dev with cdev Date: Wed, 19 Apr 2017 10:58:59 +0530 Message-Id: <0f1d7f8ebc3915c46b8fa7656a972bee75c79ba4.1492579345.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Objects of "struct thermal_cooling_device" are named a bit inconsistently. Lets use cdev everywhere. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 80a46a80817b..f1e784c22c5a 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -65,7 +65,7 @@ struct power_table { * struct cpufreq_cooling_device - data for cooling device with cpufreq * @id: unique integer value corresponding to each cpufreq_cooling_device * registered. - * @cool_dev: thermal_cooling_device pointer to keep track of the + * @cdev: thermal_cooling_device pointer to keep track of the * registered cooling device. * @cpufreq_state: integer value representing the current state of cpufreq * cooling devices. @@ -90,7 +90,7 @@ struct power_table { */ struct cpufreq_cooling_device { int id; - struct thermal_cooling_device *cool_dev; + struct thermal_cooling_device *cdev; unsigned int cpufreq_state; unsigned int clipped_freq; unsigned int max_level; @@ -242,7 +242,7 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_cdev, for_each_cpu(cpu, &cpufreq_cdev->allowed_cpus) { dev = get_cpu_device(cpu); if (!dev) { - dev_warn(&cpufreq_cdev->cool_dev->device, + dev_warn(&cpufreq_cdev->cdev->device, "No cpu device for cpu %d\n", cpu); continue; } @@ -769,7 +769,7 @@ __cpufreq_cooling_register(struct device_node *np, get_static_t plat_static_func) { struct cpufreq_policy *policy; - struct thermal_cooling_device *cool_dev; + struct thermal_cooling_device *cdev; struct cpufreq_cooling_device *cpufreq_cdev; char dev_name[THERMAL_NAME_LENGTH]; struct cpufreq_frequency_table *pos, *table; @@ -786,20 +786,20 @@ __cpufreq_cooling_register(struct device_node *np, policy = cpufreq_cpu_get(cpumask_first(temp_mask)); if (!policy) { pr_debug("%s: CPUFreq policy not found\n", __func__); - cool_dev = ERR_PTR(-EPROBE_DEFER); + cdev = ERR_PTR(-EPROBE_DEFER); goto free_cpumask; } table = policy->freq_table; if (!table) { pr_debug("%s: CPUFreq table not found\n", __func__); - cool_dev = ERR_PTR(-ENODEV); + cdev = ERR_PTR(-ENODEV); goto put_policy; } cpufreq_cdev = kzalloc(sizeof(*cpufreq_cdev), GFP_KERNEL); if (!cpufreq_cdev) { - cool_dev = ERR_PTR(-ENOMEM); + cdev = ERR_PTR(-ENOMEM); goto put_policy; } @@ -808,7 +808,7 @@ __cpufreq_cooling_register(struct device_node *np, sizeof(*cpufreq_cdev->time_in_idle), GFP_KERNEL); if (!cpufreq_cdev->time_in_idle) { - cool_dev = ERR_PTR(-ENOMEM); + cdev = ERR_PTR(-ENOMEM); goto free_cdev; } @@ -816,7 +816,7 @@ __cpufreq_cooling_register(struct device_node *np, kcalloc(num_cpus, sizeof(*cpufreq_cdev->time_in_idle_timestamp), GFP_KERNEL); if (!cpufreq_cdev->time_in_idle_timestamp) { - cool_dev = ERR_PTR(-ENOMEM); + cdev = ERR_PTR(-ENOMEM); goto free_time_in_idle; } @@ -827,7 +827,7 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_cdev->freq_table = kmalloc(sizeof(*cpufreq_cdev->freq_table) * cpufreq_cdev->max_level, GFP_KERNEL); if (!cpufreq_cdev->freq_table) { - cool_dev = ERR_PTR(-ENOMEM); + cdev = ERR_PTR(-ENOMEM); goto free_time_in_idle_timestamp; } @@ -841,7 +841,7 @@ __cpufreq_cooling_register(struct device_node *np, ret = build_dyn_power_table(cpufreq_cdev, capacitance); if (ret) { - cool_dev = ERR_PTR(ret); + cdev = ERR_PTR(ret); goto free_table; } @@ -852,7 +852,7 @@ __cpufreq_cooling_register(struct device_node *np, ret = ida_simple_get(&cpufreq_ida, 0, 0, GFP_KERNEL); if (ret < 0) { - cool_dev = ERR_PTR(ret); + cdev = ERR_PTR(ret); goto free_power_table; } cpufreq_cdev->id = ret; @@ -872,14 +872,13 @@ __cpufreq_cooling_register(struct device_node *np, snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", cpufreq_cdev->id); - cool_dev = thermal_of_cooling_device_register(np, dev_name, - cpufreq_cdev, - cooling_ops); - if (IS_ERR(cool_dev)) + cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev, + cooling_ops); + if (IS_ERR(cdev)) goto remove_ida; cpufreq_cdev->clipped_freq = cpufreq_cdev->freq_table[0]; - cpufreq_cdev->cool_dev = cool_dev; + cpufreq_cdev->cdev = cdev; mutex_lock(&cooling_list_lock); /* Register the notifier for first cpufreq cooling device */ @@ -909,7 +908,7 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_cpu_put(policy); free_cpumask: free_cpumask_var(temp_mask); - return cool_dev; + return cdev; } /** @@ -1047,7 +1046,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, CPUFREQ_POLICY_NOTIFIER); - thermal_cooling_device_unregister(cpufreq_cdev->cool_dev); + thermal_cooling_device_unregister(cpufreq_cdev->cdev); ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); kfree(cpufreq_cdev->dyn_power_table); kfree(cpufreq_cdev->time_in_idle_timestamp); From patchwork Wed Apr 19 05:29:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97605 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159895qgf; Tue, 18 Apr 2017 22:33:47 -0700 (PDT) X-Received: by 10.84.229.7 with SMTP id b7mr1590591plk.72.1492580027884; Tue, 18 Apr 2017 22:33:47 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u4si1301953pgo.283.2017.04.18.22.33.47; Tue, 18 Apr 2017 22:33:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760039AbdDSFdn (ORCPT + 17 others); Wed, 19 Apr 2017 01:33:43 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:34865 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759885AbdDSFbF (ORCPT ); Wed, 19 Apr 2017 01:31:05 -0400 Received: by mail-pf0-f173.google.com with SMTP id v14so3357162pfd.2 for ; Tue, 18 Apr 2017 22:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=962dFnpTkV5Ezk0cE/xseT2XrhtVFda/qpZ+2+FxAl8=; b=ZzdV7cqpX6nPuU/Iy2W5vLpOjybVGoCi093F8ubqwzzDc/PuqmOwqribn0adS+TJ6x f8PcDL1ep7GW6ZxbYBPHPHuiqs4QWx9pGXi5dYr3mCsqZuZPvKUY/nJPv5Vsa89Y5m5D SEmp6yaYob7W+rKPbMHgC1zv9ojXTAtWwJesA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=962dFnpTkV5Ezk0cE/xseT2XrhtVFda/qpZ+2+FxAl8=; b=EURNvgkdOHm7AKjRoTDf5JpN8sTlp1QW8vAwJSwwFBPV6WOe78QqSI4iKG5u14PIFY h68A1C7lW6ZaaYXYoIAQIMNn8b/GizxDSswCkC8FDrKfZ+uBVFR29R+ryrlYMRInN8jK VbRxGOLholuVp5m8785JEM8LItBqWRAkzsycKtnEBbgkfBpSWHf32HiUVojK1ZU9j5SF XTl6fiVNlRNl15jbwr3Bc8ExGKQEei3WH8wf+o01+v32Dkb5+PKqWvGmF9pmXMaWf4P6 kEHdqRCuYAlKTvAv/G9VvhEmx3EMNicmm84tOpYEuICRHuVupIlGYJnIuj/Tomac3jIN KUpw== X-Gm-Message-State: AN3rC/4aVrSEo0FxEBLWGjf1OwjxjRpq7YnkYJKZjd8oVSMtB/WGFenn JTiYO6qKIO2oE7j/ X-Received: by 10.84.225.129 with SMTP id u1mr1534617plj.123.1492579864796; Tue, 18 Apr 2017 22:31:04 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id y6sm1674400pgc.40.2017.04.18.22.31.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:04 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V3 09/17] thermal: cpu_cooling: store cpufreq policy Date: Wed, 19 Apr 2017 10:59:04 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cpufreq policy can be used by the cpu_cooling driver, lets store it in the cpufreq_cooling_device structure. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 55ff45c1e917..7dddc7443f5d 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -67,6 +67,7 @@ struct power_table { * registered. * @cdev: thermal_cooling_device pointer to keep track of the * registered cooling device. + * @policy: cpufreq policy. * @cpufreq_state: integer value representing the current state of cpufreq * cooling devices. * @clipped_freq: integer value representing the absolute value of the clipped @@ -91,6 +92,7 @@ struct power_table { struct cpufreq_cooling_device { int id; struct thermal_cooling_device *cdev; + struct cpufreq_policy *policy; unsigned int cpufreq_state; unsigned int clipped_freq; unsigned int max_level; @@ -760,6 +762,7 @@ __cpufreq_cooling_register(struct device_node *np, if (!cpufreq_cdev) return ERR_PTR(-ENOMEM); + cpufreq_cdev->policy = policy; num_cpus = cpumask_weight(policy->related_cpus); cpufreq_cdev->time_in_idle = kcalloc(num_cpus, sizeof(*cpufreq_cdev->time_in_idle), From patchwork Wed Apr 19 05:29:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97598 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159352qgf; Tue, 18 Apr 2017 22:31:36 -0700 (PDT) X-Received: by 10.99.123.72 with SMTP id k8mr1216838pgn.6.1492579896590; Tue, 18 Apr 2017 22:31:36 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t65si1299733pfg.280.2017.04.18.22.31.36; Tue, 18 Apr 2017 22:31:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759966AbdDSFbZ (ORCPT + 17 others); Wed, 19 Apr 2017 01:31:25 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:33592 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759927AbdDSFbS (ORCPT ); Wed, 19 Apr 2017 01:31:18 -0400 Received: by mail-pg0-f44.google.com with SMTP id 63so7412622pgh.0 for ; Tue, 18 Apr 2017 22:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=hYyHMeC7VXANBPHeJx84iO9Kp1b9PHCjQsjW/GMkZMA=; b=bcu89A1tI+0HQg3aZ+sOTn/IDunAt/ByE2PV8UZe+CwWGpI/J2BcVCd3gm8emAoh8W UQJsNXYfE03h5g7Jz289d/02Lbyb+hjde5dxRl/cbt20rUrl/3BpBaY5RRfsxtqwt3Wd tSsbxvFZSzLyHQ3QMn8xOURRsAJlsEAxLrE3c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=hYyHMeC7VXANBPHeJx84iO9Kp1b9PHCjQsjW/GMkZMA=; b=EDDMUe1WfND+idqvFNwAh5k5pPoen08+alqhd6vM6fiUb3PTi0/zQGpCJfIdlsiPWb 2j0gHsHC+e6OG1wyvqjLsja64PU3lBztm2Y3TDjvtP04xhR6WLBNmCiuBc+Rtg4oO7Lc ibocMdjl2c5fu23jKPedvzzNugxEYFFbVM4jQqDmzX8hJ/Edr+K4USeT+ejIJIQh1Vlk pUO0fDiN952djesIc9GnsOvF+eLPbm128h8pWNoi+q4EoUXNnbz4kzgAY77alWp/9qMy mIffHxS62nd9Igk0yDpazKypJNMLESsNUWG+ZHVsUoGjDROZAA/QoHuOUcmJVGCXM94b Xoww== X-Gm-Message-State: AN3rC/6w4lqltiL7yaeEjeHc6df9U5Bb5TNPIsNC4KlWB2GeyjZzXMYP jDrpgSSKYWzRZtiV X-Received: by 10.99.114.80 with SMTP id c16mr1176203pgn.121.1492579868094; Tue, 18 Apr 2017 22:31:08 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id y184sm1671614pgb.33.2017.04.18.22.31.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:07 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V3 10/17] thermal: cpu_cooling: OPPs are registered for all CPUs Date: Wed, 19 Apr 2017 10:59:05 +0530 Message-Id: X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The OPPs are registered for all CPUs of a cpufreq policy now and we don't need to run the loop in build_dyn_power_table(). Just check for the policy->cpu and we should be fine. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 7dddc7443f5d..ce387f62c93e 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -83,7 +83,7 @@ struct power_table { * @dyn_power_table: array of struct power_table for frequency to power * conversion, sorted in ascending order. * @dyn_power_table_entries: number of entries in the @dyn_power_table array - * @cpu_dev: the first cpu_device from @allowed_cpus that has OPPs registered + * @cpu_dev: the cpu_device of policy->cpu. * @plat_get_static_power: callback to calculate the static power * * This structure is required for keeping information of each registered @@ -207,24 +207,20 @@ static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_cdev, struct power_table *power_table; struct dev_pm_opp *opp; struct device *dev = NULL; - int num_opps = 0, cpu, i, ret = 0; + int num_opps = 0, cpu = cpufreq_cdev->policy->cpu, i, ret = 0; unsigned long freq; - for_each_cpu(cpu, &cpufreq_cdev->allowed_cpus) { - dev = get_cpu_device(cpu); - if (!dev) { - dev_warn(&cpufreq_cdev->cdev->device, - "No cpu device for cpu %d\n", cpu); - continue; - } - - num_opps = dev_pm_opp_get_opp_count(dev); - if (num_opps > 0) - break; - else if (num_opps < 0) - return num_opps; + dev = get_cpu_device(cpu); + if (unlikely(!dev)) { + dev_warn(&cpufreq_cdev->cdev->device, + "No cpu device for cpu %d\n", cpu); + return -ENODEV; } + num_opps = dev_pm_opp_get_opp_count(dev); + if (num_opps < 0) + return num_opps; + if (num_opps == 0) return -EINVAL; From patchwork Wed Apr 19 05:29:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97599 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159445qgf; Tue, 18 Apr 2017 22:31:57 -0700 (PDT) X-Received: by 10.99.105.10 with SMTP id e10mr1213213pgc.142.1492579917146; Tue, 18 Apr 2017 22:31:57 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f35si1321610plh.40.2017.04.18.22.31.56; Tue, 18 Apr 2017 22:31:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760002AbdDSFbf (ORCPT + 17 others); Wed, 19 Apr 2017 01:31:35 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:32979 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759959AbdDSFbY (ORCPT ); Wed, 19 Apr 2017 01:31:24 -0400 Received: by mail-pf0-f177.google.com with SMTP id a188so7018574pfa.0 for ; Tue, 18 Apr 2017 22:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=X6DB3sJCkAMeHm8LvB1QJVO0O4bhfzFfUwrxNnGon/0=; b=Xo58cWlsz0BTXGPF6/IznvDF7hspvuEWS5JXV/t82W8pYztiyFmakP0bQavrcyxKHA hBDZ/bob3H9o0tyfz1j3BgiIg8btfLVsGW7gMbNrnQ2I0WRbgnZiFGf9g4o995OH5Q06 TFMPKjDZRiKi0iy9hjwTaR3dQ2OHrMyHSONDA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=X6DB3sJCkAMeHm8LvB1QJVO0O4bhfzFfUwrxNnGon/0=; b=LLgXGIml5LsA8pb2COAMVCO9dyBpbg+WnOFEF3WavjoRNvAIUdCaDANCXRbCUpOsyN O85HSPUS5rzNJa8HyxgMvjov1KvrPGmezGLQKekXGsa19xXtVd05RFgHrtLuFW6WQDu3 LlbSoCSCHibEKj4ye+dVevpmeyronvClkcYiHbEusWGs/3Qu/rkaBJdyp9N/pTK87YMh wzB4lOXwXuPcj8SzDXrTwHiO7jHyJS6la1KUqDUMDdSrZtbRhYdWfcr77q1T3kxTql3e TIwseGjOY/G/I/brLmxpNNniDXrr5wRDkPD8CfdSc6AJpUaB4Jw3iuwQh8/UyosieyHV nKIQ== X-Gm-Message-State: AN3rC/4hp9aJ+haIFW1RbyORTCU27cb9lgT4tJ6M2LPnRYkUyhlV6d1b Izi1eOFMRThKvijC X-Received: by 10.84.232.68 with SMTP id f4mr1560566pln.90.1492579878442; Tue, 18 Apr 2017 22:31:18 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id e131sm1687391pfg.10.2017.04.18.22.31.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:17 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V3 13/17] thermal: cpu_cooling: create structure for idle time stats Date: Wed, 19 Apr 2017 10:59:08 +0530 Message-Id: <0b2ff123ccb13c1ba0edb5716d28994884d87734.1492579345.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We keep two arrays for idle time stats and allocate memory for them separately. It would be much easier to follow if we create an array of idle stats structure instead and allocate it once. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 53 ++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 28 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 17d6d4635936..71d15448a293 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -62,6 +62,16 @@ struct freq_table { }; /** + * struct time_in_idle - Idle time stats + * @time: previous reading of the absolute time that this cpu was idle + * @timestamp: wall time of the last invocation of get_cpu_idle_time_us() + */ +struct time_in_idle { + u64 time; + u64 timestamp; +}; + +/** * struct cpufreq_cooling_device - data for cooling device with cpufreq * @id: unique integer value corresponding to each cpufreq_cooling_device * registered. @@ -76,9 +86,7 @@ struct freq_table { * cpufreq frequencies. * @node: list_head to link all cpufreq_cooling_device together. * @last_load: load measured by the latest call to cpufreq_get_requested_power() - * @time_in_idle: previous reading of the absolute time that this cpu was idle - * @time_in_idle_timestamp: wall time of the last invocation of - * get_cpu_idle_time_us() + * @idle_time: idle time stats * @cpu_dev: the cpu_device of policy->cpu. * @plat_get_static_power: callback to calculate the static power * @@ -95,8 +103,7 @@ struct cpufreq_cooling_device { struct freq_table *freq_table; /* In descending order */ struct list_head node; u32 last_load; - u64 *time_in_idle; - u64 *time_in_idle_timestamp; + struct time_in_idle *idle_time; struct device *cpu_dev; get_static_t plat_get_static_power; }; @@ -296,18 +303,19 @@ static u32 get_load(struct cpufreq_cooling_device *cpufreq_cdev, int cpu, { u32 load; u64 now, now_idle, delta_time, delta_idle; + struct time_in_idle *idle_time = &cpufreq_cdev->idle_time[cpu_idx]; now_idle = get_cpu_idle_time(cpu, &now, 0); - delta_idle = now_idle - cpufreq_cdev->time_in_idle[cpu_idx]; - delta_time = now - cpufreq_cdev->time_in_idle_timestamp[cpu_idx]; + delta_idle = now_idle - idle_time->time; + delta_time = now - idle_time->timestamp; if (delta_time <= delta_idle) load = 0; else load = div64_u64(100 * (delta_time - delta_idle), delta_time); - cpufreq_cdev->time_in_idle[cpu_idx] = now_idle; - cpufreq_cdev->time_in_idle_timestamp[cpu_idx] = now; + idle_time->time = now_idle; + idle_time->timestamp = now; return load; } @@ -711,22 +719,14 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_cdev->policy = policy; num_cpus = cpumask_weight(policy->related_cpus); - cpufreq_cdev->time_in_idle = kcalloc(num_cpus, - sizeof(*cpufreq_cdev->time_in_idle), - GFP_KERNEL); - if (!cpufreq_cdev->time_in_idle) { + cpufreq_cdev->idle_time = kcalloc(num_cpus, + sizeof(*cpufreq_cdev->idle_time), + GFP_KERNEL); + if (!cpufreq_cdev->idle_time) { cdev = ERR_PTR(-ENOMEM); goto free_cdev; } - cpufreq_cdev->time_in_idle_timestamp = - kcalloc(num_cpus, sizeof(*cpufreq_cdev->time_in_idle_timestamp), - GFP_KERNEL); - if (!cpufreq_cdev->time_in_idle_timestamp) { - cdev = ERR_PTR(-ENOMEM); - goto free_time_in_idle; - } - /* max_level is an index, not a counter */ cpufreq_cdev->max_level = i - 1; @@ -734,7 +734,7 @@ __cpufreq_cooling_register(struct device_node *np, GFP_KERNEL); if (!cpufreq_cdev->freq_table) { cdev = ERR_PTR(-ENOMEM); - goto free_time_in_idle_timestamp; + goto free_idle_time; } ret = ida_simple_get(&cpufreq_ida, 0, 0, GFP_KERNEL); @@ -797,10 +797,8 @@ __cpufreq_cooling_register(struct device_node *np, ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); free_table: kfree(cpufreq_cdev->freq_table); -free_time_in_idle_timestamp: - kfree(cpufreq_cdev->time_in_idle_timestamp); -free_time_in_idle: - kfree(cpufreq_cdev->time_in_idle); +free_idle_time: + kfree(cpufreq_cdev->idle_time); free_cdev: kfree(cpufreq_cdev); return cdev; @@ -943,8 +941,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) thermal_cooling_device_unregister(cpufreq_cdev->cdev); ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); - kfree(cpufreq_cdev->time_in_idle_timestamp); - kfree(cpufreq_cdev->time_in_idle); + kfree(cpufreq_cdev->idle_time); kfree(cpufreq_cdev->freq_table); kfree(cpufreq_cdev); } From patchwork Wed Apr 19 05:29:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97603 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159671qgf; Tue, 18 Apr 2017 22:32:51 -0700 (PDT) X-Received: by 10.84.204.8 with SMTP id a8mr1593431ple.4.1492579971327; Tue, 18 Apr 2017 22:32:51 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m77si1320339pfk.78.2017.04.18.22.32.51; Tue, 18 Apr 2017 22:32:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760092AbdDSFct (ORCPT + 17 others); Wed, 19 Apr 2017 01:32:49 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:36771 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759948AbdDSFbc (ORCPT ); Wed, 19 Apr 2017 01:31:32 -0400 Received: by mail-pg0-f45.google.com with SMTP id g2so7363574pge.3 for ; Tue, 18 Apr 2017 22:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ahpmI1YLl0RT+Uo2v5QzlQE3xRyjtadMKU23p1gghBY=; b=KEaTY1ETyw8paFPEL3abDtpwMIQnFcCDWhhHycILe0qwwJoN8iJKybmEhI4HsqC7fJ a/gJowTtblYWrZUmNOHxP2EQDGMiFMhS6s+SdY+vv8CVNuk+iudzNEbgwi+ZcWbEQLYI gNCGYW3L3ai3JuSK9MNyjaEgFMQctTP5WWbCk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ahpmI1YLl0RT+Uo2v5QzlQE3xRyjtadMKU23p1gghBY=; b=W2iubgiv+FjeWV5wpOltNURlYHA49eBQ5lTFLpR36tWs+YidlzqNuowv8/jcbiWB6h CopeZG23eiHFHQQQT0uxKVDSZdEWvV9soNCIqxbVuZmFDzdmV97LR92KfC4yCLo5iqpK RBkpJmDHfI/oNFOaa51ET8o1MLRwpkkDHfFVdDveViyRUQK1EcEbDqtzyQQOOrB9QKX3 xJoPU8iomLruu6X6hlEcmtes6x3DBpID29YLsyA2hBruTJjSK0Zjprk5taVZGFw73pYP GJD8yB8Ikcr1j93TYy84BAOwrIEwVfPnr+PprrTndOk/6ynqpFhqH1JEfHyzfiRl2w/J o5ig== X-Gm-Message-State: AN3rC/6+NREoGLv9O1gPril/+mso0d24Tlo7w3oLKfOTRmO7GwNGsKxQ TzLAeaQfpigORaw3 X-Received: by 10.98.78.195 with SMTP id c186mr1173296pfb.155.1492579886864; Tue, 18 Apr 2017 22:31:26 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id u23sm1664673pgo.58.2017.04.18.22.31.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:26 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V3 14/17] thermal: cpu_cooling: get_level() can't fail Date: Wed, 19 Apr 2017 10:59:09 +0530 Message-Id: <09e52ed89325153b65be7896918d7dcf8b7f1684.1492579345.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The frequency passed to get_level() is returned by cpu_power_to_freq() and it is guaranteed that get_level() can't fail. Get rid of error code. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 71d15448a293..762ddfc4e654 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -119,22 +119,19 @@ static LIST_HEAD(cpufreq_cdev_list); * @cpufreq_cdev: cpufreq_cdev for which the property is required * @freq: Frequency * - * Return: level on success, THERMAL_CSTATE_INVALID on error. + * Return: level corresponding to the frequency. */ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, unsigned int freq) { + struct freq_table *freq_table = cpufreq_cdev->freq_table; unsigned long level; - for (level = 0; level <= cpufreq_cdev->max_level; level++) { - if (freq == cpufreq_cdev->freq_table[level].frequency) - return level; - - if (freq > cpufreq_cdev->freq_table[level].frequency) + for (level = 1; level < cpufreq_cdev->max_level; level++) + if (freq > freq_table[level].frequency) break; - } - return THERMAL_CSTATE_INVALID; + return level - 1; } /** @@ -623,13 +620,6 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev, target_freq = cpu_power_to_freq(cpufreq_cdev, normalised_power); *state = get_level(cpufreq_cdev, target_freq); - if (*state == THERMAL_CSTATE_INVALID) { - dev_err_ratelimited(&cdev->device, - "Failed to convert %dKHz for cpu %d into a cdev state\n", - target_freq, policy->cpu); - return -EINVAL; - } - trace_thermal_power_cpu_limit(policy->related_cpus, target_freq, *state, power); return 0; From patchwork Wed Apr 19 05:29:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 97602 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp159549qgf; Tue, 18 Apr 2017 22:32:23 -0700 (PDT) X-Received: by 10.98.81.132 with SMTP id f126mr1187707pfb.95.1492579943509; Tue, 18 Apr 2017 22:32:23 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k4si1305947pgn.218.2017.04.18.22.32.23; Tue, 18 Apr 2017 22:32:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760056AbdDSFcM (ORCPT + 17 others); Wed, 19 Apr 2017 01:32:12 -0400 Received: from mail-pg0-f52.google.com ([74.125.83.52]:35615 "EHLO mail-pg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759992AbdDSFbe (ORCPT ); Wed, 19 Apr 2017 01:31:34 -0400 Received: by mail-pg0-f52.google.com with SMTP id 72so7373863pge.2 for ; Tue, 18 Apr 2017 22:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=+uptI25DhQOS9ZVHX6zgqKgGv81u8Oej0uJ+6fqJ6Xw=; b=OVTHPRhtJNkAyhOt/4eQDWyu2DmvzIAPJPaGo1yuyKl+0olAX3L7DPlWP0Ah7LU5qq Uu313LEuzrr5o9lxJp9ck/UjmXrv2qiOPyS0Ii7BrtJxx2P4fy/91mk75gKw6oUX5dKl 5eBql7H/L2RYtIV6Uo+RlQKh3bGs4NxoKhfI8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=+uptI25DhQOS9ZVHX6zgqKgGv81u8Oej0uJ+6fqJ6Xw=; b=kyarAXGnhV77fEeYJyEswDZrph4rl4LQDxUjK0ye+MgJfpSmYrKJENjDhDKIfJuw49 MVbwImSS4WQrTiAx2JSRJB0OsdSxk47zqUX/C9pch+e7bPCUUPNTv6+U3PVyFJbv18GT gjuGULXj/rNvA4d8hNl2M74XxYBy/v8oHTjAIGnXv5jk6N5ytv2X0rV7U4igJNPOxb9u C4HURwaYHMoMqvfX3Qn2tRJYeCcuNGoCWstDyu9GLHyOhaQIw9nQ/Vy6rJPsgAuRYGHy /VQIEwSKYkmBpsLe87J/mjdhDkax8KQ2q7kcIJCJWiYWOw+27vnfkiAUpi2Gw1uMlqLo MKSg== X-Gm-Message-State: AN3rC/7cnVmQoY4OeZ8pQKZz4IDpjF7EwesxL9Fmr8raymj0p7hPQhwu 8oMl6Aw6j8RWzyN1 X-Received: by 10.84.129.131 with SMTP id b3mr1588839plb.1.1492579893626; Tue, 18 Apr 2017 22:31:33 -0700 (PDT) Received: from localhost ([122.172.121.5]) by smtp.gmail.com with ESMTPSA id t141sm1682082pgb.3.2017.04.18.22.31.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 22:31:32 -0700 (PDT) From: Viresh Kumar To: Javi Merino , Zhang Rui , Eduardo Valentin , Lukasz Luba , Amit Daniel Kachhap , Viresh Kumar Cc: linaro-kernel@lists.linaro.org, Rafael Wysocki , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Punit Agrawal Subject: [PATCH V3 16/17] thermal: cpu_cooling: 'freq' can't be zero in cpufreq_state2power() Date: Wed, 19 Apr 2017 10:59:11 +0530 Message-Id: <17b27faf383d82aa7a5a6330f08c185663aac447.1492579345.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.12.0.432.g71c3a4f4ba37 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The frequency table shouldn't have any zero frequency entries and so such a check isn't required. Though it would be better to make sure 'state' is within limits. Signed-off-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 2.12.0.432.g71c3a4f4ba37 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index c85b217d16c8..dc73405b04f2 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -560,12 +560,13 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, int ret; struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; + /* Request state should be less than max_level */ + if (WARN_ON(state > cpufreq_cdev->max_level)) + return -EINVAL; + num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); freq = cpufreq_cdev->freq_table[state].frequency; - if (!freq) - return -EINVAL; - dynamic_power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus; ret = get_static_power(cpufreq_cdev, tz, freq, &static_power); if (ret)