[PATCH v2 01/13] perf pmu: Simplify an asprintf error message

Ian Rogers posted 13 patches 2 months, 2 weeks ago
There is a newer version of this series
[PATCH v2 01/13] perf pmu: Simplify an asprintf error message
Posted by Ian Rogers 2 months, 2 weeks ago
Use ifs rather than ?: to avoid a large compound statement.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/pmu.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 61bdda01a05a..779db2ac06f0 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1466,13 +1466,12 @@ static int pmu_config_term(const struct perf_pmu *pmu,
 		if (err) {
 			char *err_str;
 
-			parse_events_error__handle(err, term->err_val,
-				asprintf(&err_str,
-				    "value too big for format (%s), maximum is %llu",
-				    format->name, (unsigned long long)max_val) < 0
-				    ? strdup("value too big for format")
-				    : err_str,
-				    NULL);
+			if (asprintf(&err_str,
+				     "value too big for format (%s), maximum is %llu",
+				     format->name, (unsigned long long)max_val) < 0) {
+				err_str = strdup("value too big for format");
+			}
+			parse_events_error__handle(err, term->err_val, err_str, /*help=*/NULL);
 			return -EINVAL;
 		}
 		/*
-- 
2.46.0.662.g92d0881bb0-goog
Re: [PATCH v2 01/13] perf pmu: Simplify an asprintf error message
Posted by Arnaldo Carvalho de Melo 2 months, 2 weeks ago
On Thu, Sep 12, 2024 at 12:03:28PM -0700, Ian Rogers wrote:
> Use ifs rather than ?: to avoid a large compound statement.

Cherry picked this one.

- Arnaldo
 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/pmu.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 61bdda01a05a..779db2ac06f0 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -1466,13 +1466,12 @@ static int pmu_config_term(const struct perf_pmu *pmu,
>  		if (err) {
>  			char *err_str;
>  
> -			parse_events_error__handle(err, term->err_val,
> -				asprintf(&err_str,
> -				    "value too big for format (%s), maximum is %llu",
> -				    format->name, (unsigned long long)max_val) < 0
> -				    ? strdup("value too big for format")
> -				    : err_str,
> -				    NULL);
> +			if (asprintf(&err_str,
> +				     "value too big for format (%s), maximum is %llu",
> +				     format->name, (unsigned long long)max_val) < 0) {
> +				err_str = strdup("value too big for format");
> +			}
> +			parse_events_error__handle(err, term->err_val, err_str, /*help=*/NULL);
>  			return -EINVAL;
>  		}
>  		/*
> -- 
> 2.46.0.662.g92d0881bb0-goog
>