Skip to content

Commit

Permalink
tracing: Handle tracing_map_alloc_elts() error path correctly
Browse files Browse the repository at this point in the history
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.

Link: http://lkml.kernel.org/r/f29d03b00bce3aac8cf151a8a30e6c83e5fee66d.1461610073.git.tom.zanussi@linux.intel.com

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Tom Zanussi authored and Steven Rostedt committed Apr 26, 2016
1 parent 432480c commit 6e4cf65
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions kernel/trace/tracing_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit 6e4cf65

Please sign in to comment.