tracing: Return ERR_PTR() from expr_str()

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>
This commit is contained in:
Pengpeng Hou
2026-06-11 13:59:44 +08:00
committed by Steven Rostedt
parent 988995c055
commit a5ca27e8ff

View File

@@ -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;