From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Rob Herring <robh@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>
Subject: Re: [PATCH] libperf: xyarray: Add bounds checks to xyarray__entry()
Date: Thu, 15 Apr 2021 16:51:09 -0300 [thread overview]
Message-ID: <YHiZLbHBsnBkVzbZ@kernel.org> (raw)
In-Reply-To: <YHiYkhBKWRYA6WRC@kernel.org>
Em Thu, Apr 15, 2021 at 04:48:34PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Apr 15, 2021 at 04:46:46PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Wed, Apr 14, 2021 at 03:53:36PM -0500, Rob Herring escreveu:
> > > On Wed, Apr 14, 2021 at 3:25 PM Namhyung Kim <namhyung@kernel.org> wrote:
> > > > > +static inline void *xyarray__entry(struct xyarray *xy, int x, int y)
> > > > > +{
> > > > > + if (x >= xy->max_x || y >= xy->max_y)
> > > > > + return NULL;
> > > >
> > > > Maybe better to check negatives as well.
> > >
> > > max_x and max_y are size_t and unsigned, so x and y will be promoted
> > > to unsigned and the check will still work.
> >
> > Fair enough, applied.
>
> So...:
>
> CC /tmp/build/perf/builtin-script.o
> In file included from xyarray.c:2:
> /home/acme/git/perf/tools/lib/perf/include/internal/xyarray.h: In function ‘xyarray__entry’:
> /home/acme/git/perf/tools/lib/perf/include/internal/xyarray.h:28:8: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
> 28 | if (x >= xy->max_x || y >= xy->max_y)
> | ^~
> /home/acme/git/perf/tools/lib/perf/include/internal/xyarray.h:28:26: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
> 28 | if (x >= xy->max_x || y >= xy->max_y)
> | ^~
> cc1: all warnings being treated as errors
>
>
> Fedora 33's gcc complains, so I'll cast it to size_t.
> > > It's probably better to change the args to size_t though. And perhaps
> > > on xyarray__new(), xyarray__max_y(), and xyarray__max_x() as well.
So I did this, should be enough:
diff --git a/tools/lib/perf/include/internal/xyarray.h b/tools/lib/perf/include/internal/xyarray.h
index f0896c00b4940016..f10af3da7b21cc15 100644
--- a/tools/lib/perf/include/internal/xyarray.h
+++ b/tools/lib/perf/include/internal/xyarray.h
@@ -23,7 +23,7 @@ static inline void *__xyarray__entry(struct xyarray *xy, int x, int y)
return &xy->contents[x * xy->row_size + y * xy->entry_size];
}
-static inline void *xyarray__entry(struct xyarray *xy, int x, int y)
+static inline void *xyarray__entry(struct xyarray *xy, size_t x, size_t y)
{
if (x >= xy->max_x || y >= xy->max_y)
return NULL;
next prev parent reply other threads:[~2021-04-15 19:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-14 19:57 [PATCH] libperf: xyarray: Add bounds checks to xyarray__entry() Rob Herring
2021-04-14 20:25 ` Namhyung Kim
2021-04-14 20:53 ` Rob Herring
2021-04-15 19:46 ` Arnaldo Carvalho de Melo
2021-04-15 19:48 ` Arnaldo Carvalho de Melo
2021-04-15 19:51 ` Arnaldo Carvalho de Melo [this message]
2021-04-15 20:02 ` Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YHiZLbHBsnBkVzbZ@kernel.org \
--to=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.