A couple hist trigger fixes
cover 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(-)
Signature · 1 line
1.9.3
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.
--- kernel/trace/tracing_map.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/trace/tracing_map.c +6 -2
@@ -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 ;
Signature · 1 line
1.9.3
PATCH 1/2 tracing: Add check for NULL event field when creating hist field
In reply to Tom ZanussiSmatch 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.
--- kernel/trace/trace_events_hist.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_events_hist.c +3 -0
@@ -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 ;
Signature · 1 line
1.9.3
Quoted 19 lines · On Mon, 25 Apr 2016 14:01:26 -0500 Tom Zanussi <[email protected]>…
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_ERRproblem 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.gittzanussi/hist-trigger-err-fixes
http://git.yoctoproject.org/cgit/cgit.cgi/linux-yocto-contrib/log/?h=tzanussi/hist-trigger-err-fixes
Quoted 8 lines
Tom Zanussi (2):
tracing: Add check for NULL event field when creating hist field
tracing: Handletracing_map_alloc_elts()error path correctlykernel/trace/trace_events_hist.c | 3 +++ kernel/trace/tracing_map.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
Applied.
Thanks Tom,
-- Steve