Commit 3180c44f authored by Johannes Berg's avatar Johannes Berg Committed by Linus Torvalds

gcov: simplify buffer allocation

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@changeidSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7a1d55b9
...@@ -97,9 +97,9 @@ __setup("gcov_persist=", gcov_persist_setup); ...@@ -97,9 +97,9 @@ __setup("gcov_persist=", gcov_persist_setup);
*/ */
struct gcov_iterator { struct gcov_iterator {
struct gcov_info *info; struct gcov_info *info;
void *buffer;
size_t size; size_t size;
loff_t pos; loff_t pos;
char buffer[];
}; };
/** /**
...@@ -111,25 +111,20 @@ struct gcov_iterator { ...@@ -111,25 +111,20 @@ struct gcov_iterator {
static struct gcov_iterator *gcov_iter_new(struct gcov_info *info) static struct gcov_iterator *gcov_iter_new(struct gcov_info *info)
{ {
struct gcov_iterator *iter; 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) if (!iter)
goto err_free; return NULL;
iter->info = info; iter->info = info;
/* Dry-run to get the actual buffer size. */ iter->size = size;
iter->size = convert_to_gcda(NULL, info);
iter->buffer = vmalloc(iter->size);
if (!iter->buffer)
goto err_free;
convert_to_gcda(iter->buffer, info); convert_to_gcda(iter->buffer, info);
return iter; return iter;
err_free:
kfree(iter);
return NULL;
} }
...@@ -139,8 +134,7 @@ static struct gcov_iterator *gcov_iter_new(struct gcov_info *info) ...@@ -139,8 +134,7 @@ static struct gcov_iterator *gcov_iter_new(struct gcov_info *info)
*/ */
static void gcov_iter_free(struct gcov_iterator *iter) static void gcov_iter_free(struct gcov_iterator *iter)
{ {
vfree(iter->buffer); vfree(iter);
kfree(iter);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment