From: Dev Jain <dev.jain@arm.com>
To: Markus Elfring <Markus.Elfring@web.de>,
Zhu Jun <zhujun2@cmss.chinamobile.com>,
linux-mm@kvack.org, kernel-janitors@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: tools/mm: Use calloc and check the potential memory allocation failure
Date: Thu, 29 Aug 2024 13:44:39 +0530 [thread overview]
Message-ID: <dd9faaa9-72ea-445d-b687-5005ede01b09@arm.com> (raw)
In-Reply-To: <22213ddd-90b3-4d33-aa80-4b3500a21a2e@web.de>
On 8/29/24 13:25, Markus Elfring wrote:
>>>> Replace malloc with calloc and add memory allocating check
>>> memset(…, 0, …) call by calloc()?
>> Calloc returns zeroed-out memory.
> I propose to improve the change description considerably.
>
>
>>>> of comm_str before used.
>>> * Add also a null pointer check for the detection of a memory allocation failure.
>> Which is exactly what Zhu has done?
> Can the commit message become nicer anyhow?
I agree. The commit message should note two things, first that
a malloc followed by a memset to 0 can be reduced to single calloc,
and second that, "add memory allocating check" can be replaced by
"add null pointer check in case of allocation failure".
>
>
> …
>>> * How do you think about to omit the statement “fprintf(stderr, "Out of memory\n");”?
>> Why?
> I imagine that a returned null pointer can eventually be sufficient already.
> Would you get helpful background information from the variable “errno”?
In case of calloc failure, errno is always set to ENOMEM, so we are guaranteed
that any failure is an out of memory failure.
>
> Regards,
> Markus
prev parent reply other threads:[~2024-08-29 8:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 5:56 [PATCH] " Zhu Jun
2024-08-29 6:25 ` Markus Elfring
2024-08-29 7:39 ` Dev Jain
2024-08-29 7:55 ` Markus Elfring
2024-08-29 8:14 ` Dev Jain [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=dd9faaa9-72ea-445d-b687-5005ede01b09@arm.com \
--to=dev.jain@arm.com \
--cc=Markus.Elfring@web.de \
--cc=akpm@linux-foundation.org \
--cc=kernel-janitors@vger.kernel.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