Skip to contentSkip to conversation

tracing: fix a potential mutex deadlock in register_tracer

PATCH New Chunyu Hu 1 participant 1 message Mar 14, 2016

Subsystems (2)
lore
Share & tools
lore

Chunyu Hu

author
#0 lore raw

PATCH 1/1 tracing: fix a potential mutex deadlock in register_tracer

commit d39cdd2036a63eef17a14efbd969405ca5612886 ("tracing: Make tracer_flags use the right set_flag callback") introduces a potential mutex deadlock issue, as it forgets to free the mutex when allocaing the tracer_flags gets fail. This patch fix the issue. The issue was found by Dan Carpenter through Smatch static code check tool.

---
 kernel/trace/trace.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/trace/trace.c +4 -2
index b401a18..0ae4604 100644
@@ -1256,8 +1256,10 @@ int __init register_tracer(struct tracer *type)
 	if (!type->flags) {
 		/*allocate a dummy tracer_flags*/
 		type->flags = kmalloc(sizeof(*type->flags), GFP_KERNEL);
-		if (!type->flags)
-			return -ENOMEM;
+		if (!type->flags) {
+			ret = -ENOMEM;
+			goto out;
+		}
 		type->flags->val = 0;
 		type->flags->opts = dummy_tracer_opt;
 	} else
Signature · 1 line
1.8.3.1