7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pengpeng Hou [ Upstream commit 988995c0552b6213b6bf16cea57258d4842c1488 ] expr_str() allocates a temporary expression buffer and manually frees it on some error paths. Convert the buffer to __free(kfree) and return it with return_ptr() on success. This keeps ownership handling separate from the later ERR_PTR() conversion and string-bound change. Link: https://patch.msgid.link/20260611055945.22348-2-pengpeng@iscas.ac.cn Signed-off-by: Pengpeng Hou Signed-off-by: Steven Rostedt Stable-dep-of: a0777b9e5315 ("tracing: Fix NULL dereference when copying keys for a field variable") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_events_hist.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1758,7 +1758,7 @@ static void expr_field_str(struct hist_f static char *expr_str(struct hist_field *field, unsigned int level) { - char *expr; + char *expr __free(kfree) = NULL; if (level > 1) return NULL; @@ -1769,7 +1769,7 @@ static char *expr_str(struct hist_field if (!field->operands[0]) { expr_field_str(field, expr); - return expr; + return_ptr(expr); } if (field->operator == FIELD_OP_UNARY_MINUS) { @@ -1777,16 +1777,15 @@ static char *expr_str(struct hist_field strcat(expr, "-("); subexpr = expr_str(field->operands[0], ++level); - if (!subexpr) { - kfree(expr); + if (!subexpr) return NULL; - } + strcat(expr, subexpr); strcat(expr, ")"); kfree(subexpr); - return expr; + return_ptr(expr); } expr_field_str(field->operands[0], expr); @@ -1805,13 +1804,12 @@ static char *expr_str(struct hist_field strcat(expr, "*"); break; default: - kfree(expr); return NULL; } expr_field_str(field->operands[1], expr); - return expr; + return_ptr(expr); } /*