gcov: simplify buffer allocation
authorJohannes Berg <johannes.berg@intel.com>
Fri, 7 May 2021 01:04:48 +0000 (18:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 7 May 2021 07:26:32 +0000 (00:26 -0700)
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 <johannes.berg@intel.com>
Cc: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/gcov/fs.c

index 2d29e1d..40ea81c 100644 (file)
@@ -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[];
 };
 
 /**
@@ -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;
 }
 
 
@@ -139,8 +134,7 @@ err_free:
  */
 static void gcov_iter_free(struct gcov_iterator *iter)
 {
-       vfree(iter->buffer);
-       kfree(iter);
+       vfree(iter);
 }
 
 /**