From: jianchunfu <jianchunfu@cmss.chinamobile.com>
To: bristot@kernel.org, rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
jianchunfu <jianchunfu@cmss.chinamobile.com>
Subject: [PATCH v2] rtla/utils: Use calloc and check the potential memory allocation failure
Date: Wed, 15 Jun 2022 15:33:48 +0800 [thread overview]
Message-ID: <20220615073348.6891-1-jianchunfu@cmss.chinamobile.com> (raw)
Replace malloc with calloc and add memory allocating check
of mon_cpus before used.
Fixes: 7d0dc9576dc3 ("rtla/timerlat: Add --dma-latency option")
Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
---
V1 -> V2: using calloc, removing the memset and goto err
instead of returning when allocation fails.
---
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 ffaf8ec84..56bdc9962 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -105,8 +105,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.18.4
next reply other threads:[~2022-06-15 7:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-15 7:33 jianchunfu [this message]
2022-07-08 12:37 ` [PATCH v2] rtla/utils: Use calloc and check the potential memory allocation failure Daniel Bristot de Oliveira
2022-07-12 1:17 ` 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=20220615073348.6891-1-jianchunfu@cmss.chinamobile.com \
--to=jianchunfu@cmss.chinamobile.com \
--cc=bristot@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.