All of lore.kernel.org
 help / color / mirror / Atom feed
From: lukasz.luba@arm.com
To: linux-kernel@vger.kernel.org, rui.zhang@intel.com,
	daniel.lezcano@linaro.org, linux-pm@vger.kernel.org
Cc: amit.kucheria@verdurent.com, lukasz.luba@arm.com,
	dietmar.eggemann@arm.com
Subject: [PATCH  2/2] thermal: devfreq_cooling: Add device node reclaiming in devfreq_cooling_register()
Date: Mon, 16 Dec 2019 14:19:09 +0000	[thread overview]
Message-ID: <20191216141909.30063-3-lukasz.luba@arm.com> (raw)
In-Reply-To: <20191216141909.30063-1-lukasz.luba@arm.com>

From: Lukasz Luba <lukasz.luba@arm.com>

Since the devfreq device parent might have the proper device node, devfreq
cooling registration can re-use it. This will allow thermal bind function
to pin thermal zone with cooling device based on definition in the device
tree automatically. It will simplify registration of cooling device in
drivers code.
Fix also 'unregister path' and add IS_ERR_OR_NULL() check.

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/devfreq_cooling.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c
index 1861241c7ef5..c29056cb4a71 100644
--- a/drivers/thermal/devfreq_cooling.c
+++ b/drivers/thermal/devfreq_cooling.c
@@ -574,7 +574,24 @@ EXPORT_SYMBOL_GPL(of_devfreq_cooling_register);
  */
 struct thermal_cooling_device *devfreq_cooling_register(struct devfreq *df)
 {
-	return of_devfreq_cooling_register(NULL, df);
+	struct thermal_cooling_device *dfc;
+	struct device_node *np = NULL;
+	struct device *dev;
+
+	if (IS_ERR_OR_NULL(df))
+		return ERR_PTR(-EINVAL);
+
+	dev = df->dev.parent;
+
+	if (dev && dev->of_node)
+		np = of_node_get(dev->of_node);
+
+	dfc = of_devfreq_cooling_register(np, df);
+
+	if (np)
+		of_node_put(np);
+
+	return dfc;
 }
 EXPORT_SYMBOL_GPL(devfreq_cooling_register);
 
@@ -586,7 +603,7 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
 {
 	struct devfreq_cooling_device *dfc;
 
-	if (!cdev)
+	if (IS_ERR_OR_NULL(cdev))
 		return;
 
 	dfc = cdev->devdata;
-- 
2.17.1


      parent reply	other threads:[~2019-12-16 14:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-16 14:19 [PATCH 0/2] Thermal devfreq cooling small updates lukasz.luba
2019-12-16 14:19 ` [PATCH 1/2] thermal: devfreq_cooling: Change license header to SPDX lukasz.luba
2019-12-16 14:19 ` lukasz.luba [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191216141909.30063-3-lukasz.luba@arm.com \
    --to=lukasz.luba@arm.com \
    --cc=amit.kucheria@verdurent.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.