Skip to contentSkip to conversation

tracing: Various cleanups

PATCH In review Jiri Olsa 2 participants 12 messages Apr 25, 2012 – May 12, 2012

Subsystems (2)
lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

cover tracing: Various cleanups

hi,
sending some small cleanups I gathered along the way ;)

attached patches:
1/4 ftrace: Remove unused code ftrace related code 2/4 ftrace: Remove unused ftrace_update_time variable/code 3/4 ftrace: No return value for ftrace_process_locs 4/4 tracing: Use seq_*_private interface for some seq files

wbr,
jirka

---
 include/linux/ftrace.h |    7 --
 kernel/trace/ftrace.c  |  199 ++++++++----------------------------------------
 kernel/trace/trace.c   |   27 +------
 3 files changed, 35 insertions(+), 198 deletions(-)
author
#4 lore raw

PATCH 2/4 ftrace: Remove unused ftrace_update_time variable/code

The update time of the records update is meassured but never used. It was probably dropped along the way, removing it.

Also changing ftrace_update_cnt static variable into automatic, since it's used only in ftrace_update_code function.

---
 kernel/trace/ftrace.c |   18 ++++--------------
 1 files changed, 4 insertions(+), 14 deletions(-)
kernel/trace/ftrace.c +4 -14
index 6e6c51a..b3ceecd 100644
@@ -1920,9 +1920,7 @@ static void ftrace_shutdown_sysctl(void)
 		ftrace_run_update_code(FTRACE_DISABLE_CALLS);
 }
 
