From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Richard Henderson <rth@twiddle.net>
Subject: [PULL 4/4] i386: Use g_autofree in a few places
Date: Mon, 16 Dec 2019 16:38:25 -0300 [thread overview]
Message-ID: <20191216193825.1794153-5-ehabkost@redhat.com> (raw)
In-Reply-To: <20191216193825.1794153-1-ehabkost@redhat.com>
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>
---
target/i386/cpu.c | 41 +++++++++++++----------------------------
1 file 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 =
--
2.23.0
next prev parent reply other threads:[~2019-12-16 19:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-16 19:38 [PULL 0/4] x86 queue, 2019-12-16 Eduardo Habkost
2019-12-16 19:38 ` [PULL 1/4] i386: Add MSR feature bit for MDS-NO Eduardo Habkost
2019-12-16 19:38 ` [PULL 2/4] i386: Add macro for stibp Eduardo Habkost
2019-12-16 19:38 ` [PULL 3/4] i386: Add new CPU model Cooperlake Eduardo Habkost
2019-12-17 2:26 ` Xiaoyao Li
2019-12-17 7:52 ` Philippe Mathieu-Daudé
2019-12-16 19:38 ` Eduardo Habkost [this message]
2019-12-17 11:51 ` [PULL 0/4] x86 queue, 2019-12-16 Peter Maydell
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=20191216193825.1794153-5-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=sgarzare@redhat.com \
/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).