On Mon, Sep 14, 2020 at 6:05 AM Jiri Olsa <jo...@kernel.org> wrote:
>
> Adding build_id__is_defined helper to check build id
> is defined and is != zero build id.
>
> Signed-off-by: Jiri Olsa <jo...@kernel.org>
> ---
>  tools/perf/util/build-id.c | 11 +++++++++++
>  tools/perf/util/build-id.h |  1 +
>  2 files changed, 12 insertions(+)
>
> diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> index 31207b6e2066..bdee4e08e60d 100644
> --- a/tools/perf/util/build-id.c
> +++ b/tools/perf/util/build-id.c
> @@ -902,3 +902,14 @@ bool perf_session__read_build_ids(struct perf_session 
> *session, bool with_hits)
>
>         return ret;
>  }
> +
> +bool build_id__is_defined(const u8 *build_id)
> +{
> +       static u8 zero[BUILD_ID_SIZE];
> +       int err = 0;
> +
> +       if (build_id)
> +               err = memcmp(build_id, &zero, BUILD_ID_SIZE);
> +
> +       return err ? true : false;
> +}

I think this is a bit confusing.. How about this?

  bool ret = false;
  if (build_id)
      ret = memcmp(...);
  return ret;

Or, it can be a oneliner..

Thanks
Namhyung


> diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
> index aad419bb165c..1ceede45c231 100644
> --- a/tools/perf/util/build-id.h
> +++ b/tools/perf/util/build-id.h
> @@ -14,6 +14,7 @@ extern struct perf_tool build_id__mark_dso_hit_ops;
>  struct dso;
>  struct feat_fd;
>
> +bool build_id__is_defined(const u8 *build_id);
>  int build_id__sprintf(const u8 *build_id, int len, char *bf);
>  int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id);
>  int filename__sprintf_build_id(const char *pathname, char *sbuild_id);
> --
> 2.26.2
>

Reply via email to