ppc: get rid of free() (gitlab #1798)
cover ppc: get rid of free() (gitlab #1798)
Hello,
Here's some trivial changes following Peter's call to arms against free() and friends in gitlab issue #1798 in an attempt to enforce our memory management guidelines [1].
We only have 2 "free()" occurences that needs fixing in the ppc tree. The hard part is to be dilligent to to not introduce new ones.
Michael, feel free to take it via qemu-trivial.
[1] https://www.qemu.org/docs/master/devel/style.html#low-level-memory-management
Daniel Henrique Barboza (2):
hw/ppc: use g_free() in spapr_tce_table_post_load() target/ppc: use g_free() in test_opcode_table()
hw/ppc/spapr_iommu.c | 2 +- target/ppc/translate.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/2 hw/ppc: use g_free() in spapr_tce_table_post_load()
tcet->mig_table is memcpy'ed from tcet->table, which in turn is created via spapr_tce_alloc_table().
Use g_free() instead of free() to deallocate it.
--- hw/ppc/spapr_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_iommu.c +1 -1
@@ -248,7 +248,7 @@ static int spapr_tce_table_post_load(void *opaque, int version_id)memcpy (tcet->table, tcet->mig_table, tcet->nb_table *sizeof (tcet->table[0 ])); -free (tcet->mig_table); +g_free (tcet->mig_table); tcet->mig_table =NULL ; }
Signature · 1 line
2.41.0
Re: [PATCH for-8.2 1/2] hw/ppc: use g_free() in spapr_tce_table_post_load()
Quoted 2 lines · Daniel Henrique Barboza
tcet->mig_tableis memcpy'ed fromtcet->table,
The pointer is just copied, not memcpy'd.
Quoted 2 lines
which in turn is created
viaspapr_tce_alloc_table().
You could mention that this uses g_new0() for the allocation.
Quoted 12 lines
Use
g_free()instead offree()to deallocate it.Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/ppc/spapr_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/ppc/spapr_iommu.c +0
-0
hw/ppc/spapr_iommu.c static int spapr_tce_table_post_load(void *opaque, int version_id) · line 253
Quoted 7 lines
hw/ppc/spapr_iommu.c +1
-1@@ -248,7 +248,7 @@ static int spapr_tce_table_post_load(void *opaque, int version_id)memcpy (tcet->table, tcet->mig_table, tcet->nb_table *sizeof (tcet->table[0 ])); -free (tcet->mig_table); +g_free (tcet->mig_table); tcet->mig_table =NULL ; }
thanks
-- PMM
PATCH 2/2 target/ppc: use g_free() in test_opcode_table()
In reply to Daniel Henrique BarbozaUse g_free(table[i]) instead of free(table[i]) to comply with QEMU low level memory management guidelines.
--- target/ppc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate.c +1 -1
@@ -7129,7 +7129,7 @@ static int test_opcode_table(opc_handler_t **table, int len) tmp =test_opcode_table (ind_table (table[i]),PPC_CPU_INDIRECT_OPCODES_LEN );if (tmp ==0 ) { -free (table[i]); +g_free (table[i]); table[i] = &invalid_handler; }else { count++;
Signature · 1 line
2.41.0
Re: [PATCH for-8.2 2/2] target/ppc: use g_free() in test_opcode_table()
Quoted 14 lines · Daniel Henrique Barboza
Use
g_free(table[i])instead offree(table[i])to comply with QEMU low level memory management guidelines.Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/ppc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/ppc/translate.c +0
-0
target/ppc/translate.c static int test_opcode_table(opc_handler_t **table, int len) · line 7135
Quoted 8 lines
target/ppc/translate.c +1
-1@@ -7129,7 +7129,7 @@ static int test_opcode_table(opc_handler_t **table, int len) tmp =test_opcode_table (ind_table (table[i]),PPC_CPU_INDIRECT_OPCODES_LEN );if (tmp ==0 ) { -free (table[i]); +g_free (table[i]); table[i] = &invalid_handler; }else { count++;
Where is the allocation that this memory is free()ing? I think it is the g_new() in create_new_table(), but the code is a little complicated for me to understand...
thanks
-- PMM
Re: [PATCH for-8.2 2/2] target/ppc: use g_free() in test_opcode_table()
Quoted 20 lines · Peter Maydell
Quoted 18 lines · Daniel Henrique Barboza
Use
g_free(table[i])instead offree(table[i])to comply with QEMU low level memory management guidelines.Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/ppc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/ppc/translate.c +0
-1@@ -7129,7 +7129,7 @@ static int test_opcode_table(opc_handler_t **table, int len) tmp =test_opcode_table (ind_table (table[i]),PPC_CPU_INDIRECT_OPCODES_LEN );if (tmp ==0 ) { -free (table[i]);
Quoted 8 lines
target/ppc/translate.c static int test_opcode_table(opc_handler_t **table, int len) · line 7135
Quoted 4 lines
target/ppc/translate.c +1
-0+g_free (table[i]); table[i] = &invalid_handler; }else { count++;Where is the allocation that this memory is free()ing? I think it is the
g_new()increate_new_table(), but the code is a little complicated for me to understand...
It's on create_new_table() in the same file:
static int create_new_table(opc_handler_t **table, unsigned char idx)
{
opc_handler_t **tmp;
tmp = g_new(opc_handler_t *, PPC_CPU_INDIRECT_OPCODES_LEN);
fill_new_table(tmp, PPC_CPU_INDIRECT_OPCODES_LEN);
table[idx] = (opc_handler_t *)((uintptr_t)tmp | PPC_INDIRECT);
return 0;
}I probably should've mentioned in the commit msg ...
Daniel
Quoted 3 lines
thanks
-- PMM
Quoted 3 lines · Daniel Henrique Barboza
Here's some trivial changes following Peter's call to arms against
free()and friends in gitlab issue #1798 in an attempt to enforce our memory management guidelines [1].
To clarify, this isn't a "call to arms". The issue is marked up as a "bite-sized task", which is to say that it's a potential easy place to start for newcomers to the community who might be making their first contribution to the codebase. The changes it suggests aren't urgent; at most they're a nice-to-have, since glib guarantees that you can mix malloc/free and g_malloc/g_free.
We've had this sitting around as a suggestion on the wiki page for bite-sized-tasks for years, and occasionally people come through and have a go at it. I wanted to clean up and expand on the description of what we had in mind for the change, to give those people a better chance of successfully completing the task.
thanks
-- PMM
Quoted 6 lines · Peter Maydell
Quoted 3 lines · Daniel Henrique Barboza
Here's some trivial changes following Peter's call to arms against
free()and friends in gitlab issue #1798 in an attempt to enforce our memory management guidelines [1].
Quoted 6 lines
To clarify, this isn't a "call to arms". The issue is marked up as a "bite-sized task", which is to say that it's a potential easy place to start for newcomers to the community who might be making their first contribution to the codebase. The changes it suggests aren't urgent; at most they're a nice-to-have, since glib guarantees that you can mix malloc/free and g_malloc/g_free.
I failed to realized it was a byte sized task :/ and my Coccinelle comment in the bug makes me fell dumb hehe (given that Coccinelle is not newcomer friendly).
Quoted 7 lines
We've had this sitting around as a suggestion on the wiki page for bite-sized-tasks for years, and occasionally people come through and have a go at it. I wanted to clean up and expand on the description of what we had in mind for the change, to give those people a better chance of successfully completing the task.
What we can do then, since I already sent these, is perhaps link these patches as example/template in the gitlab issue later on.
Thanks,
Daniel
Quoted 3 lines
thanks
-- PMM
Michael Tokarev
AppliedQuoted 28 lines · Daniel Henrique Barboza
Quoted 6 lines · Peter Maydell
Quoted 3 lines · Daniel Henrique Barboza
Here's some trivial changes following Peter's call to arms against
free()and friends in gitlab issue #1798 in an attempt to enforce our memory management guidelines [1].Quoted 6 lines
To clarify, this isn't a "call to arms". The issue is marked up as a "bite-sized task", which is to say that it's a potential easy place to start for newcomers to the community who might be making their first contribution to the codebase. The changes it suggests aren't urgent; at most they're a nice-to-have, since glib guarantees that you can mix malloc/free and g_malloc/g_free.
I failed to realized it was a byte sized task :/ and my Coccinelle comment in the bug makes me fell dumb hehe (given that Coccinelle is not newcomer friendly).
Quoted 7 lines
We've had this sitting around as a suggestion on the wiki page for bite-sized-tasks for years, and occasionally people come through and have a go at it. I wanted to clean up and expand on the description of what we had in mind for the change, to give those people a better chance of successfully completing the task.
Quoted 2 lines
What we can do then, since I already sent these, is perhaps link these patches as example/template in the gitlab issue later on.
Applied to my trivial-patches branch adding suggested commit comment fixes while at it, hopefully there's nothing more to do :)
Thanks,
/mjt