Skip to content

Commit 59927cb

Browse files
ZhiqiangLiu26rostedt
authored andcommitted
tracing: Use free_trace_buffer() in allocate_trace_buffers()
In allocate_trace_buffers(), if allocating tr->max_buffer fails, we can directly call free_trace_buffer to free tr->array_buffer. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Zhiqiang Liu <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 4c3d2f9 commit 59927cb

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

kernel/trace/trace.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9101,6 +9101,16 @@ allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size
91019101
return 0;
91029102
}
91039103

9104+
static void free_trace_buffer(struct array_buffer *buf)
9105+
{
9106+
if (buf->buffer) {
9107+
ring_buffer_free(buf->buffer);
9108+
buf->buffer = NULL;
9109+
free_percpu(buf->data);
9110+
buf->data = NULL;
9111+
}
9112+
}
9113+
91049114
static int allocate_trace_buffers(struct trace_array *tr, int size)
91059115
{
91069116
int ret;
@@ -9113,10 +9123,7 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)
91139123
ret = allocate_trace_buffer(tr, &tr->max_buffer,
91149124
allocate_snapshot ? size : 1);
91159125
if (MEM_FAIL(ret, "Failed to allocate trace buffer\n")) {
9116-
ring_buffer_free(tr->array_buffer.buffer);
9117-
tr->array_buffer.buffer = NULL;
9118-
free_percpu(tr->array_buffer.data);
9119-
tr->array_buffer.data = NULL;
9126+
free_trace_buffer(&tr->array_buffer);
91209127
return -ENOMEM;
91219128
}
91229129
tr->allocated_snapshot = allocate_snapshot;
@@ -9131,16 +9138,6 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)
91319138
return 0;
91329139
}
91339140

9134-
static void free_trace_buffer(struct array_buffer *buf)
9135-
{
9136-
if (buf->buffer) {
9137-
ring_buffer_free(buf->buffer);
9138-
buf->buffer = NULL;
9139-
free_percpu(buf->data);
9140-
buf->data = NULL;
9141-
}
9142-
}
9143-
91449141
static void free_trace_buffers(struct trace_array *tr)
91459142
{
91469143
if (!tr)

0 commit comments

Comments
 (0)