-static cycle_t		ftrace_update_time;
-static unsigned long	ftrace_update_cnt;
-unsigned long		ftrace_update_tot_cnt;
+unsigned long ftrace_update_tot_cnt;
 
 static int ops_traces_mod(struct ftrace_ops *ops)
 {
@@ -1936,8 +1934,7 @@ static int ftrace_update_code(struct module *mod)
 {
 	struct ftrace_page *pg;
 	struct dyn_ftrace *p;
-	cycle_t start, stop;
-	unsigned long ref = 0;
+	unsigned long ref = 0, cnt = 0;
 	int i;
 
 	/*
@@ -1957,9 +1954,6 @@ static int ftrace_update_code(struct module *mod)
 		}
 	}
 
-	start = ftrace_now(raw_smp_processor_id());
-	ftrace_update_cnt = 0;
-
 	for (pg = ftrace_new_pgs; pg; pg = pg->next) {
 
 		for (i = 0; i < pg->index; i++) {
@@ -1977,7 +1971,7 @@ static int ftrace_update_code(struct module *mod)
 			if (!ftrace_code_disable(mod, p))
 				break;
 
-			ftrace_update_cnt++;
+			cnt++;
 
 			/*
 			 * If the tracing is enabled, go ahead and enable the record.
@@ -1997,11 +1991,7 @@ static int ftrace_update_code(struct module *mod)
 	}
 
 	ftrace_new_pgs = NULL;
-
-	stop = ftrace_now(raw_smp_processor_id());
-	ftrace_update_time = stop - start;
-	ftrace_update_tot_cnt += ftrace_update_cnt;
-
+	ftrace_update_tot_cnt += cnt;
 	return 0;
 }
 
Signature · 1 line
1.7.1
author
#6 lore raw

PATCH 3/4 ftrace: No return value for ftrace_process_locs

In reply to Jiri Olsa

The return value of ftrace_process_locs is never checked. The function tries to update as many calls as possible and in case of error there's either warning output or ftrace_bug call.

---
 kernel/trace/ftrace.c |   37 ++++++++++++++++---------------------
 1 files changed, 16 insertions(+), 21 deletions(-)
kernel/trace/ftrace.c +16 -21
index b3ceecd..e67f5b3 100644
@@ -1930,7 +1930,7 @@ static int ops_traces_mod(struct ftrace_ops *ops)
 	return ftrace_hash_empty(hash);
 }
 
-static int ftrace_update_code(struct module *mod)
+static void ftrace_update_code(struct module *mod)
 {
 	struct ftrace_page *pg;
 	struct dyn_ftrace *p;
@@ -1959,7 +1959,7 @@ static int ftrace_update_code(struct module *mod)
 		for (i = 0; i < pg->index; i++) {
 			/* If something went wrong, bail without enabling anything */
 			if (unlikely(ftrace_disabled))
-				return -1;
+				return;
 
 			p = &pg->records[i];
 			p->flags = ref;
@@ -1968,8 +1968,8 @@ static int ftrace_update_code(struct module *mod)
 			 * Do the initial record conversion from mcount jump
 			 * to the NOP instructions.
 			 */
-			if (!ftrace_code_disable(mod, p))
-				break;
+			if (WARN_ON_ONCE(!ftrace_code_disable(mod, p)))
+				return;
 
 			cnt++;
 
@@ -1992,7 +1992,6 @@ static int ftrace_update_code(struct module *mod)
 
 	ftrace_new_pgs = NULL;
 	ftrace_update_tot_cnt += cnt;
-	return 0;
 }
 
 static int ftrace_allocate_records(struct ftrace_page *pg, int count)
@@ -2041,11 +2040,11 @@ ftrace_allocate_pages(unsigned long num_to_init)
 	int cnt;
 
 	if (!num_to_init)
-		return 0;
+		return NULL;
 
 	start_pg = pg = kzalloc(sizeof(*pg), GFP_KERNEL);
 	if (!pg)
-		return NULL;
+		goto out;
 
 	/*
 	 * Try to allocate as much as possible in one continues
@@ -2078,6 +2077,7 @@ ftrace_allocate_pages(unsigned long num_to_init)
 		kfree(pg);
 		pg = start_pg;
 	}
+ out:
 	pr_info("ftrace: FAILED to allocate memory for functions\n");
 	return NULL;
 }
@@ -3589,25 +3589,23 @@ static void ftrace_swap_recs(void *a, void *b, int size)
 	*recb = t;
 }
 
-static int ftrace_process_locs(struct module *mod,
-			       unsigned long *start,
-			       unsigned long *end)
+static void ftrace_process_locs(struct module *mod,
+				unsigned long *start,
+				unsigned long *end)
 {
 	struct ftrace_page *pg;
 	unsigned long count;
 	unsigned long *p;
 	unsigned long addr;
 	unsigned long flags = 0; /* Shut up gcc */
-	int ret = -ENOMEM;
 
 	count = end - start;
-
 	if (!count)
-		return 0;
+		return;
 
 	pg = ftrace_allocate_pages(count);
 	if (!pg)
-		return -ENOMEM;
+		return;
 
 	mutex_lock(&ftrace_lock);
 
@@ -3621,7 +3619,7 @@ static int ftrace_process_locs(struct module *mod,
 		/* First initialization */
 		ftrace_pages = ftrace_pages_start = pg;
 	} else {
-		if (!ftrace_pages)
+		if (!WARN_ON_ONCE(ftrace_pages))
 			goto out;
 
 		if (WARN_ON(ftrace_pages->next)) {
@@ -3670,11 +3668,8 @@ static int ftrace_process_locs(struct module *mod,
 	ftrace_update_code(mod);
 	if (!mod)
 		local_irq_restore(flags);
-	ret = 0;
  out:
 	mutex_unlock(&ftrace_lock);
-
-	return ret;
 }
 
 #ifdef CONFIG_MODULES
@@ -3789,9 +3784,9 @@ void __init ftrace_init(void)
 
 	last_ftrace_enabled = ftrace_enabled = 1;
 
-	ret = ftrace_process_locs(NULL,
-				  __start_mcount_loc,
-				  __stop_mcount_loc);
+	ftrace_process_locs(NULL,
+			    __start_mcount_loc,
+			    __stop_mcount_loc);
 
 	ret = register_module_notifier(&ftrace_module_nb);
 	if (ret)
Signature · 1 line
1.7.1
author
#10 lore raw

PATCH 4/4 tracing: Use seq_*_private interface for some seq files

In reply to Jiri Olsa

It's appropriate to use __seq_open_private interface to open some of trace seq files, because it covers all steps we are duplicating in tracing code - zallocating the iterator and setting it as seq_file's private.

Using this for following files:
trace
available_filter_functions
enabled_functions

---
 kernel/trace/ftrace.c |   44 +++++++++++---------------------------------
 kernel/trace/trace.c  |   27 ++++-----------------------
 2 files changed, 15 insertions(+), 56 deletions(-)
kernel/trace/ftrace.c +11 -33
index e67f5b3..14989a7 100644
@@ -2359,57 +2359,35 @@ static int
 ftrace_avail_open(struct inode *inode, struct file *file)
 {
 	struct ftrace_iterator *iter;
-	int ret;
 
 	if (unlikely(ftrace_disabled))
 		return -ENODEV;
 
-	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
-	if (!iter)
-		return -ENOMEM;
-
-	iter->pg = ftrace_pages_start;
-	iter->ops = &global_ops;
-
-	ret = seq_open(file, &show_ftrace_seq_ops);
-	if (!ret) {
-		struct seq_file *m = file->private_data;
-
-		m->private = iter;
-	} else {
-		kfree(iter);
+	iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
+	if (iter) {
+		iter->pg = ftrace_pages_start;
+		iter->ops = &global_ops;
 	}
 
-	return ret;
+	return iter ? 0 : -ENOMEM;
 }
 
 static int
 ftrace_enabled_open(struct inode *inode, struct file *file)
 {
 	struct ftrace_iterator *iter;
-	int ret;
 
 	if (unlikely(ftrace_disabled))
 		return -ENODEV;
 
-	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
-	if (!iter)
-		return -ENOMEM;
-
-	iter->pg = ftrace_pages_start;
-	iter->flags = FTRACE_ITER_ENABLED;
-	iter->ops = &global_ops;
-
-	ret = seq_open(file, &show_ftrace_seq_ops);
-	if (!ret) {
-		struct seq_file *m = file->private_data;
-
-		m->private = iter;
-	} else {
-		kfree(iter);
+	iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
+	if (iter) {
+		iter->pg = ftrace_pages_start;
+		iter->flags = FTRACE_ITER_ENABLED;
+		iter->ops = &global_ops;
 	}
 
-	return ret;
+	return iter ? 0 : -ENOMEM;
 }
 
 static void ftrace_filter_reset(struct ftrace_hash *hash)
kernel/trace/trace.c +4 -23
index ed7b5d1..cf382a4 100644
@@ -2332,7 +2332,6 @@ static struct trace_iterator *
 __tracing_open(struct inode *inode, struct file *file)
 {
 	long cpu_file = (long) inode->i_private;
-	void *fail_ret = ERR_PTR(-ENOMEM);
 	struct trace_iterator *iter;
 	struct seq_file *m;
 	int cpu, ret;
@@ -2340,7 +2339,7 @@ __tracing_open(struct inode *inode, struct file *file)
 	if (tracing_disabled)
 		return ERR_PTR(-ENODEV);
 
-	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+	iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter));
 	if (!iter)
 		return ERR_PTR(-ENOMEM);
 
@@ -2397,32 +2396,15 @@ __tracing_open(struct inode *inode, struct file *file)
 		tracing_iter_reset(iter, cpu);
 	}
 
-	ret = seq_open(file, &tracer_seq_ops);
-	if (ret < 0) {
-		fail_ret = ERR_PTR(ret);
-		goto fail_buffer;
-	}
-
-	m = file->private_data;
-	m->private = iter;
-
 	mutex_unlock(&trace_types_lock);
 
 	return iter;
 
- fail_buffer:
-	for_each_tracing_cpu(cpu) {
-		if (iter->buffer_iter[cpu])
-			ring_buffer_read_finish(iter->buffer_iter[cpu]);
-	}
-	free_cpumask_var(iter->started);
-	tracing_start();
  fail:
 	mutex_unlock(&trace_types_lock);
 	kfree(iter->trace);
-	kfree(iter);
-
-	return fail_ret;
+	seq_release_private(inode, file);
+	return ERR_PTR(-ENOMEM);
 }
 
 int tracing_open_generic(struct inode *inode, struct file *filp)
@@ -2458,11 +2440,10 @@ static int tracing_release(struct inode *inode, struct file *file)
 	tracing_start();
 	mutex_unlock(&trace_types_lock);
 
-	seq_release(inode, file);
 	mutex_destroy(&iter->mutex);
 	free_cpumask_var(iter->started);
 	kfree(iter->trace);
-	kfree(iter);
+	seq_release_private(inode, file);
 	return 0;
 }
 
Signature · 1 line
1.7.1
author
#1 lore raw

PATCH 1/4 ftrace: Remove unused code ftrace related code

In reply to Jiri Olsa

Removing unused functions:
ftrace_rec_iter_record
ftrace_rec_iter_next
ftrace_rec_iter_start
ftrace_location

---
 include/linux/ftrace.h |    7 ---
 kernel/trace/ftrace.c  |  100 ------------------------------------------------
 2 files changed, 0 insertions(+), 107 deletions(-)
include/linux/ftrace.h +0 -7
index 72a6cab..49596e3 100644
@@ -280,16 +280,9 @@ enum {
 
 void arch_ftrace_update_code(int command);
 
-struct ftrace_rec_iter;
-
-struct ftrace_rec_iter *ftrace_rec_iter_start(void);
-struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
-struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
-
 int ftrace_update_record(struct dyn_ftrace *rec, int enable);
 int ftrace_test_record(struct dyn_ftrace *rec, int enable);
 void ftrace_run_stop_machine(int command);
-int ftrace_location(unsigned long ip);
 
 extern ftrace_func_t ftrace_trace_function;
 
kernel/trace/ftrace.c +0 -100

112 lines not on this page · raw message

Signature · 1 line
1.7.1
maintainer
#2 lore raw

Re: [PATCH 1/4] ftrace: Remove unused code ftrace related code

Quoted 5 lines · Jiri Olsa

Removing unused functions:
ftrace_rec_iter_record
ftrace_rec_iter_next
ftrace_rec_iter_start
ftrace_location

No, no, no!!

These are used in the core infrastructure of removing stop machine from ftrace.

Correct, no one currently uses them, but that's because they were needed for the arch dependent code. I have patches for both PPC and x86 to remove stop machine, and I want the PPC changes to go through the PPC tree.

I pushed the changes for the core infrastructure so that we don't have dependencies between different archs.

Please read: commit c88fd8634ea68e74c7d19fd2621b4078fd22864c

If you remove these you would break:

https://lkml.org/lkml/2012/4/23/620

Big NACK!

-- Steve

maintainer
#5 lore raw

Re: [PATCH 2/4] ftrace: Remove unused ftrace_update_time variable/code

In reply to Jiri Olsa
Quoted 2 lines · Jiri Olsa

The update time of the records update is meassured but never used. It was probably dropped along the way, removing it.

No it's not dropped. I have patches that read it. But you are correct, that I should either add those patches, or moved this code out into those patches, and keep the kernel clean.

Actually, as there's a debug file in the debugfs code now (dyn_ftrace_total_info). That would be a good place to put this info.

-- Steve

Quoted 3 lines

Also changing ftrace_update_cnt static variable into automatic, since it's used only in ftrace_update_code function.

maintainer
#7 lore raw

Re: [PATCH 3/4] ftrace: No return value for ftrace_process_locs

In reply to Jiri Olsa
Quoted 3 lines · Jiri Olsa

The return value of ftrace_process_locs is never checked. The function tries to update as many calls as possible and in case of error there's either warning output or ftrace_bug call.

No, the real bug is...

kernel/trace/ftrace.c void __init ftrace_init(void) · line 3789

Quoted 11 lines

#ifdef CONFIG_MODULES

kernel/trace/ftrace.c +3 -3
@@ -3789,9 +3784,9 @@ void __init ftrace_init(void)
 
 	last_ftrace_enabled = ftrace_enabled = 1;
 
-	ret = ftrace_process_locs(NULL,
-				  __start_mcount_loc,
-				  __stop_mcount_loc);
+	ftrace_process_locs(NULL,
+			    __start_mcount_loc,
+			    __stop_mcount_loc);

We should check the return code of ftrace_process_locs().

-- Steve

Quoted 3 lines
kernel/trace/ftrace.c +0 -0
 	ret = register_module_notifier(&ftrace_module_nb);
 	if (ret)
author
#3 lore raw

Re: [PATCH 1/4] ftrace: Remove unused code ftrace related code

In reply to Steven Rostedt
Quoted 20 lines · Steven Rostedt
Quoted 5 lines · Jiri Olsa

Removing unused functions:
ftrace_rec_iter_record
ftrace_rec_iter_next
ftrace_rec_iter_start
ftrace_location

No, no, no!!

These are used in the core infrastructure of removing stop machine from ftrace.

Correct, no one currently uses them, but that's because they were needed for the arch dependent code. I have patches for both PPC and x86 to remove stop machine, and I want the PPC changes to go through the PPC tree.

I pushed the changes for the core infrastructure so that we don't have dependencies between different archs.

Quoted 7 lines

Please read: commit c88fd8634ea68e74c7d19fd2621b4078fd22864c

If you remove these you would break:

https://lkml.org/lkml/2012/4/23/620

Big NACK!

I see, thought they were just leftover not seeing any user.. big sorry then ;-)

jirka

Quoted 5 lines

-- Steve

maintainer
#8 lore raw

Re: [PATCH 3/4] ftrace: No return value for ftrace_process_locs

In reply to Jiri Olsa
Quoted 32 lines · Jiri Olsa

The return value of ftrace_process_locs is never checked. The function tries to update as many calls as possible and in case of error there's either warning output or ftrace_bug call.

---
 kernel/trace/ftrace.c |   37 ++++++++++++++++---------------------
 1 files changed, 16 insertions(+), 21 deletions(-)
kernel/trace/ftrace.c +2 -2
index b3ceecd..e67f5b3 100644
@@ -1930,7 +1930,7 @@ static int ops_traces_mod(struct ftrace_ops *ops)
 	return ftrace_hash_empty(hash);
 }
 
