accel: Simplify configure_accelerator() using AccelType *acc variable

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Eduardo Habkost 2014-09-26 17:45:19 -03:00 committed by Paolo Bonzini
parent e54adde615
commit e8b466ef95

18
accel.c
View file

@ -62,6 +62,7 @@ int configure_accelerator(MachineClass *mc)
int i, ret; int i, ret;
bool accel_initialised = false; bool accel_initialised = false;
bool init_failed = false; bool init_failed = false;
AccelType *acc = NULL;
p = qemu_opt_get(qemu_get_machine_opts(), "accel"); p = qemu_opt_get(qemu_get_machine_opts(), "accel");
if (p == NULL) { if (p == NULL) {
@ -75,20 +76,21 @@ int configure_accelerator(MachineClass *mc)
} }
p = get_opt_name(buf, sizeof(buf), p, ':'); p = get_opt_name(buf, sizeof(buf), p, ':');
for (i = 0; i < ARRAY_SIZE(accel_list); i++) { for (i = 0; i < ARRAY_SIZE(accel_list); i++) {
if (strcmp(accel_list[i].opt_name, buf) == 0) { acc = &accel_list[i];
if (!accel_list[i].available()) { if (strcmp(acc->opt_name, buf) == 0) {
if (!acc->available()) {
printf("%s not supported for this target\n", printf("%s not supported for this target\n",
accel_list[i].name); acc->name);
break; break;
} }
*(accel_list[i].allowed) = true; *(acc->allowed) = true;
ret = accel_list[i].init(mc); ret = acc->init(mc);
if (ret < 0) { if (ret < 0) {
init_failed = true; init_failed = true;
fprintf(stderr, "failed to initialize %s: %s\n", fprintf(stderr, "failed to initialize %s: %s\n",
accel_list[i].name, acc->name,
strerror(-ret)); strerror(-ret));
*(accel_list[i].allowed) = false; *(acc->allowed) = false;
} else { } else {
accel_initialised = true; accel_initialised = true;
} }
@ -108,7 +110,7 @@ int configure_accelerator(MachineClass *mc)
} }
if (init_failed) { if (init_failed) {
fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); fprintf(stderr, "Back to %s accelerator.\n", acc->name);
} }
return !accel_initialised; return !accel_initialised;