Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1688134 > unrolled thread
| Started by | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| First post | 2017-07-16 09:00 +0200 |
| Last post | 2017-07-16 09:00 +0200 |
| Articles | 3 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 1/3] thermal: core: Fix a memory leak in 'thermal_zone_device_register()' error handling path Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-07-16 09:00 +0200
[PATCH 3/3] thermal: core: Avoid code duplication in 'thermal_zone_device_register()' Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-07-16 09:00 +0200
[PATCH 2/3] thermal: core: Reorder 'thermal_zone_device_register()' error handling code Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-07-16 09:00 +0200
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-07-16 09:00 +0200 |
| Subject | [PATCH 1/3] thermal: core: Fix a memory leak in 'thermal_zone_device_register()' error handling path |
| Message-ID | <u3LH3-3He-3@gated-at.bofh.it> |
'tz' is freed in some error handling paths but not in the main one. So free it also here to avoid a memory leak. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> --- drivers/thermal/thermal_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 5a51c740e372..9743f3e65eb0 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1296,6 +1296,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, unregister: ida_simple_remove(&thermal_tz_ida, tz->id); device_unregister(&tz->device); + kfree(tz); return ERR_PTR(result); } EXPORT_SYMBOL_GPL(thermal_zone_device_register); -- 2.11.0
[toc] | [next] | [standalone]
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-07-16 09:00 +0200 |
| Subject | [PATCH 3/3] thermal: core: Avoid code duplication in 'thermal_zone_device_register()' |
| Message-ID | <u3LH3-3He-9@gated-at.bofh.it> |
| In reply to | #1688134 |
Jump in the error handling path in order to avoid code duplication if
some function fail.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/thermal/thermal_core.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index c58714800660..fe4b812eeb12 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1213,10 +1213,8 @@ thermal_zone_device_register(const char *type, int trips, int mask,
ida_init(&tz->ida);
mutex_init(&tz->lock);
result = ida_simple_get(&thermal_tz_ida, 0, 0, GFP_KERNEL);
- if (result < 0) {
- kfree(tz);
- return ERR_PTR(result);
- }
+ if (result < 0)
+ goto free_tz;
tz->id = result;
strlcpy(tz->type, type, sizeof(tz->type));
@@ -1239,11 +1237,8 @@ thermal_zone_device_register(const char *type, int trips, int mask,
dev_set_name(&tz->device, "thermal_zone%d", tz->id);
result = device_register(&tz->device);
- if (result) {
- ida_simple_remove(&thermal_tz_ida, tz->id);
- kfree(tz);
- return ERR_PTR(result);
- }
+ if (result)
+ goto remove_id;
for (count = 0; count < trips; count++) {
if (tz->ops->get_trip_type(tz, count, &trip_type))
@@ -1297,6 +1292,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
device_unregister(&tz->device);
remove_id:
ida_simple_remove(&thermal_tz_ida, tz->id);
+free_tz:
kfree(tz);
return ERR_PTR(result);
}
--
2.11.0
[toc] | [prev] | [next] | [standalone]
| From | Christophe JAILLET <christophe.jaillet@wanadoo.fr> |
|---|---|
| Date | 2017-07-16 09:00 +0200 |
| Subject | [PATCH 2/3] thermal: core: Reorder 'thermal_zone_device_register()' error handling code |
| Message-ID | <u3LH4-3He-21@gated-at.bofh.it> |
| In reply to | #1688134 |
Reorder code in the error handling path in order to match the way resources have been allocated. With this new order, we can avoid a call to 'device_unregister()' if 'thermal_zone_create_device_groups'()' fails. At this point, 'device_register()' has not been called yet. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> --- drivers/thermal/thermal_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 9743f3e65eb0..c58714800660 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1232,7 +1232,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, /* Add nodes that are always present via .groups */ result = thermal_zone_create_device_groups(tz, mask); if (result) - goto unregister; + goto remove_id; /* A new thermal zone needs to be updated anyway. */ atomic_set(&tz->need_update, 1); @@ -1294,8 +1294,9 @@ thermal_zone_device_register(const char *type, int trips, int mask, return tz; unregister: - ida_simple_remove(&thermal_tz_ida, tz->id); device_unregister(&tz->device); +remove_id: + ida_simple_remove(&thermal_tz_ida, tz->id); kfree(tz); return ERR_PTR(result); } -- 2.11.0
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web