From: Mahmoud Mandour <ma.mandourr@gmail.com>
To: qemu-devel@nongnu.org
Cc: Max Filippov <jcmvbkbc@gmail.com>,
Mahmoud Mandour <ma.mandourr@gmail.com>
Subject: [PATCH 4/8] target/xtensa: Replaced malloc/free with GLib's variants
Date: Sun, 14 Mar 2021 05:23:20 +0200 [thread overview]
Message-ID: <20210314032324.45142-5-ma.mandourr@gmail.com> (raw)
In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com>
Replaced the calls to malloc() and their respective calls to
free() with GLib's allocation and deallocation functions.
Removed null checking before calling g_free() because it's
not necessary and generates style errors.
Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
target/xtensa/xtensa-isa.c | 53 +++++++++++++++-----------------------
1 file changed, 21 insertions(+), 32 deletions(-)
diff --git a/target/xtensa/xtensa-isa.c b/target/xtensa/xtensa-isa.c
index 630b4f9da1..5afdba77aa 100644
--- a/target/xtensa/xtensa-isa.c
+++ b/target/xtensa/xtensa-isa.c
@@ -79,7 +79,7 @@ int xtensa_insnbuf_size(xtensa_isa isa)
xtensa_insnbuf xtensa_insnbuf_alloc(xtensa_isa isa)
{
xtensa_insnbuf result = (xtensa_insnbuf)
- malloc(xtensa_insnbuf_size(isa) * sizeof(xtensa_insnbuf_word));
+ g_try_malloc(xtensa_insnbuf_size(isa) * sizeof(xtensa_insnbuf_word));
CHECK_ALLOC(result, 0);
return result;
@@ -89,7 +89,7 @@ xtensa_insnbuf xtensa_insnbuf_alloc(xtensa_isa isa)
void xtensa_insnbuf_free(xtensa_isa isa __attribute__ ((unused)),
xtensa_insnbuf buf)
{
- free(buf);
+ g_free(buf);
}
@@ -237,7 +237,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
/* Set up the opcode name lookup table. */
isa->opname_lookup_table =
- malloc(isa->num_opcodes * sizeof(xtensa_lookup_entry));
+ g_try_new(xtensa_lookup_entry, isa->num_opcodes);
CHECK_ALLOC_FOR_INIT(isa->opname_lookup_table, NULL, errno_p, error_msg_p);
for (n = 0; n < isa->num_opcodes; n++) {
isa->opname_lookup_table[n].key = isa->opcodes[n].name;
@@ -248,7 +248,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
/* Set up the state name lookup table. */
isa->state_lookup_table =
- malloc(isa->num_states * sizeof(xtensa_lookup_entry));
+ g_try_new(xtensa_lookup_entry, isa->num_states);
CHECK_ALLOC_FOR_INIT(isa->state_lookup_table, NULL, errno_p, error_msg_p);
for (n = 0; n < isa->num_states; n++) {
isa->state_lookup_table[n].key = isa->states[n].name;
@@ -259,7 +259,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
/* Set up the sysreg name lookup table. */
isa->sysreg_lookup_table =
- malloc(isa->num_sysregs * sizeof(xtensa_lookup_entry));
+ g_try_new(xtensa_lookup_entry, isa->num_sysregs);
CHECK_ALLOC_FOR_INIT(isa->sysreg_lookup_table, NULL, errno_p, error_msg_p);
for (n = 0; n < isa->num_sysregs; n++) {
isa->sysreg_lookup_table[n].key = isa->sysregs[n].name;
@@ -271,7 +271,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
/* Set up the user & system sysreg number tables. */
for (is_user = 0; is_user < 2; is_user++) {
isa->sysreg_table[is_user] =
- malloc((isa->max_sysreg_num[is_user] + 1) * sizeof(xtensa_sysreg));
+ g_try_new(xtensa_sysreg, isa->max_sysreg_num[is_user] + 1);
CHECK_ALLOC_FOR_INIT(isa->sysreg_table[is_user], NULL,
errno_p, error_msg_p);
@@ -290,7 +290,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
/* Set up the interface lookup table. */
isa->interface_lookup_table =
- malloc(isa->num_interfaces * sizeof(xtensa_lookup_entry));
+ g_try_new(xtensa_lookup_entry, isa->num_interfaces);
CHECK_ALLOC_FOR_INIT(isa->interface_lookup_table, NULL, errno_p,
error_msg_p);
for (n = 0; n < isa->num_interfaces; n++) {
@@ -302,7 +302,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p,
/* Set up the funcUnit lookup table. */
isa->funcUnit_lookup_table =
- malloc(isa->num_funcUnits * sizeof(xtensa_lookup_entry));
+ g_try_new(xtensa_lookup_entry, isa->num_funcUnits);
CHECK_ALLOC_FOR_INIT(isa->funcUnit_lookup_table, NULL, errno_p,
error_msg_p);
for (n = 0; n < isa->num_funcUnits; n++) {
@@ -332,36 +332,25 @@ void xtensa_isa_free(xtensa_isa isa)
* structure to its initial state.
*/
- if (intisa->opname_lookup_table) {
- free(intisa->opname_lookup_table);
- intisa->opname_lookup_table = 0;
- }
+ g_free(intisa->opname_lookup_table);
+ intisa->opname_lookup_table = 0;
- if (intisa->state_lookup_table) {
- free(intisa->state_lookup_table);
- intisa->state_lookup_table = 0;
- }
+ g_free(intisa->state_lookup_table);
+ intisa->state_lookup_table = 0;
+
+ g_free(intisa->sysreg_lookup_table);
+ intisa->sysreg_lookup_table = 0;
- if (intisa->sysreg_lookup_table) {
- free(intisa->sysreg_lookup_table);
- intisa->sysreg_lookup_table = 0;
- }
for (n = 0; n < 2; n++) {
- if (intisa->sysreg_table[n]) {
- free(intisa->sysreg_table[n]);
- intisa->sysreg_table[n] = 0;
- }
+ g_free(intisa->sysreg_table[n]);
+ intisa->sysreg_table[n] = 0;
}
- if (intisa->interface_lookup_table) {
- free(intisa->interface_lookup_table);
- intisa->interface_lookup_table = 0;
- }
+ g_free(intisa->interface_lookup_table);
+ intisa->interface_lookup_table = 0;
- if (intisa->funcUnit_lookup_table) {
- free(intisa->funcUnit_lookup_table);
- intisa->funcUnit_lookup_table = 0;
- }
+ g_free(intisa->funcUnit_lookup_table);
+ intisa->funcUnit_lookup_table = 0;
}
--
2.25.1
next prev parent reply other threads:[~2021-03-14 3:28 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-14 3:23 [PATCH 0/8] Replacing malloc and the like with GLib's variants Mahmoud Mandour
2021-03-14 3:23 ` [PATCH 1/8] bsd-user/elfload.c: Replaced calls to malloc/free with GLib variants Mahmoud Mandour
2021-03-15 16:07 ` Alex Bennée
2021-03-15 16:22 ` Mahmoud Mandour
2021-03-15 17:56 ` Alex Bennée
2021-03-14 3:23 ` [PATCH 2/8] hw/audio/fmopl.c: Fixing some style errors Mahmoud Mandour
2021-03-14 3:23 ` [PATCH 3/8] hw/audio/fmopl.c: Replaced calls to malloc with GLib's variants Mahmoud Mandour
2021-03-15 16:12 ` Alex Bennée
2021-03-15 17:35 ` Mahmoud Mandour
2021-03-14 3:23 ` Mahmoud Mandour [this message]
2021-03-14 15:38 ` [PATCH 4/8] target/xtensa: Replaced malloc/free " Max Filippov
2021-03-14 3:23 ` [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant Mahmoud Mandour
2021-03-15 6:10 ` Thomas Huth
2021-03-15 6:43 ` Mahmoud Mandour
2021-03-15 7:29 ` Thomas Huth
2021-03-15 16:15 ` Alex Bennée
2021-03-14 3:23 ` [PATCH 6/8] tools/virtiofsd/buffer.c: replaced a calloc call with GLib's g_try_new0 Mahmoud Mandour
2021-03-15 9:53 ` Stefan Hajnoczi
2021-05-25 19:01 ` Dr. David Alan Gilbert
2021-03-14 3:23 ` [PATCH 7/8] tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc Mahmoud Mandour
2021-03-15 9:54 ` Stefan Hajnoczi
2021-03-14 3:23 ` [PATCH 8/8] tools/virtiofsd: Replacing malloc-like calls with GLib's variants Mahmoud Mandour
2021-03-15 10:01 ` Stefan Hajnoczi
2021-03-15 10:46 ` Mahmoud Mandour
2021-03-16 17:23 ` Stefan Hajnoczi
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=20210314032324.45142-5-ma.mandourr@gmail.com \
--to=ma.mandourr@gmail.com \
--cc=jcmvbkbc@gmail.com \
--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).