Patchwork [v2,01/15] target-i386: Fix x86_cpuid_set_model_id()

login
register
mail settings
Submitter Andreas Färber
Date April 24, 2012, 9:33 a.m.
Message ID <1335260021-26366-2-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/154646/
State New
Headers show

Comments

Andreas Färber - April 24, 2012, 9:33 a.m.
Don't assume zeroed cpuid_model[] fields.

This doesn't break anything yet but QOM properties should be able to set
the value to something else without setting an intermediate zero string.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Igor Mammedov - April 24, 2012, 11:32 a.m.
On 04/24/2012 11:33 AM, Andreas Färber wrote:
> Don't assume zeroed cpuid_model[] fields.
>
> This doesn't break anything yet but QOM properties should be able to set
> the value to something else without setting an intermediate zero string.
>
> Signed-off-by: Andreas Färber<afaerber@suse.de>
> Reviewed-by: Eduardo Habkost<ehabkost@redhat.com>
> ---
>   target-i386/cpu.c |    3 +++
>   1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 3df53ca..80c1ca5 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -627,6 +627,9 @@ static void x86_cpuid_set_model_id(CPUX86State *env, const char *model_id)
>           model_id = "";
>       }
>       len = strlen(model_id);
> +    for (i = 0; i<  12; i++) {
> +        env->cpuid_model[i] = 0;
> +    }
It's not important, but why not to use memset here?

>       for (i = 0; i<  48; i++) {
>           if (i>= len) {
>               c = '\0';
Andreas Färber - April 24, 2012, 11:39 a.m.
Am 24.04.2012 13:32, schrieb Igor Mammedov:
> On 04/24/2012 11:33 AM, Andreas Färber wrote:
>> Don't assume zeroed cpuid_model[] fields.
>>
>> This doesn't break anything yet but QOM properties should be able to set

Should've read "didn't". I sure hope it doesn't. :)

>> the value to something else without setting an intermediate zero string.
>>
>> Signed-off-by: Andreas Färber<afaerber@suse.de>
>> Reviewed-by: Eduardo Habkost<ehabkost@redhat.com>
>> ---
>>   target-i386/cpu.c |    3 +++
>>   1 files changed, 3 insertions(+), 0 deletions(-)
>>
>> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
>> index 3df53ca..80c1ca5 100644
>> --- a/target-i386/cpu.c
>> +++ b/target-i386/cpu.c
>> @@ -627,6 +627,9 @@ static void x86_cpuid_set_model_id(CPUX86State
>> *env, const char *model_id)
>>           model_id = "";
>>       }
>>       len = strlen(model_id);
>> +    for (i = 0; i<  12; i++) {
>> +        env->cpuid_model[i] = 0;
>> +    }
> It's not important, but why not to use memset here?

I guess I was blinded by the for loop below. ;)
Will change it for the PULL if there's no other reason to resend.

Thanks for asking,
Andreas

>>       for (i = 0; i<  48; i++) {
>>           if (i>= len) {
>>               c = '\0';

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 3df53ca..80c1ca5 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -627,6 +627,9 @@  static void x86_cpuid_set_model_id(CPUX86State *env, const char *model_id)
         model_id = "";
     }
     len = strlen(model_id);
+    for (i = 0; i < 12; i++) {
+        env->cpuid_model[i] = 0;
+    }
     for (i = 0; i < 48; i++) {
         if (i >= len) {
             c = '\0';