linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dev Jain <dev.jain@arm.com>
To: Zhu Jun <zhujun2@cmss.chinamobile.com>, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RESEND] tools/mm: Use calloc and check the memory allocation failure
Date: Thu, 12 Sep 2024 09:58:50 +0530	[thread overview]
Message-ID: <09efaf91-4d85-47c9-857f-94f1a9c9bce8@arm.com> (raw)
In-Reply-To: <20240912032457.2780-1-zhujun2@cmss.chinamobile.com>


On 9/12/24 08:54, Zhu Jun wrote:
> Replace malloc with calloc and add null pointer check
> in case of allocation failure.
>
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
> ---
>   tools/mm/page_owner_sort.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tools/mm/page_owner_sort.c b/tools/mm/page_owner_sort.c
> index e1f264444342..8c78265cef67 100644
> --- a/tools/mm/page_owner_sort.c
> +++ b/tools/mm/page_owner_sort.c
> @@ -368,9 +368,10 @@ static __u64 get_ts_nsec(char *buf)
>   
>   static char *get_comm(char *buf)
>   {
> -	char *comm_str = malloc(TASK_COMM_LEN);
> +	char *comm_str = calloc(TASK_COMM_LEN, sizeof(char));
>   
> -	memset(comm_str, 0, TASK_COMM_LEN);
> +	if (!comm_str)
> +		return NULL;
>   
>   	search_pattern(&comm_pattern, comm_str, buf);
>   	errno = 0;

Hello Zhu,

It is pointless to resend if you haven't addressed the queries
raised by Andrew. He notes that the callers aren't handling a
possible NULL return, so there is no point in even checking for
a mem alloc failure. I haven't wandered in tools/mm but from a
programming PoV what Andrew says is correct...if you are returning
NULL then you also must decide what to do with that in the caller,
and so on, on which I cannot comment :)



  reply	other threads:[~2024-09-12  4:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-12  3:24 Zhu Jun
2024-09-12  4:28 ` Dev Jain [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-09-06  9:24 Zhu Jun

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=09efaf91-4d85-47c9-857f-94f1a9c9bce8@arm.com \
    --to=dev.jain@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=zhujun2@cmss.chinamobile.com \
    /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