linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Bristot de Oliveira <bristot@kernel.org>
To: jianchunfu <jianchunfu@cmss.chinamobile.com>
Cc: linux-trace-devel@vger.kernel.org, rostedt@goodmis.org
Subject: Re: [PATCH] rtla/utils: Fix the potential memory allocation failure
Date: Tue, 14 Jun 2022 14:44:54 +0200	[thread overview]
Message-ID: <e9a891e6-586d-46a6-d623-6d25575f62c8@kernel.org> (raw)
In-Reply-To: <20220614093800.8743-1-jianchunfu@cmss.chinamobile.com>

Hi

On 6/14/22 11:38, jianchunfu wrote:
> Add memory allocating check of mon_cpus before used in utils.
> 
Yeah, you found a problem, thanks for you patch! But it needs improvement.

Please, add the Fixes: tag.
Please Cc: linux-kernel

> Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
> ---
>  tools/tracing/rtla/src/utils.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
> index ffaf8ec84..2a86440b3 100644
> --- a/tools/tracing/rtla/src/utils.c
> +++ b/tools/tracing/rtla/src/utils.c
> @@ -106,6 +106,10 @@ int parse_cpu_list(char *cpu_list, char **monitored_cpus)
>  	nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
>  
>  	mon_cpus = malloc(nr_cpus * sizeof(char));
> +	if (!mon_cpus) {
> +		perror("Failed to allocate memory");
> +		return -errno;
> +	}
>  	memset(mon_cpus, 0, (nr_cpus * sizeof(char)));

Your patch is fixing the problem, but it can be improved by:
	- using calloc (as in other .c)
	- removing the memset
	- instead of returning, goto err;

Do you mind sending a v2?

-- Daniel

      reply	other threads:[~2022-06-14 12:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14  9:38 [PATCH] rtla/utils: Fix the potential memory allocation failure jianchunfu
2022-06-14 12:44 ` Daniel Bristot de Oliveira [this message]

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=e9a891e6-586d-46a6-d623-6d25575f62c8@kernel.org \
    --to=bristot@kernel.org \
    --cc=jianchunfu@cmss.chinamobile.com \
    --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 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).