diff options
author | Eduardo Habkost <ehabkost@redhat.com> | 2019-10-24 23:56:32 -0300 |
---|---|---|
committer | Eduardo Habkost <ehabkost@redhat.com> | 2019-12-13 16:32:19 -0300 |
commit | 88703ce2e6bbc8cc00c90c1bb8af1f3cd964ac9c (patch) | |
tree | 43752141b821c01e9a1b747419cd54064004f04f /target/i386/cpu.c | |
parent | 22a866b6166db5caa4abaa6e656c2a431fa60726 (diff) | |
download | qemu-88703ce2e6bbc8cc00c90c1bb8af1f3cd964ac9c.zip |
i386: Use g_autofree in a few places
Get rid of 12 explicit g_free() calls.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20191025025632.5928-1-ehabkost@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'target/i386/cpu.c')
-rw-r--r-- | target/i386/cpu.c | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/target/i386/cpu.c b/target/i386/cpu.c index de828e29d8..0a9ac65974 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1671,11 +1671,8 @@ static char *x86_cpu_type_name(const char *model_name) static ObjectClass *x86_cpu_class_by_name(const char *cpu_model) { - ObjectClass *oc; - char *typename = x86_cpu_type_name(cpu_model); - oc = object_class_by_name(typename); - g_free(typename); - return oc; + g_autofree char *typename = x86_cpu_type_name(cpu_model); + return object_class_by_name(typename); } static char *x86_cpu_class_get_model_name(X86CPUClass *cc) @@ -4226,7 +4223,6 @@ static void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t mask, CPUX86State *env = &cpu->env; FeatureWordInfo *f = &feature_word_info[w]; int i; - char *feat_word_str; if (!cpu->force_features) { env->features[w] &= ~mask; @@ -4239,13 +4235,12 @@ static void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint64_t mask, for (i = 0; i < 64; ++i) { if ((1ULL << i) & mask) { - feat_word_str = feature_word_description(f, i); + g_autofree char *feat_word_str = feature_word_description(f, i); warn_report("%s: %s%s%s [bit %d]", verbose_prefix, feat_word_str, f->feat_names[i] ? "." : "", f->feat_names[i] ? f->feat_names[i] : "", i); - g_free(feat_word_str); } } } @@ -4747,17 +4742,14 @@ static gint x86_cpu_list_compare(gconstpointer a, gconstpointer b) ObjectClass *class_b = (ObjectClass *)b; X86CPUClass *cc_a = X86_CPU_CLASS(class_a); X86CPUClass *cc_b = X86_CPU_CLASS(class_b); - char *name_a, *name_b; int ret; if (cc_a->ordering != cc_b->ordering) { ret = cc_a->ordering - cc_b->ordering; } else { - name_a = x86_cpu_class_get_model_name(cc_a); - name_b = x86_cpu_class_get_model_name(cc_b); + g_autofree char *name_a = x86_cpu_class_get_model_name(cc_a); + g_autofree char *name_b = x86_cpu_class_get_model_name(cc_b); ret = strcmp(name_a, name_b); - g_free(name_a); - g_free(name_b); } return ret; } @@ -4795,9 +4787,9 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) { ObjectClass *oc = data; X86CPUClass *cc = X86_CPU_CLASS(oc); - char *name = x86_cpu_class_get_model_name(cc); - char *desc = g_strdup(cc->model_description); - char *alias_of = x86_cpu_class_get_alias_of(cc); + g_autofree char *name = x86_cpu_class_get_model_name(cc); + g_autofree char *desc = g_strdup(cc->model_description); + g_autofree char *alias_of = x86_cpu_class_get_alias_of(cc); if (!desc && alias_of) { if (cc->model && cc->model->version == CPU_VERSION_AUTO) { @@ -4811,9 +4803,6 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data) } qemu_printf("x86 %-20s %-48s\n", name, desc); - g_free(name); - g_free(desc); - g_free(alias_of); } /* list available CPU models and flags */ @@ -5252,7 +5241,7 @@ static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data) static void x86_register_cpu_model_type(const char *name, X86CPUModel *model) { - char *typename = x86_cpu_type_name(name); + g_autofree char *typename = x86_cpu_type_name(name); TypeInfo ti = { .name = typename, .parent = TYPE_X86_CPU, @@ -5261,14 +5250,12 @@ static void x86_register_cpu_model_type(const char *name, X86CPUModel *model) }; type_register(&ti); - g_free(typename); } static void x86_register_cpudef_types(X86CPUDefinition *def) { X86CPUModel *m; const X86CPUVersionDefinition *vdef; - char *name; /* AMD aliases are handled at runtime based on CPUID vendor, so * they shouldn't be set on the CPU model table. @@ -5288,11 +5275,11 @@ static void x86_register_cpudef_types(X86CPUDefinition *def) for (vdef = x86_cpu_def_get_versions(def); vdef->version; vdef++) { X86CPUModel *m = g_new0(X86CPUModel, 1); + g_autofree char *name = + x86_cpu_versioned_model_name(def, vdef->version); m->cpudef = def; m->version = vdef->version; - name = x86_cpu_versioned_model_name(def, vdef->version); x86_register_cpu_model_type(name, m); - g_free(name); if (vdef->alias) { X86CPUModel *am = g_new0(X86CPUModel, 1); @@ -6364,9 +6351,8 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) if (xcc->host_cpuid_required) { if (!accel_uses_host_cpuid()) { - char *name = x86_cpu_class_get_model_name(xcc); + g_autofree char *name = x86_cpu_class_get_model_name(xcc); error_setg(&local_err, "CPU model '%s' requires KVM", name); - g_free(name); goto out; } @@ -6482,10 +6468,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) /* Cache information initialization */ if (!cpu->legacy_cache) { if (!xcc->model || !xcc->model->cpudef->cache_info) { - char *name = x86_cpu_class_get_model_name(xcc); + g_autofree char *name = x86_cpu_class_get_model_name(xcc); error_setg(errp, "CPU model '%s' doesn't support legacy-cache=off", name); - g_free(name); return; } env->cache_info_cpuid2 = env->cache_info_cpuid4 = env->cache_info_amd = |