aboutsummaryrefslogtreecommitdiff
path: root/target/arm/helper.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2022-04-30 22:49:54 -0700
committerPeter Maydell <peter.maydell@linaro.org>2022-05-05 09:35:51 +0100
commitc27f5d3a83ed2959a6a1947708b588a6774a2aec (patch)
tree50ebe60847d744660289a9cdb4636c2d3cb73545 /target/arm/helper.c
parent5860362d25f3afa99364d60295c09147a07055f1 (diff)
target/arm: Merge allocation of the cpreg and its name
Simplify freeing cp_regs hash table entries by using a single allocation for the entire value. This fixes a theoretical bug if we were to ever free the entire hash table, because we've been installing string literal constants into the cpreg structure in define_arm_vh_e2h_redirects_aliases. However, at present we only free entries created for AArch32 wildcard cpregs which get overwritten by more specific cpregs, so this bug is never exposed. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 20220501055028.646596-13-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'target/arm/helper.c')
-rw-r--r--target/arm/helper.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 2bc81dbc5e..d92fd23445 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -8506,11 +8506,17 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r,
* add a single reginfo struct to the hash table.
*/
uint32_t key;
- ARMCPRegInfo *r2 = g_memdup(r, sizeof(ARMCPRegInfo));
+ ARMCPRegInfo *r2;
int is64 = (r->type & ARM_CP_64BIT) ? 1 : 0;
int ns = (secstate & ARM_CP_SECSTATE_NS) ? 1 : 0;
+ size_t name_len;
+
+ /* Combine cpreg and name into one allocation. */
+ name_len = strlen(name) + 1;
+ r2 = g_malloc(sizeof(*r2) + name_len);
+ *r2 = *r;
+ r2->name = memcpy(r2 + 1, name, name_len);
- r2->name = g_strdup(name);
/* Reset the secure state to the specific incoming state. This is
* necessary as the register may have been defined with both states.
*/