lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM9d7cgraWne_NRGFqscWbYSx5nue_A2fJCQ-OaQBTC3g0eijg@mail.gmail.com>
Date:   Thu, 2 Jun 2022 14:37:20 -0700
From:   Namhyung Kim <namhyung@...nel.org>
To:     Ravi Bangoria <ravi.bangoria@....com>
Cc:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        Kan Liang <kan.liang@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
        Peter Zijlstra <peterz@...radead.org>, rrichter@....com,
        Ingo Molnar <mingo@...hat.com>,
        Mark Rutland <mark.rutland@....com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Borislav Petkov <bp@...en8.de>,
        James Clark <james.clark@....com>,
        Leo Yan <leo.yan@...aro.org>, Andi Kleen <ak@...ux.intel.com>,
        Stephane Eranian <eranian@...gle.com>, like.xu.linux@...il.com,
        x86@...nel.org,
        linux-perf-users <linux-perf-users@...r.kernel.org>,
        linux-kernel <linux-kernel@...r.kernel.org>,
        Sandipan Das <sandipan.das@....com>, ananth.narayan@....com,
        Kim Phillips <kim.phillips@....com>, santosh.shukla@....com
Subject: Re: [PATCH v5 4/8] perf headers: Store pmu caps in an array of strings

On Tue, May 31, 2022 at 8:28 PM Ravi Bangoria <ravi.bangoria@....com> wrote:
>
> Currently all capabilities are stored in a single string separated
> by NULL character. Instead, store them in an array which makes
> searching of capability easier.
>
> Signed-off-by: Ravi Bangoria <ravi.bangoria@....com>
> ---
[SNIP]
> @@ -3231,12 +3226,16 @@ static int process_per_cpu_pmu_caps(struct feat_fd *ff, int *nr_cpu_pmu_caps,
>                 if (!value)
>                         goto free_name;
>
> -               if (strbuf_addf(&sb, "%s=%s", name, value) < 0)
> +               name_size = strlen(name);
> +               value_size = strlen(value);
> +               ptr = zalloc(sizeof(char) * (name_size + value_size + 2));
> +               if (!ptr)
>                         goto free_value;
>
> -               /* include a NULL character at the end */
> -               if (strbuf_add(&sb, "", 1) < 0)
> -                       goto free_value;
> +               memcpy(ptr, name, name_size);
> +               ptr[name_size] = '=';
> +               memcpy(ptr + name_size + 1, value, value_size);

What about using asprintf() instead?

Thanks,
Namhyung


> +               (*cpu_pmu_caps)[i] = ptr;
>
>                 if (!strcmp(name, "branches"))
>                         *max_branches = atoi(value);
> @@ -3244,7 +3243,7 @@ static int process_per_cpu_pmu_caps(struct feat_fd *ff, int *nr_cpu_pmu_caps,
>                 free(value);
>                 free(name);
>         }
> -       *cpu_pmu_caps = strbuf_detach(&sb, NULL);
> +       *nr_cpu_pmu_caps = nr_caps;
>         return 0;
>
>  free_value:
> @@ -3252,16 +3251,24 @@ static int process_per_cpu_pmu_caps(struct feat_fd *ff, int *nr_cpu_pmu_caps,
>  free_name:
>         free(name);
>  error:
> -       strbuf_release(&sb);
> +       for (; i > 0; i--)
> +               free((*cpu_pmu_caps)[i - 1]);
> +       free(*cpu_pmu_caps);
> +       *cpu_pmu_caps = NULL;
> +       *nr_cpu_pmu_caps = 0;
>         return -1;
>  }
>
>  static int process_cpu_pmu_caps(struct feat_fd *ff,
>                                 void *data __maybe_unused)
>  {
> -       return process_per_cpu_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps,
> +       int ret = process_per_cpu_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps,
>                                         &ff->ph->env.cpu_pmu_caps,
>                                         &ff->ph->env.max_branches);
> +
> +       if (!ret && !ff->ph->env.cpu_pmu_caps)
> +               pr_debug("cpu pmu capabilities not available\n");
> +       return ret;
>  }
>
>  static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff,
> @@ -3270,6 +3277,7 @@ static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff,
>         struct hybrid_cpc_node *nodes;
>         u32 nr_pmu, i;
>         int ret;
> +       int j;
>
>         if (do_read_u32(ff, &nr_pmu))
>                 return -1;
> @@ -3297,6 +3305,8 @@ static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff,
>                         ret = -1;
>                         goto err;
>                 }
> +               if (!n->nr_cpu_pmu_caps)
> +                       pr_debug("%s pmu capabilities not available\n", n->pmu_name);
>         }
>
>         ff->ph->env.nr_hybrid_cpc_nodes = nr_pmu;
> @@ -3305,6 +3315,8 @@ static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff,
>
>  err:
>         for (i = 0; i < nr_pmu; i++) {
> +               for (j = 0; j < nodes[i].nr_cpu_pmu_caps; j++)
> +                       free(nodes[i].cpu_pmu_caps[j]);
>                 free(nodes[i].cpu_pmu_caps);
>                 free(nodes[i].pmu_name);
>         }
> --
> 2.31.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