From patchwork Thu Jun 27 21:02:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 167991 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2830063ilk; Thu, 27 Jun 2019 14:02:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRzaISS7GiHGvn/i1wwgvtq2vOBMT4JtYOv+DeDj4KKDSOoTgTwwiqnk9ZB4NfFS2oL4k0 X-Received: by 2002:a17:902:934a:: with SMTP id g10mr7198375plp.18.1561669348862; Thu, 27 Jun 2019 14:02:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561669348; cv=none; d=google.com; s=arc-20160816; b=nloIwf+kLtm5e1vx7oJ+wHcp2iiLax4ewd1aYzsQJKWw9FQ6JXV4VIjOyA22BUY61h fzim0jVqTVrcycwAxT+tUpBQW10TXK9Ja9kYvCozvSJ3Ei1F5nLBF0u1O8igQGGUVqNf GI8GIzvHqTQJO0t2NGB1C+rpOPvxCd9fh0LyAAfGRybT3rI9gkRuWiEKmM+UvMAPceh2 mFPk4NB2A+MB509Bo/+nUUrfYrU09QZ1dR2RCg1TKC07IMEZVdrEqO8jfrrvn9IZt4gX BmPC+Rd06Dnm1VvYwpR5o9BONR1uSDcxC+QTrrtm06QV1d8ArKn+jBcTVlHQZFyx6Tag HBFg== 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 :dkim-signature; bh=Jb+mp+rDj9DLSvOVTi217/rhPZn5ckg46P7fvQWw8bI=; b=USWKK8fQPZFG9C5TJJ43aEwKzzOxFI2GxjW8A35z1lyMI7EFuUhx7tbvW6YbS/+Nis S/NTSfpQJz/MTHWAAsfNj1eD9Fk9FYivvJfv6/0Z+WUdBH+wj5R5G2tD2ddlIZ+3vG9L EmhNVvFYTTxOkReLZAesj84Rd3rIbYoza2F8FsyorHIsPHhaoizFZ2cT4bcdg8H+p5yV aiRfizO1jiDu7xSFdhmDr8bPMnr0cUvXXKbQrNgW5tnkb/5PfUSUhKWE7NCB6IF/d0Ud wfz4hFiruNiIHsBMitSkxgyZ4ZgaTHjOg/Due2cjI4h7ZFzavpFDk4eMIUQkF3XWAWZQ XYrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XVUwEFJc; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si3417344plq.157.2019.06.27.14.02.28; Thu, 27 Jun 2019 14:02:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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 header.s=google header.b=XVUwEFJc; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1726441AbfF0VC1 (ORCPT + 11 others); Thu, 27 Jun 2019 17:02:27 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39265 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726384AbfF0VC1 (ORCPT ); Thu, 27 Jun 2019 17:02:27 -0400 Received: by mail-wm1-f67.google.com with SMTP id z23so6960484wma.4 for ; Thu, 27 Jun 2019 14:02:26 -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; bh=Jb+mp+rDj9DLSvOVTi217/rhPZn5ckg46P7fvQWw8bI=; b=XVUwEFJc76EMd/mccv9X0ByGbh5iraSJs6Fk0OV4yyos19CgBVM6X+EZu2DTrk15MH QFIul6likq8ngMyjhWhD9ZKaSzO4OGFTtnzLfQ0BMr5m9PKCKS3ebXdYFnehLUzI/vyY x7rQ0QPKjDy+HN1XV6GX0gyAJSE71tT1JY7wmarTtdJaZqq6oQZlHF5cxGpNCuU3Rgsd cT7Raw8bQg9MRKwBjIppz0fN/3MDThple+CpwnWebHEDxHeiX1R+WFtwt40jZSPqwN5t ca7dvDZq2t09/d5KGzLjFVfxZIqoed/K9rK7QxYmOnkoPfKtfgcrPu6PvAfe8kSROxG4 6hKQ== 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; bh=Jb+mp+rDj9DLSvOVTi217/rhPZn5ckg46P7fvQWw8bI=; b=ujGDYcRZB9LTPIsbpXaYG5wGLs+TCo0fuWOkmFe1ndras3biZRu/U122SaK3EKu8j9 0h8JFoeQR6F1bY3PzHHrDDf1/pN9u5BKFAqCZH3o3tYhlyS3KIdJuz81CIbhW76X50gr 2Cxu23+TQGZBMQ45vmuZivZ4A5i8y+mXduQOSQ0ylBvWfwB9gI+lqgsbPNN5kB42LaGK B0RXb0YFbKDPuo0OhARzidhHlqNjh5zIw83U9/7E3/chTjBYsAyGDQpTkUO49mlTrpWb bxYTARZrs0yafBDKrIo+/nS/z+irwu4QQiPrb0TRTTFIpY0OPZJYWrUulG9CVJSKgMD5 7XAA== X-Gm-Message-State: APjAAAVru08CNoVxRUJUEIRwwrXd64FEnzEfE1i/MkupYfsGxlkEJYUY CgYCHS4PKQBek5qdD+wqGx3F8w== X-Received: by 2002:a1c:7008:: with SMTP id l8mr4221000wmc.64.1561669345669; Thu, 27 Jun 2019 14:02:25 -0700 (PDT) Received: from clegane.local (11.117.130.77.rev.sfr.net. [77.130.117.11]) by smtp.gmail.com with ESMTPSA id k82sm107902wma.15.2019.06.27.14.02.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Jun 2019 14:02:25 -0700 (PDT) From: Daniel Lezcano To: viresh.kumar@linaro.org Cc: rjw@rjwysocki.net, edubezval@gmail.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK) Subject: [PATCH V4 1/3] cpufreq: Move the IS_ENABLED(CPU_THERMAL) macro in a stub Date: Thu, 27 Jun 2019 23:02:06 +0200 Message-Id: <20190627210209.32600-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The cpufreq_online and the cpufreq_offline [un]register the driver as a cooling device. This is done if the driver is flagged as a cooling device in addition with a IS_ENABLED macro to compile out the branching code. Group this test in a stub function added in the cpufreq header instead of having the IS_ENABLED in the code path. Suggested-by: Rafael J. Wysocki Signed-off-by: Daniel Lezcano Acked-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 6 ++---- include/linux/cpufreq.h | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 85ff958e01f1..aee024e42618 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1378,8 +1378,7 @@ static int cpufreq_online(unsigned int cpu) if (cpufreq_driver->ready) cpufreq_driver->ready(policy); - if (IS_ENABLED(CONFIG_CPU_THERMAL) && - cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) + if (cpufreq_thermal_control_enabled(cpufreq_driver)) policy->cdev = of_cpufreq_cooling_register(policy); pr_debug("initialization complete\n"); @@ -1469,8 +1468,7 @@ static int cpufreq_offline(unsigned int cpu) goto unlock; } - if (IS_ENABLED(CONFIG_CPU_THERMAL) && - cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) { + if (cpufreq_thermal_control_enabled(cpufreq_driver)) { cpufreq_cooling_unregister(policy->cdev); policy->cdev = NULL; } diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index d01a74fbc4db..a1467aa7f58b 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -409,6 +409,12 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver_data); const char *cpufreq_get_current_driver(void); void *cpufreq_get_driver_data(void); +static inline int cpufreq_thermal_control_enabled(struct cpufreq_driver *drv) +{ + return IS_ENABLED(CONFIG_CPU_THERMAL) && + (drv->flags & CPUFREQ_IS_COOLING_DEV); +} + static inline void cpufreq_verify_within_limits(struct cpufreq_policy *policy, unsigned int min, unsigned int max) { From patchwork Thu Jun 27 21:02:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 167993 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2830193ilk; Thu, 27 Jun 2019 14:02:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7OwfXfoqwsITEic5YbjThN487U8J3eZ2Wz7RsmxkJDfntduO0q9f9PyevHeZZahZ3vdPr X-Received: by 2002:a65:404a:: with SMTP id h10mr5849843pgp.262.1561669355761; Thu, 27 Jun 2019 14:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561669355; cv=none; d=google.com; s=arc-20160816; b=Kt3b0ajk4X4IdeOW0VZavVx01lvVhC3Ac4J64hVTy5qAaiYgq/i+ftMn8An/TKyV7v 2Ut+/PCEv/VwuXuGfcC1hlZ7t2exmel8Bp1b9sIoK0KU4uDYYlfQwVluM5OXKocQfoHX XtfaPkXBOn3xIl12lou/4Te5LCNopvHsf2IevbLmpjRDA7khjM68VK8YOlFBeZWys/64 mml/XJP3pUo6qIzflqLAOOhjRYVrFmPPt3M7KsHmI7V95RSaYeGTj+AKTpmqMeCgzm3J kHIhYLw0Snyaogh6aqIK8tTXwX20FClL6CaFoG7J6kxMx6IP7HYpCC48YVivZHq5lSIC Pa9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=tpUESVgsv/sulA0PM7+SZlP275qaUOQmqQ29BukGITA=; b=DBzw1t7kvwlqoEpU3+7TCDA9p5BRUXZaeJE34tLGIPBQACoJd0vDQ8t3wrxSIUw9eJ H+Tma8/laV1XRTGop834kUGWcoYnJfU82NIqkUuDrF9E/jpkRjoz5Z/wZUiJfVC8Hlvl pPhOtzn0ZMpGR/Av0A32Irh4M42fm+FMFNNAc4y+DpKyDVK/CUceGD5LWWOzOO+HR29r cEjGBxlUhGYkgEZJ2FPZeKyLRdsqbGaXDvNbHDj8gcy0Cxzs9eCozHyD+YGOWaDlMX4I +IknXO3qOjg2jYLldgwLupYtTQrE662ZdKzzSM+H7yJXLOh+9W5xqoaN0Uy8rpk836sd yjFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sQohD71H; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17si167871pgw.451.2019.06.27.14.02.35; Thu, 27 Jun 2019 14:02:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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 header.s=google header.b=sQohD71H; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1726426AbfF0VCe (ORCPT + 11 others); Thu, 27 Jun 2019 17:02:34 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34053 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726567AbfF0VCe (ORCPT ); Thu, 27 Jun 2019 17:02:34 -0400 Received: by mail-wm1-f65.google.com with SMTP id w9so7898397wmd.1 for ; Thu, 27 Jun 2019 14:02:33 -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; bh=tpUESVgsv/sulA0PM7+SZlP275qaUOQmqQ29BukGITA=; b=sQohD71HHG60ny5GLHRLPoXwYOfyt+Dnz8+4A04pWdW1QoTXb/LdwXbRkhWxoRp4fw AH7pws31fi2NICaQ4sznHRkNtLe/7uQQMWlfJ3GkYFptzTXEUPcMr8i+D2IY7+QI2RQP +TdsP/gO8BbvQQac2AsX5GLmzCi6gccA1slEmPehIUfy/oLqYM2/nYA2SLMYCJpbfMEd dyZPxr4amzs6WKCvUlbKwMGJZTu75gGyNDhd6RFQmNyzifEJyJVIQweUxK25vPxj8ZZ+ RIqKZalcXz6PSmATz+H1V9ezTkK0iywtbEcyz43c7bfkH9OVwtL/7sqM0dSOtjNjKS6H 5AsQ== 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; bh=tpUESVgsv/sulA0PM7+SZlP275qaUOQmqQ29BukGITA=; b=nM1uGoqZm+sp5jlvc5LavTlIr9M6jTyE3HdjoLerMkFhYBpIqPDUlFsd6XzwH2xBKN UnEIAiaX9PI1h1i4jZtYzB+pN/YSmvcMA8qjJK2EXVJUUTVEyRKAD2fba5mOqtGHx4w7 RH6Kc/8i93qMJ2ldwyXqt7IBaOpGwto5dBebdXjJjPVoYPhzOxmoYd2jDht4dCDoGIPv rlKY9FPKAAXXb++SruzE9PMm/mO4SPf6XP/T1YKJeLlHQ0eK9Vfsn14xHFDQrUGc2o+X O4CSCY7KkviPXxO56tGP/wUVR5wHcv4hkuGD2An4evgIEVyNHLW8DzFKnsGe5BNcMpjV heGA== X-Gm-Message-State: APjAAAWCS0fD5PagCs68jl8VtGe3vVgZu4vEOHDQQjLpkwTHNKr1kVWM crUDeT+JDQykwjrLNjctOFdygA== X-Received: by 2002:a1c:b604:: with SMTP id g4mr4610761wmf.111.1561669352055; Thu, 27 Jun 2019 14:02:32 -0700 (PDT) Received: from clegane.local (11.117.130.77.rev.sfr.net. [77.130.117.11]) by smtp.gmail.com with ESMTPSA id k82sm107902wma.15.2019.06.27.14.02.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Jun 2019 14:02:31 -0700 (PDT) From: Daniel Lezcano To: viresh.kumar@linaro.org Cc: rjw@rjwysocki.net, edubezval@gmail.com, linux-kernel@vger.kernel.org, Amit Daniel Kachhap , Javi Merino , Zhang Rui , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Keerthy , linux-pm@vger.kernel.org (open list:THERMAL/CPU_COOLING), linux-arm-kernel@lists.infradead.org (moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE), linux-omap@vger.kernel.org (open list:TI BANDGAP AND THERMAL DRIVER) Subject: [PATCH V4 3/3] thermal/drivers/cpu_cooling: cpufreq_cooling_register returns an int Date: Thu, 27 Jun 2019 23:02:08 +0200 Message-Id: <20190627210209.32600-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190627210209.32600-1-daniel.lezcano@linaro.org> References: <20190627210209.32600-1-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org It looks like after the changes in the patch the only reason for returning (struct thermal_cooling_device *) from cpufreq_cooling_register() is error checking, but it would be much more straightforward to return int for this purpose. Moreover, that would prevent the callers of it from doing incorrect things with the returned pointers (like using it to unregister the cooling device). Replace the returned value an integer instead of a pointer to a thermal cooling device structure. Suggested-by: Rafael J. Wysocki Signed-off-by: Daniel Lezcano --- drivers/thermal/cpu_cooling.c | 63 +++++++++---------- drivers/thermal/imx_thermal.c | 6 +- .../ti-soc-thermal/ti-thermal-common.c | 7 +-- include/linux/cpu_cooling.h | 16 ++--- 4 files changed, 40 insertions(+), 52 deletions(-) -- 2.17.1 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index be01546a656f..0d5e39716542 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -530,13 +530,12 @@ static struct notifier_block thermal_cpufreq_notifier_block = { * cooling devices. It also gives the opportunity to link the cooling device * with a device tree node, in order to bind it via the thermal DT code. * - * Return: a valid struct thermal_cooling_device pointer on success, - * on failure, it returns a corresponding ERR_PTR(). + * Return: zero on success, less than zero corresponding to the + * negative error code. */ -static struct thermal_cooling_device * -__cpufreq_cooling_register(struct device_node *np, - struct cpufreq_policy *policy, - struct em_perf_domain *em) +static int __cpufreq_cooling_register(struct device_node *np, + struct cpufreq_policy *policy, + struct em_perf_domain *em) { struct thermal_cooling_device *cdev; struct cpufreq_cooling_device *cpufreq_cdev; @@ -548,19 +547,19 @@ __cpufreq_cooling_register(struct device_node *np, if (IS_ERR_OR_NULL(policy)) { pr_err("%s: cpufreq policy isn't valid: %p\n", __func__, policy); - return ERR_PTR(-EINVAL); + return -EINVAL; } i = cpufreq_table_count_valid_entries(policy); if (!i) { pr_debug("%s: CPUFreq table not found or has no valid entries\n", __func__); - return ERR_PTR(-ENODEV); + return -ENODEV; } cpufreq_cdev = kzalloc(sizeof(*cpufreq_cdev), GFP_KERNEL); if (!cpufreq_cdev) - return ERR_PTR(-ENOMEM); + return -ENOMEM; cpufreq_cdev->policy = policy; num_cpus = cpumask_weight(policy->related_cpus); @@ -568,7 +567,7 @@ __cpufreq_cooling_register(struct device_node *np, sizeof(*cpufreq_cdev->idle_time), GFP_KERNEL); if (!cpufreq_cdev->idle_time) { - cdev = ERR_PTR(-ENOMEM); + ret = -ENOMEM; goto free_cdev; } @@ -576,10 +575,8 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_cdev->max_level = i - 1; ret = ida_simple_get(&cpufreq_ida, 0, 0, GFP_KERNEL); - if (ret < 0) { - cdev = ERR_PTR(ret); + if (ret < 0) goto free_idle_time; - } cpufreq_cdev->id = ret; snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", @@ -597,14 +594,16 @@ __cpufreq_cooling_register(struct device_node *np, if (policy->freq_table_sorted == CPUFREQ_TABLE_UNSORTED) { pr_err("%s: unsorted frequency tables are not supported\n", __func__); - cdev = ERR_PTR(-EINVAL); + ret = -EINVAL; goto remove_ida; } cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev, cooling_ops); - if (IS_ERR(cdev)) + if (IS_ERR(cdev)) { + ret = PTR_ERR(cdev); goto remove_ida; + } cpufreq_cdev->clipped_freq = get_state_freq(cpufreq_cdev, 0); cpufreq_cdev->cdev = cdev; @@ -619,7 +618,7 @@ __cpufreq_cooling_register(struct device_node *np, cpufreq_register_notifier(&thermal_cpufreq_notifier_block, CPUFREQ_POLICY_NOTIFIER); - return cdev; + return 0; remove_ida: ida_simple_remove(&cpufreq_ida, cpufreq_cdev->id); @@ -627,7 +626,7 @@ __cpufreq_cooling_register(struct device_node *np, kfree(cpufreq_cdev->idle_time); free_cdev: kfree(cpufreq_cdev); - return cdev; + return ret; } /** @@ -638,11 +637,10 @@ __cpufreq_cooling_register(struct device_node *np, * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq * cooling devices. * - * Return: a valid struct thermal_cooling_device pointer on success, - * on failure, it returns a corresponding ERR_PTR(). + * Return: zero on success, less than zero corresponding to the + * negative error code. */ -struct thermal_cooling_device * -cpufreq_cooling_register(struct cpufreq_policy *policy) +int cpufreq_cooling_register(struct cpufreq_policy *policy) { return __cpufreq_cooling_register(NULL, policy, NULL); } @@ -664,34 +662,31 @@ EXPORT_SYMBOL_GPL(cpufreq_cooling_register); * It also takes into account, if property present in policy CPU node, the * static power consumed by the cpu. * - * Return: a valid struct thermal_cooling_device pointer on success, - * and NULL on failure. + * Return: zero on success, less than zero corresponding to the + * negative error code. */ -struct thermal_cooling_device * -of_cpufreq_cooling_register(struct cpufreq_policy *policy) +int of_cpufreq_cooling_register(struct cpufreq_policy *policy) { struct device_node *np = of_get_cpu_node(policy->cpu, NULL); - struct thermal_cooling_device *cdev = NULL; + int ret = -EINVAL; if (!np) { pr_err("cpu_cooling: OF node not available for cpu%d\n", policy->cpu); - return NULL; + return -EINVAL; } if (of_find_property(np, "#cooling-cells", NULL)) { struct em_perf_domain *em = em_cpu_get(policy->cpu); - cdev = __cpufreq_cooling_register(np, policy, em); - if (IS_ERR(cdev)) { - pr_err("cpu_cooling: cpu%d failed to register as cooling device: %ld\n", - policy->cpu, PTR_ERR(cdev)); - cdev = NULL; - } + ret = __cpufreq_cooling_register(np, policy, em); + if (ret) + pr_err("cpu_cooling: cpu%d failed to register as cooling device: %d\n", + policy->cpu, ret); } of_node_put(np); - return cdev; + return ret; } EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 021c0948b740..1c4b49b583bc 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -655,7 +655,6 @@ MODULE_DEVICE_TABLE(of, of_imx_thermal_match); static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data) { struct device_node *np; - struct thermal_cooling_device *cdev; int ret; data->policy = cpufreq_cpu_get(0); @@ -667,9 +666,8 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data) np = of_get_cpu_node(data->policy->cpu, NULL); if (!np || !of_find_property(np, "#cooling-cells", NULL)) { - cdev = cpufreq_cooling_register(data->policy); - if (IS_ERR(cdev)) { - ret = PTR_ERR(cdev); + ret = cpufreq_cooling_register(data->policy); + if (ret) { cpufreq_cpu_put(data->policy); return ret; } diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c index 170b70b6ec61..eacc46d7bd1c 100644 --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c @@ -232,7 +232,7 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) { struct ti_thermal_data *data; struct device_node *np = bgp->dev->of_node; - struct thermal_cooling_device *cdev; + int ret; /* * We are assuming here that if one deploys the zone @@ -256,9 +256,8 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) } /* Register cooling device */ - cdev = cpufreq_cooling_register(data->policy); - if (IS_ERR(cdev)) { - int ret = PTR_ERR(cdev); + ret = cpufreq_cooling_register(data->policy); + if (ret) { dev_err(bgp->dev, "Failed to register cpu cooling device %d\n", ret); cpufreq_cpu_put(data->policy); diff --git a/include/linux/cpu_cooling.h b/include/linux/cpu_cooling.h index 89f469ee4be4..98f7c8a9cab6 100644 --- a/include/linux/cpu_cooling.h +++ b/include/linux/cpu_cooling.h @@ -24,8 +24,7 @@ struct cpufreq_policy; * cpufreq_cooling_register - function to create cpufreq cooling device. * @policy: cpufreq policy. */ -struct thermal_cooling_device * -cpufreq_cooling_register(struct cpufreq_policy *policy); +int cpufreq_cooling_register(struct cpufreq_policy *policy); /** * cpufreq_cooling_unregister - function to remove cpufreq cooling device. @@ -34,10 +33,9 @@ cpufreq_cooling_register(struct cpufreq_policy *policy); void cpufreq_cooling_unregister(struct cpufreq_policy *policy); #else /* !CONFIG_CPU_THERMAL */ -static inline struct thermal_cooling_device * -cpufreq_cooling_register(struct cpufreq_policy *policy) +static inline int cpufreq_cooling_register(struct cpufreq_policy *policy) { - return ERR_PTR(-ENOSYS); + return -ENOSYS; } static inline @@ -52,13 +50,11 @@ void cpufreq_cooling_unregister(struct cpufreq_policy *policy) * of_cpufreq_cooling_register - create cpufreq cooling device based on DT. * @policy: cpufreq policy. */ -struct thermal_cooling_device * -of_cpufreq_cooling_register(struct cpufreq_policy *policy); +int of_cpufreq_cooling_register(struct cpufreq_policy *policy); #else -static inline struct thermal_cooling_device * -of_cpufreq_cooling_register(struct cpufreq_policy *policy) +static inline int of_cpufreq_cooling_register(struct cpufreq_policy *policy) { - return NULL; + return -ENOSYS; } #endif /* defined(CONFIG_THERMAL_OF) && defined(CONFIG_CPU_THERMAL) */