提交 c2aad93c 编写于 作者: V Vladimir Zapolskiy 提交者: Eduardo Valentin

thermal: fix multiple disbalanced device node counters

Here on function return all temporarily used device nodes shall
decrement their usage counter. The problems are found with device
nodes allocated by for_each_child_of_node(), of_parse_phandle()
and of_find_node_by_name(), fix all problems at once.
Signed-off-by: NVladimir Zapolskiy <vz@mleia.com>
Cc: devicetree@vger.kernel.org
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Eduardo Valentin <edubezval@gmail.com>
Signed-off-by: NEduardo Valentin <edubezval@gmail.com>
上级 689bd24c
...@@ -387,15 +387,18 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, ...@@ -387,15 +387,18 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
int (*get_trend)(void *, long *)) int (*get_trend)(void *, long *))
{ {
struct device_node *np, *child, *sensor_np; struct device_node *np, *child, *sensor_np;
struct thermal_zone_device *tzd = ERR_PTR(-ENODEV);
np = of_find_node_by_name(NULL, "thermal-zones"); np = of_find_node_by_name(NULL, "thermal-zones");
if (!np) if (!np)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
if (!dev || !dev->of_node) if (!dev || !dev->of_node) {
of_node_put(np);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
}
sensor_np = dev->of_node; sensor_np = of_node_get(dev->of_node);
for_each_child_of_node(np, child) { for_each_child_of_node(np, child) {
struct of_phandle_args sensor_specs; struct of_phandle_args sensor_specs;
...@@ -422,16 +425,21 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, ...@@ -422,16 +425,21 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
} }
if (sensor_specs.np == sensor_np && id == sensor_id) { if (sensor_specs.np == sensor_np && id == sensor_id) {
of_node_put(np); tzd = thermal_zone_of_add_sensor(child, sensor_np,
return thermal_zone_of_add_sensor(child, sensor_np, data,
data, get_temp,
get_temp, get_trend);
get_trend); of_node_put(sensor_specs.np);
of_node_put(child);
goto exit;
} }
of_node_put(sensor_specs.np);
} }
exit:
of_node_put(sensor_np);
of_node_put(np); of_node_put(np);
return ERR_PTR(-ENODEV); return tzd;
} }
EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_register); EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_register);
...@@ -623,6 +631,7 @@ static int thermal_of_populate_trip(struct device_node *np, ...@@ -623,6 +631,7 @@ static int thermal_of_populate_trip(struct device_node *np,
/* Required for cooling map matching */ /* Required for cooling map matching */
trip->np = np; trip->np = np;
of_node_get(np);
return 0; return 0;
} }
...@@ -730,9 +739,14 @@ thermal_of_build_thermal_zone(struct device_node *np) ...@@ -730,9 +739,14 @@ thermal_of_build_thermal_zone(struct device_node *np)
return tz; return tz;
free_tbps: free_tbps:
for (i = 0; i < tz->num_tbps; i++)
of_node_put(tz->tbps[i].cooling_device);
kfree(tz->tbps); kfree(tz->tbps);
free_trips: free_trips:
for (i = 0; i < tz->ntrips; i++)
of_node_put(tz->trips[i].np);
kfree(tz->trips); kfree(tz->trips);
of_node_put(gchild);
free_tz: free_tz:
kfree(tz); kfree(tz);
of_node_put(child); of_node_put(child);
...@@ -742,7 +756,13 @@ thermal_of_build_thermal_zone(struct device_node *np) ...@@ -742,7 +756,13 @@ thermal_of_build_thermal_zone(struct device_node *np)
static inline void of_thermal_free_zone(struct __thermal_zone *tz) static inline void of_thermal_free_zone(struct __thermal_zone *tz)
{ {
int i;
for (i = 0; i < tz->num_tbps; i++)
of_node_put(tz->tbps[i].cooling_device);
kfree(tz->tbps); kfree(tz->tbps);
for (i = 0; i < tz->ntrips; i++)
of_node_put(tz->trips[i].np);
kfree(tz->trips); kfree(tz->trips);
kfree(tz); kfree(tz);
} }
...@@ -814,10 +834,13 @@ int __init of_parse_thermal_zones(void) ...@@ -814,10 +834,13 @@ int __init of_parse_thermal_zones(void)
/* attempting to build remaining zones still */ /* attempting to build remaining zones still */
} }
} }
of_node_put(np);
return 0; return 0;
exit_free: exit_free:
of_node_put(child);
of_node_put(np);
of_thermal_free_zone(tz); of_thermal_free_zone(tz);
/* no memory available, so free what we have built */ /* no memory available, so free what we have built */
...@@ -859,4 +882,5 @@ void of_thermal_destroy_zones(void) ...@@ -859,4 +882,5 @@ void of_thermal_destroy_zones(void)
kfree(zone->ops); kfree(zone->ops);
of_thermal_free_zone(zone->devdata); of_thermal_free_zone(zone->devdata);
} }
of_node_put(np);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册