perf cputopo: Use struct_size() helper
PATCH 1/1 perf cputopo: Use struct_size() helper
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes.
This code was detected with the help of Coccinelle and, audited and fixed manually.
Signed-off-by Gustavo A. R. Silva <[email protected]>
--- tools/perf/util/cputopo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/cputopo.c +2 -1
@@ -7,6 +7,7 @@#include <api/fs/fs.h> #include <linux/zalloc.h> #include <perf/cpumap.h> +#include <linux/overflow.h> #include "cputopo.h" #include "cpumap.h"
@@ -321,7 +322,7 @@ struct numa_topology *numa_topology__new(void) nr = (u32 ) node_map->nr; - tp =zalloc (sizeof (*tp) +sizeof (tp->nodes[0 ])*nr); + tp =zalloc (struct_size (tp, nodes, nr));if (!tp) goto out;
Signature · 1 line
2.27.0