[PATCH 2/2] thermal: devfreq_cooling: Add device node reclaiming in devfreq_cooling_register()
From: lukasz . luba
Date: Mon Dec 16 2019 - 09:19:29 EST
From: Lukasz Luba <lukasz.luba@xxxxxxx>
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@xxxxxxx>
---
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