linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing/ring-buffer: hide unused last_boot_fops
@ 2024-07-19 10:26 Arnd Bergmann
  2024-07-19 13:56 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2024-07-19 10:26 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Arnd Bergmann, Mathieu Desnoyers, Zheng Yejian, Vincent Donnefort,
	Huang Yiwei, Tzvetomir Stoyanov (VMware), linux-kernel,
	linux-trace-kernel

From: Arnd Bergmann <arnd@arndb.de>

This variable is used only in an #ifdef, which causes a W=1 warning
with some compilers:

kernel/trace/trace.c:7570:37: error: 'last_boot_fops' defined but not used [-Werror=unused-const-variable=]
 7570 | static const struct file_operations last_boot_fops = {

Guard this one with the same #ifdef.

Fixes: 7a1d1e4b9639 ("tracing/ring-buffer: Add last_boot_info file to boot instance")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
Alternatively it could be marked as __maybe_unused, but I tried to follow
the style used in this file.
---
 kernel/trace/trace.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 5462fb10ff64..6ab24213d496 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6913,6 +6913,7 @@ tracing_total_entries_read(struct file *filp, char __user *ubuf,
 	return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
 }
 
+#ifdef CONFIG_TRACER_SNAPSHOT
 static ssize_t
 tracing_last_boot_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
 {
@@ -6927,6 +6928,7 @@ tracing_last_boot_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t
 
 	return simple_read_from_buffer(ubuf, cnt, ppos, buf, seq_buf_used(&seq));
 }
+#endif
 
 static int tracing_buffer_meta_open(struct inode *inode, struct file *filp)
 {
@@ -7567,12 +7569,14 @@ static const struct file_operations trace_time_stamp_mode_fops = {
 	.release	= tracing_single_release_tr,
 };
 
+#ifdef CONFIG_TRACER_SNAPSHOT
 static const struct file_operations last_boot_fops = {
 	.open		= tracing_open_generic_tr,
 	.read		= tracing_last_boot_read,
 	.llseek		= generic_file_llseek,
 	.release	= tracing_release_generic_tr,
 };
+#endif
 
 #ifdef CONFIG_TRACER_SNAPSHOT
 static const struct file_operations snapshot_fops = {
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tracing/ring-buffer: hide unused last_boot_fops
  2024-07-19 10:26 [PATCH] tracing/ring-buffer: hide unused last_boot_fops Arnd Bergmann
@ 2024-07-19 13:56 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2024-07-19 13:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masami Hiramatsu, Arnd Bergmann, Mathieu Desnoyers, Zheng Yejian,
	Vincent Donnefort, Huang Yiwei, Tzvetomir Stoyanov (VMware),
	linux-kernel, linux-trace-kernel

On Fri, 19 Jul 2024 12:26:33 +0200
Arnd Bergmann <arnd@kernel.org> wrote:

> From: Arnd Bergmann <arnd@arndb.de>
> 
> This variable is used only in an #ifdef, which causes a W=1 warning
> with some compilers:
> 
> kernel/trace/trace.c:7570:37: error: 'last_boot_fops' defined but not used [-Werror=unused-const-variable=]
>  7570 | static const struct file_operations last_boot_fops = {
> 
> Guard this one with the same #ifdef.
> 
> Fixes: 7a1d1e4b9639 ("tracing/ring-buffer: Add last_boot_info file to boot instance")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Actually "last_boot_info" and snapshot should be mutually exclusive.
That is, an instance can have a snapshot or the "last_boot_info" but not
both. The real fix is:

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 5462fb10ff64..0d1841b3363e 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -9828,15 +9828,15 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
 	if (ftrace_create_function_files(tr, d_tracer))
 		MEM_FAIL(1, "Could not allocate function filter files");
 
-#ifdef CONFIG_TRACER_SNAPSHOT
 	if (tr->range_addr_start) {
 		trace_create_file("last_boot_info", TRACE_MODE_READ, d_tracer,
 				  tr, &last_boot_fops);
+#ifdef CONFIG_TRACER_SNAPSHOT
 	} else {
 		trace_create_file("snapshot", TRACE_MODE_WRITE, d_tracer,
 				  tr, &snapshot_fops);
-	}
 #endif
+	}
 
 	trace_create_file("error_log", TRACE_MODE_WRITE, d_tracer,
 			  tr, &tracing_err_log_fops);


I'll write up a patch and give you the "reported-by".

Thanks!

-- Steve

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-19 13:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-19 10:26 [PATCH] tracing/ring-buffer: hide unused last_boot_fops Arnd Bergmann
2024-07-19 13:56 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).