Skip to content

Commit

Permalink
rtla/utils: Use calloc and check the potential memory allocation failure
Browse files Browse the repository at this point in the history
Replace malloc with calloc and add memory allocating check
of mon_cpus before used.

Link: https://lkml.kernel.org/r/20220615073348.6891-1-jianchunfu@cmss.chinamobile.com

Fixes: 7d0dc95 ("rtla/timerlat: Add --dma-latency option")
Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
  • Loading branch information
jianchunfu authored and Steven Rostedt (Google) committed Jul 12, 2022
1 parent 88084a3 commit b5f37a0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/tracing/rtla/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ int parse_cpu_list(char *cpu_list, char **monitored_cpus)

nr_cpus = sysconf(_SC_NPROCESSORS_CONF);

mon_cpus = malloc(nr_cpus * sizeof(char));
memset(mon_cpus, 0, (nr_cpus * sizeof(char)));
mon_cpus = calloc(nr_cpus, sizeof(char));
if (!mon_cpus)
goto err;

for (p = cpu_list; *p; ) {
cpu = atoi(p);
Expand Down

0 comments on commit b5f37a0

Please sign in to comment.