-static int ftrace_update_code(struct module *mod)
+static void ftrace_update_code(struct module *mod)
 {
 	struct ftrace_page *pg;
 	struct dyn_ftrace *p;
@@ -1959,7 +1959,7 @@ static int ftrace_update_code(struct module *mod)
 		for (i = 0; i < pg->index; i++) {
 			/* If something went wrong, bail without enabling anything */
 			if (unlikely(ftrace_disabled))
-				return -1;
+				return;
 
 			p = &pg->records[i];
 			p->flags = ref;

kernel/trace/ftrace.c static int ftrace_update_code(struct module *mod) · line 1972

Quoted 7 lines
kernel/trace/ftrace.c +2 -2
@@ -1968,8 +1968,8 @@ static int ftrace_update_code(struct module *mod)
 			 * Do the initial record conversion from mcount jump
 			 * to the NOP instructions.
 			 */
-			if (!ftrace_code_disable(mod, p))
-				break;
+			if (WARN_ON_ONCE(!ftrace_code_disable(mod, p)))
+				return;

Why the warning? If ftrace_disabled is set, something broke a long time ago, and the ftrace_bug gives its own warning.

I don't think this is needed.

-- Steve

#11 lore raw

[tip:perf/core] tracing: Use seq_*_private interface for some seq files

In reply to Jiri Olsa
Commit-ID:  50e18b94c695644d824381e7574b9c44acc25ffe
Gitweb:     http://git.kernel.org/tip/50e18b94c695644d824381e7574b9c44acc25ffe
Author:     Jiri Olsa <[email protected]>
AuthorDate: Wed, 25 Apr 2012 10:23:39 +0200
Committer:  Steven Rostedt <[email protected]>
CommitDate: Tue, 8 May 2012 21:04:12 -0400

tracing: Use seq_*_private interface for some seq files

It's appropriate to use __seq_open_private interface to open some of trace seq files, because it covers all steps we are duplicating in tracing code - zallocating the iterator and setting it as seq_file's private.

Using this for following files:
trace
available_filter_functions
enabled_functions

[
Fixed warnings for:
kernel/trace/trace.c: In function '__tracing_open':
kernel/trace/trace.c:2418:11: warning: unused variable 'ret' [-Wunused-variable] kernel/trace/trace.c:2417:19: warning: unused variable 'm' [-Wunused-variable]
]

---
 kernel/trace/ftrace.c |   44 +++++++++++---------------------------------
 kernel/trace/trace.c  |   30 +++++-------------------------
 2 files changed, 16 insertions(+), 58 deletions(-)
kernel/trace/ftrace.c +11 -33
index 0fa92f6..cf81f27 100644
@@ -2469,57 +2469,35 @@ static int
 ftrace_avail_open(struct inode *inode, struct file *file)
 {
 	struct ftrace_iterator *iter;
-	int ret;
 
 	if (unlikely(ftrace_disabled))
 		return -ENODEV;
 
-	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
-	if (!iter)
-		return -ENOMEM;
-
-	iter->pg = ftrace_pages_start;
-	iter->ops = &global_ops;
-
-	ret = seq_open(file, &show_ftrace_seq_ops);
-	if (!ret) {
-		struct seq_file *m = file->private_data;
-
-		m->private = iter;
-	} else {
-		kfree(iter);
+	iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
+	if (iter) {
+		iter->pg = ftrace_pages_start;
+		iter->ops = &global_ops;
 	}
 
-	return ret;
+	return iter ? 0 : -ENOMEM;
 }
 
 static int
 ftrace_enabled_open(struct inode *inode, struct file *file)
 {
 	struct ftrace_iterator *iter;
-	int ret;
 
 	if (unlikely(ftrace_disabled))
 		return -ENODEV;
 
-	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
-	if (!iter)
-		return -ENOMEM;
-
-	iter->pg = ftrace_pages_start;
-	iter->flags = FTRACE_ITER_ENABLED;
-	iter->ops = &global_ops;
-
-	ret = seq_open(file, &show_ftrace_seq_ops);
-	if (!ret) {
-		struct seq_file *m = file->private_data;
-
-		m->private = iter;
-	} else {
-		kfree(iter);
+	iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
+	if (iter) {
+		iter->pg = ftrace_pages_start;
+		iter->flags = FTRACE_ITER_ENABLED;
+		iter->ops = &global_ops;
 	}
 
-	return ret;
+	return iter ? 0 : -ENOMEM;
 }
 
 static void ftrace_filter_reset(struct ftrace_hash *hash)
kernel/trace/trace.c +5 -25
index f11a285..4fb10ef 100644
@@ -2413,15 +2413,13 @@ static struct trace_iterator *
 __tracing_open(struct inode *inode, struct file *file)
 {
 	long cpu_file = (long) inode->i_private;
-	void *fail_ret = ERR_PTR(-ENOMEM);
 	struct trace_iterator *iter;
-	struct seq_file *m;
-	int cpu, ret;
+	int cpu;
 
 	if (tracing_disabled)
 		return ERR_PTR(-ENODEV);
 
-	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+	iter = __seq_open_private(file, &tracer_seq_ops, sizeof(*iter));
 	if (!iter)
 		return ERR_PTR(-ENOMEM);
 
@@ -2478,32 +2476,15 @@ __tracing_open(struct inode *inode, struct file *file)
 		tracing_iter_reset(iter, cpu);
 	}
 
-	ret = seq_open(file, &tracer_seq_ops);
-	if (ret < 0) {
-		fail_ret = ERR_PTR(ret);
-		goto fail_buffer;
-	}
-
-	m = file->private_data;
-	m->private = iter;
-
 	mutex_unlock(&trace_types_lock);
 
 	return iter;
 
- fail_buffer:
-	for_each_tracing_cpu(cpu) {
-		if (iter->buffer_iter[cpu])
-			ring_buffer_read_finish(iter->buffer_iter[cpu]);
-	}
-	free_cpumask_var(iter->started);
-	tracing_start();
  fail:
 	mutex_unlock(&trace_types_lock);
 	kfree(iter->trace);
-	kfree(iter);
-
-	return fail_ret;
+	seq_release_private(inode, file);
+	return ERR_PTR(-ENOMEM);
 }
 
 int tracing_open_generic(struct inode *inode, struct file *filp)
@@ -2539,11 +2520,10 @@ static int tracing_release(struct inode *inode, struct file *file)
 	tracing_start();
 	mutex_unlock(&trace_types_lock);
 
-	seq_release(inode, file);
 	mutex_destroy(&iter->mutex);
 	free_cpumask_var(iter->started);
 	kfree(iter->trace);
-	kfree(iter);
+	seq_release_private(inode, file);
 	return 0;
 }
 
author
#9 lore raw

Re: [PATCH 3/4] ftrace: No return value for ftrace_process_locs

In reply to Steven Rostedt
Quoted 44 lines · Steven Rostedt
Quoted 32 lines · Jiri Olsa

The return value of ftrace_process_locs is never checked. The function tries to update as many calls as possible and in case of error there's either warning output or ftrace_bug call.

---
 kernel/trace/ftrace.c |   37 ++++++++++++++++---------------------
 1 files changed, 16 insertions(+), 21 deletions(-)
kernel/trace/ftrace.c +2 -2
index b3ceecd..e67f5b3 100644
@@ -1930,7 +1930,7 @@ static int ops_traces_mod(struct ftrace_ops *ops)
 	return ftrace_hash_empty(hash);
 }
 
-static int ftrace_update_code(struct module *mod)
+static void ftrace_update_code(struct module *mod)
 {
 	struct ftrace_page *pg;
 	struct dyn_ftrace *p;
@@ -1959,7 +1959,7 @@ static int ftrace_update_code(struct module *mod)
 		for (i = 0; i < pg->index; i++) {
 			/* If something went wrong, bail without enabling anything */
 			if (unlikely(ftrace_disabled))
-				return -1;
+				return;
 
 			p = &pg->records[i];
 			p->flags = ref;

kernel/trace/ftrace.c static int ftrace_update_code(struct module *mod) · line 1972

Quoted 7 lines
kernel/trace/ftrace.c +2 -2
@@ -1968,8 +1968,8 @@ static int ftrace_update_code(struct module *mod)
 			 * Do the initial record conversion from mcount jump
 			 * to the NOP instructions.
 			 */
-			if (!ftrace_code_disable(mod, p))
-				break;
+			if (WARN_ON_ONCE(!ftrace_code_disable(mod, p)))
+				return;

Why the warning? If ftrace_disabled is set, something broke a long time ago, and the ftrace_bug gives its own warning.

Quoted 1 line

I don't think this is needed.

right, I missed the ftrace_disabled case..

About the ftrace_update_code/ftrace_process_locs return values.. I still think the void is better, because we dont change the code path in case it fails and all errors are already reported.

jirka