Skip to contentSkip to conversation

thermal: common: free the mem allocated when out of use

PATCH In review Bai Ping 2 participants 2 messages Jan 12, 2016 Thermal

lore
Share & tools
lore

Bai Ping

author
#0 lore raw

PATCH 1/1 thermal: common: free the mem allocated when out of use

The memory resource allocated for thermal_zone_device should be freed when thermal_zone_device registers failed or the thermal_zone_device unregistered.

---
 drivers/thermal/thermal_core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/thermal/thermal_core.c +2 -0
index 7f7a3ca..1a9cf31 100644
@@ -2012,6 +2012,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 unregister:
 	release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
 	device_unregister(&tz->device);
+	kfree(tz);
 	return ERR_PTR(result);
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_register);
@@ -2081,6 +2082,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 	idr_destroy(&tz->idr);
 	mutex_destroy(&tz->lock);
 	device_unregister(&tz->device);
+	kfree(tz);
 	return;
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Bai Ping

The memory resource allocated for thermal_zone_device should be freed when thermal_zone_device registers failed or the thermal_zone_device unregistered.

---
 drivers/thermal/thermal_core.c | 2 ++
 1 file changed, 2 insertions(+)

Good catch!

I hope Rui can pick this up for the rc releases.

Thanks!

Quoted 20 lines
drivers/thermal/thermal_core.c +2 -0
index 7f7a3ca..1a9cf31 100644
@@ -2012,6 +2012,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 unregister:
 	release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
 	device_unregister(&tz->device);
+	kfree(tz);
 	return ERR_PTR(result);
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_register);
@@ -2081,6 +2082,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 	idr_destroy(&tz->idr);
 	mutex_destroy(&tz->lock);
 	device_unregister(&tz->device);
+	kfree(tz);
 	return;
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);