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]
Date:   Tue, 17 Nov 2020 20:33:13 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Jiri Olsa <jolsa@...hat.com>
Cc:     Ian Rogers <irogers@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
        lkml <linux-kernel@...r.kernel.org>,
        Peter Zijlstra <a.p.zijlstra@...llo.nl>,
        Ingo Molnar <mingo@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Namhyung Kim <namhyung@...nel.org>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Michael Petlan <mpetlan@...hat.com>,
        Song Liu <songliubraving@...com>,
        Stephane Eranian <eranian@...gle.com>,
        Alexey Budankov <alexey.budankov@...ux.intel.com>,
        Andi Kleen <ak@...ux.intel.com>,
        Adrian Hunter <adrian.hunter@...el.com>
Subject: Re: [PATCH 06/24] perf tools: Add build_id__is_defined function

Em Tue, Nov 17, 2020 at 09:53:59PM +0100, Jiri Olsa escreveu:
> On Tue, Nov 17, 2020 at 11:00:37AM -0800, Ian Rogers wrote:
> > On Tue, Nov 17, 2020 at 3:01 AM Jiri Olsa <jolsa@...nel.org> wrote:
> > 
> > > Adding build_id__is_defined helper to check build id
> > > is defined and is != zero build id.
> > >
> > > Signed-off-by: Jiri Olsa <jolsa@...nel.org>
> > > ---
> > >  tools/perf/util/build-id.c | 7 +++++++
> > >  tools/perf/util/build-id.h | 1 +
> > >  2 files changed, 8 insertions(+)
> > >
> > > diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> > > index 6b410c3d52dc..7d9ecc37849c 100644
> > > --- a/tools/perf/util/build-id.c
> > > +++ b/tools/perf/util/build-id.c
> > > @@ -912,3 +912,10 @@ void build_id__init(struct build_id *bid, const u8
> > > *data, size_t size)
> > >         memcpy(bid->data, data, size);
> > >         bid->size = size;
> > >  }
> > > +
> > > +bool build_id__is_defined(const struct build_id *bid)
> > > +{
> > > +       static u8 zero[BUILD_ID_SIZE];
> > > +
> > > +       return bid && bid->size ? memcmp(bid->data, &zero, bid->size) :
> > > false;

> > Fwiw, I find this method to test for zero a little hard to parse - I'm
> 
> heh, it's controversial one, Namhyung commented
> on this one in previous version, so I changed it ;-)
>   https://lore.kernel.org/lkml/CAM9d7cjjGjTN8sDgLZ1PoQZ-sUXWjnVaNdyOVE1yHxq46PrPkw@mail.gmail.com/

So, the kernel has an idiom for this in lib/string.c:

/**
 * memchr_inv - Find an unmatching character in an area of memory.
 * @start: The memory area
 * @c: Find a character other than c
 * @bytes: The size of the area.
 *
 * returns the address of the first character other than @c, or %NULL
 * if the whole buffer contains just @c.
 */
void *memchr_inv(const void *start, int c, size_t bytes)

No need for any array of some particular size :-)

Its been there for a while:

commit 798248206b59acc6e1238c778281419c041891a7
Author: Akinobu Mita <akinobu.mita@...il.com>
Date:   Mon Oct 31 17:08:07 2011 -0700

    lib/string.c: introduce memchr_inv()

    memchr_inv() is mainly used to check whether the whole buffer is filled
    with just a specified byte.

- Arnaldo
 
> 
> > failing as a C programmer :-) Nit, should zero be const?
> 
> right, should be const, will change

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