qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH qom-cpu-next v3 2/4] target-i386: Split command


From: Andreas Färber
Subject: Re: [Qemu-devel] [PATCH qom-cpu-next v3 2/4] target-i386: Split command line parsing out of cpu_x86_register()
Date: Mon, 04 Feb 2013 13:25:54 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2

Am 04.02.2013 12:14, schrieb Igor Mammedov:
> On Sat,  2 Feb 2013 01:37:06 +0100
> Andreas Färber <address@hidden> wrote:
> 
>> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
>> index e74802b..ee2fd6b 100644
>> --- a/target-i386/cpu.c
>> +++ b/target-i386/cpu.c
[..]
>> @@ -1578,26 +1566,50 @@ out:
>>  
>>  X86CPU *cpu_x86_init(const char *cpu_model)
>>  {
>> -    X86CPU *cpu;
>> +    X86CPU *cpu = NULL;
>>      CPUX86State *env;
>> +    gchar **model_pieces;
>> +    char *name, *features;
>>      Error *error = NULL;
>>  
>> +    model_pieces = g_strsplit(cpu_model, ",", 2);
>> +    if (!model_pieces[0]) {
>> +        error_setg(&error, "Invalid/empty CPU model name");
>> +        goto error;
>> +    }
>> +    name = model_pieces[0];
>> +    features = model_pieces[1];
>> +
>>      cpu = X86_CPU(object_new(TYPE_X86_CPU));
>>      env = &cpu->env;
>>      env->cpu_model_str = cpu_model;
>>  
>> -    if (cpu_x86_register(cpu, cpu_model) < 0) {
>> -        object_delete(OBJECT(cpu));
>> -        return NULL;
>> +    if (cpu_x86_register(cpu, name) < 0) {
>> +        goto error;
>> +    }
>> +
>> +    cpu_x86_parse_featurestr(cpu, features, &error);
>> +    if (error) {
>> +        goto error;
>>      }
>>  
>>      object_property_set_bool(OBJECT(cpu), true, "realized", &error);
>>      if (error) {
>> +        goto error;
>> +    }
>> +    g_strfreev(model_pieces);
>> +    return cpu;
>> +
>> +error:
> Could you use common exit path like it's done in cpu_x86_register()?
> That allows to avoid cleanup code duplication on exit.

Well, we don't want to object_unref() the CPU in the cleanup path, so we
would need to set Error* also in the registration case and move it into
that code path, that would be possible.

Andreas

>> +    g_strfreev(model_pieces);
>> +    if (error) {
>> +        fprintf(stderr, "%s\n", error_get_pretty(error));
>>          error_free(error);
>> +    }
>> +    if (cpu != NULL) {
>>          object_delete(OBJECT(cpu));
>> -        return NULL;
>>      }
>> -    return cpu;
>> +    return NULL;
>>  }
>>  
>>  #if !defined(CONFIG_USER_ONLY)

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]