From: Kent Overstreet <kent.overstreet@linux.dev>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org,
Kent Overstreet <kent.overstreet@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>
Subject: [PATCH 07/11] tracing: trace_events_synth: Convert to printbuf
Date: Mon, 15 Aug 2022 13:26:09 -0400 [thread overview]
Message-ID: <20220815172613.621627-8-kent.overstreet@linux.dev> (raw)
In-Reply-To: <20220815172613.621627-1-kent.overstreet@linux.dev>
From: Kent Overstreet <kent.overstreet@gmail.com>
This converts from seq_buf to printbuf.
This code was using seq_buf for building up dynamically allocated
strings; the conversion uses printbuf's heap allocation functionality to
simplify things (no longer need to calculate size of the output string).
Also, alphabetize the #includes.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
---
kernel/trace/trace_events_synth.c | 51 ++++++++++---------------------
1 file changed, 16 insertions(+), 35 deletions(-)
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index 5e8c07aef0..720c75429c 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -5,13 +5,14 @@
* Copyright (C) 2015, 2020 Tom Zanussi <tom.zanussi@linux.intel.com>
*/
-#include <linux/module.h>
#include <linux/kallsyms.h>
-#include <linux/security.h>
+#include <linux/module.h>
#include <linux/mutex.h>
+#include <linux/printbuf.h>
+#include <linux/rculist.h>
+#include <linux/security.h>
#include <linux/slab.h>
#include <linux/stacktrace.h>
-#include <linux/rculist.h>
#include <linux/tracefs.h>
/* for gfp flag names */
@@ -611,7 +612,7 @@ static struct synth_field *parse_synth_field(int argc, char **argv,
const char *prefix = NULL, *field_type = argv[0], *field_name, *array;
struct synth_field *field;
int len, ret = -ENOMEM;
- struct seq_buf s;
+ struct printbuf buf;
ssize_t size;
if (!strcmp(field_type, "unsigned")) {
@@ -654,28 +655,16 @@ static struct synth_field *parse_synth_field(int argc, char **argv,
goto free;
}
- len = strlen(field_type) + 1;
-
- if (array)
- len += strlen(array);
-
- if (prefix)
- len += strlen(prefix);
-
- field->type = kzalloc(len, GFP_KERNEL);
- if (!field->type)
- goto free;
-
- seq_buf_init(&s, field->type, len);
+ buf = PRINTBUF;
if (prefix)
- seq_buf_puts(&s, prefix);
- seq_buf_puts(&s, field_type);
+ prt_str(&buf, prefix);
+ prt_str(&buf, field_type);
if (array)
- seq_buf_puts(&s, array);
- if (WARN_ON_ONCE(!seq_buf_buffer_left(&s)))
+ prt_str(&buf, array);
+ if (buf.allocation_failure)
goto free;
- s.buffer[s.len] = '\0';
+ field->type = buf.buf;
size = synth_field_size(field->type);
if (size < 0) {
@@ -687,23 +676,15 @@ static struct synth_field *parse_synth_field(int argc, char **argv,
goto free;
} else if (size == 0) {
if (synth_field_is_string(field->type)) {
- char *type;
-
- len = sizeof("__data_loc ") + strlen(field->type) + 1;
- type = kzalloc(len, GFP_KERNEL);
- if (!type)
- goto free;
-
- seq_buf_init(&s, type, len);
- seq_buf_puts(&s, "__data_loc ");
- seq_buf_puts(&s, field->type);
+ buf = PRINTBUF;
+ prt_str(&buf, "__data_loc ");
+ prt_str(&buf, field->type);
- if (WARN_ON_ONCE(!seq_buf_buffer_left(&s)))
+ if (buf.allocation_failure)
goto free;
- s.buffer[s.len] = '\0';
kfree(field->type);
- field->type = type;
+ field->type = buf.buf;
field->is_dynamic = true;
size = sizeof(u64);
--
2.36.1
next prev parent reply other threads:[~2022-08-15 17:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-15 17:26 Printbufs v6 Kent Overstreet
2022-08-15 17:26 ` [PATCH 01/11] mm/memcontrol.c: Convert to printbuf Kent Overstreet
2022-08-15 17:26 ` [PATCH 02/11] clk: tegra: bpmp: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 03/11] tools/testing/nvdimm: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 04/11] powerpc: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 05/11] x86/resctrl: " Kent Overstreet
2022-08-15 17:26 ` [PATCH 06/11] PCI/P2PDMA: " Kent Overstreet
2022-08-15 17:26 ` Kent Overstreet [this message]
2022-08-15 17:43 ` [PATCH 07/11] tracing: trace_events_synth: " Steven Rostedt
2022-08-15 17:58 ` Kent Overstreet
2022-08-15 18:28 ` Steven Rostedt
2022-08-15 17:26 ` [PATCH 08/11] d_path: prt_path() Kent Overstreet
2022-08-15 17:26 ` [PATCH 09/11] ACPI/APEI: Add missing include Kent Overstreet
2022-08-15 17:26 ` [PATCH 10/11] seq_buf: Move to kernel/tracing Kent Overstreet
2022-08-15 17:26 ` [PATCH 11/11] MAINTAINERS: Add entry for printbufs Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220815172613.621627-8-kent.overstreet@linux.dev \
--to=kent.overstreet@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=kent.overstreet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).