Re: [PATCH v5 05/26] perf annotate: Normalize arch__dwarf_regnum() error return values

From: Ian Rogers

Date: Tue Sep 08 2026 - 14:04:37 EST


On Tue, Sep 8, 2026 at 6:05 AM Tengda Wu <wutengda@xxxxxxxxxxxxxxx> wrote:
>
> arch__dwarf_regnum() returns inconsistent error values: early path
> returns -1 while the main lookup returns -ENOENT/-EINVAL from
> get_dwarf_regnum(). Callers only check for -1, so genuine failures
> can slip through.
>
> Normalize all failures to -1 to match the callers' expectation.

This sounds like a bug in the callers but this function is local to
annotate.c and is just a convenience so:

Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

Thanks,
Ian

> Suggested-by: Shuai Xue <xueshuai@xxxxxxxxxxxxxxxxx>
> Signed-off-by: Tengda Wu <wutengda@xxxxxxxxxxxxxxx>
> ---
> tools/perf/util/annotate.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index df70e95a8470..f3d17d153b67 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -2492,7 +2492,7 @@ static int arch__dwarf_regnum(const struct arch *arch, const char *str)
>
> reg = get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e_flags);
> free(regname);
> - return reg;
> + return reg < 0 ? -1 : reg;
> }
>
> /*
> --
> 2.34.1
>