2016-04-25 19:01:32

by Tom Zanussi

[permalink] [raw]
Subject: [PATCH 0/2] A couple hist trigger fixes

These are a couple of small fixes for problems pointed out by Dan
Carpenter.

patch 1, pointed out by Smatch though not actually a bug, cleans up
the code to explicitly check for something that was implied. Thanks
to Steve Rostedt for suggesting the fix.

patch 2 fixes a PTR_ERR problem similar to the one previously
reported by Dan.

The following changes since commit d50c744ecde7ee3ba4d7ffb0e1c55e7a2f6bbc8e:

tracing: Fix unsigned comparison to zero in hist trigger code (2016-04-19 18:56:05 -0400)

are available in the git repository at:

git://git.yoctoproject.org/linux-yocto-contrib.git tzanussi/hist-trigger-err-fixes
http://git.yoctoproject.org/cgit/cgit.cgi/linux-yocto-contrib/log/?h=tzanussi/hist-trigger-err-fixes

Tom Zanussi (2):
tracing: Add check for NULL event field when creating hist field
tracing: Handle tracing_map_alloc_elts() error path correctly

kernel/trace/trace_events_hist.c | 3 +++
kernel/trace/tracing_map.c | 8 ++++++--
2 files changed, 9 insertions(+), 2 deletions(-)

--
1.9.3


2016-04-25 19:01:47

by Tom Zanussi

[permalink] [raw]
Subject: [PATCH 2/2] tracing: Handle tracing_map_alloc_elts() error path correctly

If tracing_map_elt_alloc() fails, it will return ERR_PTR() instead of
NULL, so change the check to IS_ERROR(). We also need to set the
failed entry in the map->elts array to NULL instead of ERR_PTR() so
tracing_map_free_elts() doesn't try freeing an ERR_PTR().

tracing_map_free_elts() should also zero out what it frees so a
reentrant call won't find previously freed elements.

Signed-off-by: Tom Zanussi <[email protected]>
---
kernel/trace/tracing_map.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c
index e0f1729..979f6d6 100644
--- a/kernel/trace/tracing_map.c
+++ b/kernel/trace/tracing_map.c
@@ -366,10 +366,13 @@ static void tracing_map_free_elts(struct tracing_map *map)
if (!map->elts)
return;

- for (i = 0; i < map->max_elts; i++)
+ for (i = 0; i < map->max_elts; i++) {
tracing_map_elt_free(*(TRACING_MAP_ELT(map->elts, i)));
+ *(TRACING_MAP_ELT(map->elts, i)) = NULL;
+ }

tracing_map_array_free(map->elts);
+ map->elts = NULL;
}

static int tracing_map_alloc_elts(struct tracing_map *map)
@@ -383,7 +386,8 @@ static int tracing_map_alloc_elts(struct tracing_map *map)

for (i = 0; i < map->max_elts; i++) {
*(TRACING_MAP_ELT(map->elts, i)) = tracing_map_elt_alloc(map);
- if (!(*(TRACING_MAP_ELT(map->elts, i)))) {
+ if (IS_ERR(*(TRACING_MAP_ELT(map->elts, i)))) {
+ *(TRACING_MAP_ELT(map->elts, i)) = NULL;
tracing_map_free_elts(map);

return -ENOMEM;
--
1.9.3

2016-04-25 19:02:15

by Tom Zanussi

[permalink] [raw]
Subject: [PATCH 1/2] tracing: Add check for NULL event field when creating hist field

Smatch flagged create_hist_field() as possibly being able to
dereference a NULL pointer, although the current code exits in all
cases where the event field could be NULL, so it's not actually a
problem.

Still, to prevent future changes to the code from overlooking new
cases, make the NULL pointer check explicit and warn once in that
case.

Signed-off-by: Tom Zanussi <[email protected]>
---
kernel/trace/trace_events_hist.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index f98b6b3..0c05b8a 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -371,6 +371,9 @@ static struct hist_field *create_hist_field(struct ftrace_event_field *field,
goto out;
}

+ if (WARN_ON_ONCE(!field))
+ goto out;
+
if (is_string_field(field)) {
flags |= HIST_FIELD_FL_STRING;

--
1.9.3

2016-04-26 13:41:32

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 0/2] A couple hist trigger fixes

On Mon, 25 Apr 2016 14:01:26 -0500
Tom Zanussi <[email protected]> wrote:

> These are a couple of small fixes for problems pointed out by Dan
> Carpenter.
>
> patch 1, pointed out by Smatch though not actually a bug, cleans up
> the code to explicitly check for something that was implied. Thanks
> to Steve Rostedt for suggesting the fix.
>
> patch 2 fixes a PTR_ERR problem similar to the one previously
> reported by Dan.
>
> The following changes since commit d50c744ecde7ee3ba4d7ffb0e1c55e7a2f6bbc8e:
>
> tracing: Fix unsigned comparison to zero in hist trigger code (2016-04-19 18:56:05 -0400)
>
> are available in the git repository at:
>
> git://git.yoctoproject.org/linux-yocto-contrib.git tzanussi/hist-trigger-err-fixes
> http://git.yoctoproject.org/cgit/cgit.cgi/linux-yocto-contrib/log/?h=tzanussi/hist-trigger-err-fixes
>
> Tom Zanussi (2):
> tracing: Add check for NULL event field when creating hist field
> tracing: Handle tracing_map_alloc_elts() error path correctly
>
> kernel/trace/trace_events_hist.c | 3 +++
> kernel/trace/tracing_map.c | 8 ++++++--
> 2 files changed, 9 insertions(+), 2 deletions(-)
>

Applied.

Thanks Tom,

-- Steve