public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Daniel Bristot de Oliveira <bristot@kernel.org>,
	jianchunfu <jianchunfu@cmss.chinamobile.com>
Subject: [for-next][PATCH 1/4] rtla/utils: Use calloc and check the potential memory allocation failure
Date: Sun, 31 Jul 2022 17:09:19 -0400	[thread overview]
Message-ID: <20220731210939.214097203@goodmis.org> (raw)
In-Reply-To: 20220731210918.097591536@goodmis.org

From: jianchunfu <jianchunfu@cmss.chinamobile.com>

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: 7d0dc9576dc3 ("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>
---
 tools/tracing/rtla/src/utils.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index 5352167a1e75..5ae2fa96fde1 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -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);
-- 
2.35.1

  reply	other threads:[~2022-07-31 21:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-31 21:09 [for-next][PATCH 0/4] rtla: Updates for 5.20 Steven Rostedt
2022-07-31 21:09 ` Steven Rostedt [this message]
2022-07-31 21:09 ` [for-next][PATCH 2/4] rtla: Fix Makefile when called from -C tools/ Steven Rostedt
2022-07-31 21:09 ` [for-next][PATCH 3/4] rtla: Fix double free Steven Rostedt
2022-07-31 21:09 ` [for-next][PATCH 4/4] rtla: Define syscall numbers for riscv Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220731210939.214097203@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=bristot@kernel.org \
    --cc=jianchunfu@cmss.chinamobile.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox