From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Max Filippov <jcmvbkbc@gmail.com>, qemu-devel@nongnu.org
Cc: "QEMU Trivial" <qemu-trivial@nongnu.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [Qemu-devel] [PATCH] hw/xtensa: sim: use g_string/g_new
Date: Mon, 8 May 2017 15:57:23 -0300 [thread overview]
Message-ID: <e73e252e-61fc-6b2c-6e3f-f5a2e1f934cc@amsat.org> (raw)
In-Reply-To: <1494266456-2251-1-git-send-email-jcmvbkbc@gmail.com>
On 05/08/2017 03:00 PM, Max Filippov wrote:
> Replace malloc/free/sprintf with g_string/g_string_printf/g_string_free.
> Replace g_malloc with g_new when allocating the MemoryRegion to get more
> type safety.
>
> Suggested-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/xtensa/sim.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c
> index d2d1d3a..b27e28d 100644
> --- a/hw/xtensa/sim.c
> +++ b/hw/xtensa/sim.c
> @@ -41,21 +41,21 @@ static void xtensa_create_memory_regions(const XtensaMemory *memory,
> const char *name)
> {
> unsigned i;
> - char *num_name = malloc(strlen(name) + sizeof(i) * 3 + 1);
> + GString *num_name = g_string_new(NULL);
>
> for (i = 0; i < memory->num; ++i) {
> MemoryRegion *m;
>
> - sprintf(num_name, "%s%u", name, i);
> - m = g_malloc(sizeof(*m));
> - memory_region_init_ram(m, NULL, num_name,
> + g_string_printf(num_name, "%s%u", name, i);
> + m = g_new(MemoryRegion, 1);
> + memory_region_init_ram(m, NULL, num_name->str,
> memory->location[i].size,
> &error_fatal);
> vmstate_register_ram_global(m);
> memory_region_add_subregion(get_system_memory(),
> memory->location[i].addr, m);
> }
> - free(num_name);
> + g_string_free(num_name, true);
> }
>
> static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
>
next prev parent reply other threads:[~2017-05-08 18:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-08 18:00 [Qemu-devel] [PATCH] hw/xtensa: sim: use g_string/g_new Max Filippov
2017-05-08 18:57 ` Philippe Mathieu-Daudé [this message]
2017-05-09 8:00 ` Markus Armbruster
2017-05-23 14:53 ` Michael Tokarev
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=e73e252e-61fc-6b2c-6e3f-f5a2e1f934cc@amsat.org \
--to=f4bug@amsat.org \
--cc=alex.bennee@linaro.org \
--cc=jcmvbkbc@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@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).