diff mbox series

[2/2] thermal: devfreq_cooling: Add device node reclaiming in devfreq_cooling_register()

Message ID 20191216141909.30063-3-lukasz.luba@arm.com (mailing list archive)
State New, archived
Delegated to: Daniel Lezcano
Headers show
Series Thermal devfreq cooling small updates | expand

Commit Message

Lukasz Luba Dec. 16, 2019, 2:19 p.m. UTC
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 mbox series

Patch

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;