]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tracing/mmiotrace: Add NULL check for mmio_trace_array in logging functions
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Tue, 28 Jul 2026 12:50:00 +0000 (21:50 +0900)
committerSteven Rostedt <rostedt@goodmis.org>
Wed, 29 Jul 2026 18:27:55 +0000 (14:27 -0400)
mmio_trace_rw() and mmio_trace_mapping() retrieve mmio_trace_array into
tr and pass it to __trace_mmiotrace_rw() and __trace_mmiotrace_map().
If these functions are invoked while mmio_trace_array is NULL (e.g. before
initialization or after disabled), accessing tr->array_buffer.buffer will
result in a NULL pointer dereference crash.

Fix this by adding an explicit NULL check for tr at the beginning of
__trace_mmiotrace_rw() and __trace_mmiotrace_map().

Link: https://patch.msgid.link/178524300062.56416.8362487250709962380.stgit@devnote2
Fixes: f984b51e0779 ("ftrace: add mmiotrace plugin")
Assisted-by: Antigravity:gemini-3.6-flash
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/trace_mmiotrace.c

index e064ba3f28cb95d409a9bffe7a00abe0960cf882..df8692c2dea8a50475fa9e45d5186e0f8a768412 100644 (file)
@@ -294,11 +294,15 @@ device_initcall(init_mmio_trace);
 static void __trace_mmiotrace_rw(struct trace_array *tr,
                                struct mmiotrace_rw *rw)
 {
-       struct trace_buffer *buffer = tr->array_buffer.buffer;
+       struct trace_buffer *buffer;
        struct ring_buffer_event *event;
        struct trace_mmiotrace_rw *entry;
        unsigned int trace_ctx;
 
+       if (!tr)
+               return;
+
+       buffer = tr->array_buffer.buffer;
        trace_ctx = tracing_gen_ctx_flags(0);
        event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
                                          sizeof(*entry), trace_ctx);
@@ -321,11 +325,15 @@ void mmio_trace_rw(struct mmiotrace_rw *rw)
 static void __trace_mmiotrace_map(struct trace_array *tr,
                                struct mmiotrace_map *map)
 {
-       struct trace_buffer *buffer = tr->array_buffer.buffer;
+       struct trace_buffer *buffer;
        struct ring_buffer_event *event;
        struct trace_mmiotrace_map *entry;
        unsigned int trace_ctx;
 
+       if (!tr)
+               return;
+
+       buffer = tr->array_buffer.buffer;
        trace_ctx = tracing_gen_ctx_flags(0);
        event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
                                          sizeof(*entry), trace_ctx);