All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Pengpeng Hou <pengpeng@iscas.ac.cn>
Subject: [for-next][PATCH 07/16] tracing: Return ERR_PTR() from expr_str()
Date: Tue, 28 Jul 2026 20:05:30 -0400	[thread overview]
Message-ID: <20260729000556.311697849@kernel.org> (raw)
In-Reply-To: 20260729000523.093060274@kernel.org

From: Pengpeng Hou <pengpeng@iscas.ac.cn>

expr_str() currently reports all failure cases as NULL, so callers cannot
distinguish invalid recursion depth from allocation failure or later
string construction errors.

Return ERR_PTR()-encoded errors from expr_str() and make parse_unary()
and parse_expr() propagate them. Clear expr->name before destroying the
hist field so the error pointer is not freed as a string.

Link: https://patch.msgid.link/20260611055945.22348-3-pengpeng@iscas.ac.cn
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace_events_hist.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 40ae7379cbf5..dee2710da66e 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -1762,11 +1762,11 @@ static char *expr_str(struct hist_field *field, unsigned int level)
 	char *expr __free(kfree) = NULL;
 
 	if (level > 1)
-		return NULL;
+		return ERR_PTR(-EINVAL);
 
 	expr = kzalloc(MAX_FILTER_STR_VAL, GFP_KERNEL);
 	if (!expr)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	if (!field->operands[0]) {
 		expr_field_str(field, expr);
@@ -1778,8 +1778,8 @@ static char *expr_str(struct hist_field *field, unsigned int level)
 
 		strcat(expr, "-(");
 		subexpr = expr_str(field->operands[0], ++level);
-		if (!subexpr)
-			return NULL;
+		if (IS_ERR(subexpr))
+			return subexpr;
 
 		strcat(expr, subexpr);
 		strcat(expr, ")");
@@ -1805,7 +1805,7 @@ static char *expr_str(struct hist_field *field, unsigned int level)
 		strcat(expr, "*");
 		break;
 	default:
-		return NULL;
+		return ERR_PTR(-EINVAL);
 	}
 
 	expr_field_str(field->operands[1], expr);
@@ -2622,6 +2622,11 @@ static struct hist_field *parse_unary(struct hist_trigger_data *hist_data,
 	expr->is_signed = operand1->is_signed;
 	expr->operator = FIELD_OP_UNARY_MINUS;
 	expr->name = expr_str(expr, 0);
+	if (IS_ERR(expr->name)) {
+		ret = PTR_ERR(expr->name);
+		expr->name = NULL;
+		goto free;
+	}
 	expr->type = kstrdup_const(operand1->type, GFP_KERNEL);
 	if (!expr->type) {
 		ret = -ENOMEM;
@@ -2834,6 +2839,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
 		destroy_hist_field(operand1, 0);
 
 		expr->name = expr_str(expr, 0);
+		if (IS_ERR(expr->name)) {
+			ret = PTR_ERR(expr->name);
+			expr->name = NULL;
+			goto free_expr;
+		}
 	} else {
 		/* The operand sizes should be the same, so just pick one */
 		expr->size = operand1->size;
@@ -2847,6 +2857,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
 		}
 
 		expr->name = expr_str(expr, 0);
+		if (IS_ERR(expr->name)) {
+			ret = PTR_ERR(expr->name);
+			expr->name = NULL;
+			goto free_expr;
+		}
 	}
 
 	return expr;
-- 
2.53.0



  parent reply	other threads:[~2026-07-29  0:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29  0:05 [for-next][PATCH 00/16] tracing: Updates for v7.3 Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 01/16] bpf: Make btf_get_module_btf() and btf_relocate_id() non-static Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 02/16] tracing: Expose tracepoint BTF ids via tracefs Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 03/16] selftests/bpf: Add test for tracepoint btf_ids tracefs file Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 04/16] tracing: Point constant hist field type to string literal Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 05/16] kernel/trace/trace_printk: Use kstrdup() instead of kmalloc() and strcpy() Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 06/16] tracing: Use __free() for expr_str() buffer Steven Rostedt
2026-07-29  0:05 ` Steven Rostedt [this message]
2026-07-29  0:05 ` [for-next][PATCH 08/16] tracing: Bound histogram expression strings with seq_buf Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 09/16] tracing/user_events: Use seq_putc() in two functions Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 10/16] tracing/user_events: Replace a seq_printf() call by seq_puts() in user_seq_show() Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 11/16] fgraph: Use trace_seq_putc() in print_graph_return() Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 12/16] tracing: Reject invalid preemptirq_delay_test CPU affinity Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 13/16] samples/ftrace: Prevent division by zero when nr_function_calls is zero Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 14/16] tracing: Warn when an event dereferences a pointer in TP_printk() Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 15/16] tracing: Use strscpy() instead of strcpy() in trace_sched_switch Steven Rostedt
2026-07-29  0:05 ` [for-next][PATCH 16/16] tracing: Use seq_buf for string concatenation Steven Rostedt

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=20260729000556.311697849@kernel.org \
    --to=rostedt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=pengpeng@iscas.ac.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.