* [PATCH v2] rtla/utils: Use calloc and check the potential memory allocation failure
@ 2022-06-15 7:33 jianchunfu
2022-07-08 12:37 ` Daniel Bristot de Oliveira
0 siblings, 1 reply; 3+ messages in thread
From: jianchunfu @ 2022-06-15 7:33 UTC (permalink / raw)
To: bristot, rostedt; +Cc: linux-trace-devel, linux-kernel, jianchunfu
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rtla/utils: Use calloc and check the potential memory allocation failure
2022-06-15 7:33 [PATCH v2] rtla/utils: Use calloc and check the potential memory allocation failure jianchunfu
@ 2022-07-08 12:37 ` Daniel Bristot de Oliveira
2022-07-12 1:17 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Bristot de Oliveira @ 2022-07-08 12:37 UTC (permalink / raw)
To: jianchunfu, rostedt; +Cc: linux-trace-devel, linux-kernel
On 6/15/22 09:33, jianchunfu wrote:
> 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>
Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Thanks!
-- Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] rtla/utils: Use calloc and check the potential memory allocation failure
2022-07-08 12:37 ` Daniel Bristot de Oliveira
@ 2022-07-12 1:17 ` Steven Rostedt
0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-07-12 1:17 UTC (permalink / raw)
To: Daniel Bristot de Oliveira; +Cc: jianchunfu, linux-trace-devel, linux-kernel
On Fri, 8 Jul 2022 14:37:22 +0200
Daniel Bristot de Oliveira <bristot@kernel.org> wrote:
> On 6/15/22 09:33, jianchunfu wrote:
> > 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>
>
> Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
>
Applied, thanks jianchunfu and Daniel!
-- Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-12 1:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15 7:33 [PATCH v2] rtla/utils: Use calloc and check the potential memory allocation failure jianchunfu
2022-07-08 12:37 ` Daniel Bristot de Oliveira
2022-07-12 1:17 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).