Skip to content

Commit

Permalink
gcov: simplify buffer allocation
Browse files Browse the repository at this point in the history
Use just a single vmalloc() with struct_size() instead of a separate
kmalloc() for the iter struct.

Link: https://lkml.kernel.org/r/20210315235453.b6de4a92096e.Iac40a5166589cefbff8449e466bd1b38ea7a17af@changeid
Signed-off-by: Johannes Berg <[email protected]>
Cc: Peter Oberparleiter <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jmberg-intel authored and torvalds committed May 7, 2021
1 parent 7a1d55b commit 3180c44
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions kernel/gcov/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ __setup("gcov_persist=", gcov_persist_setup);
*/
struct gcov_iterator {
struct gcov_info *info;
void *buffer;
size_t size;
loff_t pos;
char buffer[];
};

/**
Expand All @@ -111,25 +111,20 @@ struct gcov_iterator {
static struct gcov_iterator *gcov_iter_new(struct gcov_info *info)
{
struct gcov_iterator *iter;
size_t size;

/* Dry-run to get the actual buffer size. */
size = convert_to_gcda(NULL, info);

iter = kzalloc(sizeof(struct gcov_iterator), GFP_KERNEL);
iter = vmalloc(struct_size(iter, buffer, size));
if (!iter)
goto err_free;
return NULL;

iter->info = info;
/* Dry-run to get the actual buffer size. */
iter->size = convert_to_gcda(NULL, info);
iter->buffer = vmalloc(iter->size);
if (!iter->buffer)
goto err_free;

iter->size = size;
convert_to_gcda(iter->buffer, info);

return iter;

err_free:
kfree(iter);
return NULL;
}


Expand All @@ -139,8 +134,7 @@ static struct gcov_iterator *gcov_iter_new(struct gcov_info *info)
*/
static void gcov_iter_free(struct gcov_iterator *iter)
{
vfree(iter->buffer);
kfree(iter);
vfree(iter);
}

/**
Expand Down

0 comments on commit 3180c44

Please sign in to comment.