Skip to content

Commit 6e4cf65

Browse files
tzanussirostedt
authored andcommitted
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. 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>
1 parent 432480c commit 6e4cf65

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎kernel/trace/tracing_map.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,13 @@ static void tracing_map_free_elts(struct tracing_map *map)
366366
if (!map->elts)
367367
return;
368368

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

372374
tracing_map_array_free(map->elts);
375+
map->elts = NULL;
373376
}
374377

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

384387
for (i = 0; i < map->max_elts; i++) {
385388
*(TRACING_MAP_ELT(map->elts, i)) = tracing_map_elt_alloc(map);
386-
if (!(*(TRACING_MAP_ELT(map->elts, i)))) {
389+
if (IS_ERR(*(TRACING_MAP_ELT(map->elts, i)))) {
390+
*(TRACING_MAP_ELT(map->elts, i)) = NULL;
387391
tracing_map_free_elts(map);
388392

389393
return -ENOMEM;

0 commit comments

Comments
 (0)