From: Richard Henderson <richard.henderson@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>, dinglimin@cmss.chinamobile.com
Cc: Michael Tokarev <mjt@tls.msk.ru>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc.
Date: Wed, 26 Jul 2023 08:21:47 -0700 [thread overview]
Message-ID: <9a05f370-1857-2c28-a184-a5197455b314@linaro.org> (raw)
In-Reply-To: <CAFEAcA8UdN4-DU4dAiY3VGLA77mLK-ohfFJs5+5fDt3v1mAAcg@mail.gmail.com>
On 7/26/23 02:43, Peter Maydell wrote:
> (Something went wrong with the quoting in your email. I've
> fixed it up.)
>
> On Wed, 26 Jul 2023 at 05:38, <dinglimin@cmss.chinamobile.com> wrote:
>> Peter Maydell wrote:
>>> The third part here, is that g_malloc() does not ever
>>> fail -- it will abort() on out of memory. However
>>> the code here is still handling g_malloc() returning NULL.
>>> The equivalent for "we expect this might fail" (which we want
>>> here, because the guest is passing us the length of memory
>>> to try to allocate) is g_try_malloc().
>
>> g_malloc() is preferred more than g_try_* functions, which return NULL on error,
>> when the size of the requested allocation is small.
>> This is because allocating few bytes should not be a problem in a healthy system.
>
> This is true. But in this particular case we cannot be sure
> that the size of the allocation is small, because the size
> is controlled by the guest. So we want g_try_malloc().
And why do we want to use g_try_malloc instead of just sticking with malloc?
I see no reason to change anything at all here.
r~
next prev parent reply other threads:[~2023-07-26 15:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-25 8:06 [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc dinglimin
2023-07-25 8:13 ` Michael Tokarev
2023-07-25 9:00 ` dinglimin
2023-07-25 9:13 ` Michael Tokarev
2023-07-25 9:35 ` Peter Maydell
2023-07-26 4:37 ` 回复: " dinglimin
2023-07-26 9:43 ` Peter Maydell
2023-07-26 15:21 ` Richard Henderson [this message]
2023-07-27 14:56 ` Peter Maydell
2023-07-27 15:04 ` Daniel P. Berrangé
2023-07-27 16:31 ` Richard Henderson
2023-07-28 5:12 ` dinglimin
2023-07-28 9:35 ` Peter Maydell
2023-07-28 10:50 ` dinglimin
2023-07-28 11:27 ` Peter Maydell
2023-07-28 12:16 ` Peter Maydell
2023-07-26 7:07 ` dinglimin
2023-07-25 10:57 ` dinglimin
-- strict thread matches above, loose matches on Subject: below --
2024-02-26 9:06 dinglimin
2024-02-26 9:48 ` Philippe Mathieu-Daudé
2024-02-26 10:03 ` Daniel P. Berrangé
2024-02-26 10:16 ` Peter Maydell
2024-02-26 10:02 ` Zhao Liu
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=9a05f370-1857-2c28-a184-a5197455b314@linaro.org \
--to=richard.henderson@linaro.org \
--cc=dinglimin@cmss.chinamobile.com \
--cc=mjt@tls.msk.ru \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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).