Patchwork [8/9] target-i386: cleanup 'foo=val' feature handling

login
register
mail settings
Submitter Igor Mammedov
Date Feb. 11, 2013, 4:35 p.m.
Message ID <1360600511-25133-9-git-send-email-imammedo@redhat.com>
Download mbox | patch
Permalink /patch/219652/
State New
Headers show

Comments

Igor Mammedov - Feb. 11, 2013, 4:35 p.m.
features family, model, stepping, level, hv_spinlocks are treated similarly
when passed from command line, so it's not necessary to handle each of them
individually. Collapse them to one catch-all branch which will treat
any not explicitly handled feature in format 'foo=val'.

PS:
Any unknown feature will be rejected by property setter so there is no
need to check for unknown feature in cpu_x86_parse_featurestr(), therefore
it's replaced by above mentioned catch-all handler.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 target-i386/cpu.c |   21 +++------------------
 1 files changed, 3 insertions(+), 18 deletions(-)
Eduardo Habkost - Feb. 19, 2013, 6:53 p.m.
On Mon, Feb 11, 2013 at 05:35:10PM +0100, Igor Mammedov wrote:
> features family, model, stepping, level, hv_spinlocks are treated similarly
> when passed from command line, so it's not necessary to handle each of them
> individually. Collapse them to one catch-all branch which will treat
> any not explicitly handled feature in format 'foo=val'.
> 
> PS:
> Any unknown feature will be rejected by property setter so there is no
> need to check for unknown feature in cpu_x86_parse_featurestr(), therefore
> it's replaced by above mentioned catch-all handler.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  target-i386/cpu.c |   21 +++------------------
>  1 files changed, 3 insertions(+), 18 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index a22d3a6..fcfe8ec 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1545,15 +1545,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
>          } else if ((val = strchr(featurestr, '='))) {
>              feat2prop(featurestr);
>              *val = 0; val++;
> -            if (!strcmp(featurestr, "family")) {
> -                object_property_parse(OBJECT(cpu), val, featurestr, errp);
> -            } else if (!strcmp(featurestr, "model")) {
> -                object_property_parse(OBJECT(cpu), val, featurestr, errp);
> -            } else if (!strcmp(featurestr, "stepping")) {
> -                object_property_parse(OBJECT(cpu), val, featurestr, errp);
> -            } else if (!strcmp(featurestr, "level")) {
> -                object_property_parse(OBJECT(cpu), val, featurestr, errp);
> -            } else if (!strcmp(featurestr, "xlevel")) {
> +            if (!strcmp(featurestr, "xlevel")) {
>                  char *err;
>                  char num[32];
>  
> @@ -1569,11 +1561,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
>                  }
>                  snprintf(num, sizeof(num), "%" PRIu32, numvalue);
>                  object_property_parse(OBJECT(cpu), num, featurestr, errp);
> -            } else if (!strcmp(featurestr, "vendor")) {
> -                object_property_parse(OBJECT(cpu), val, featurestr, errp);
> -            } else if (!strcmp(featurestr, "model-id")) {
> -                object_property_parse(OBJECT(cpu), val, featurestr, errp);
> -            } else if (!strcmp(featurestr, "tsc-freq")) {
> +           } else if (!strcmp(featurestr, "tsc-freq")) {

One whitespace is missing, here.  :-)

Except for that, patch looks good.


>                  int64_t tsc_freq;
>                  char *err;
>                  char num[32];
> @@ -1586,11 +1574,8 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
>                  }
>                  snprintf(num, sizeof(num), "%" PRId64, tsc_freq);
>                  object_property_parse(OBJECT(cpu), num, "tsc-frequency", errp);
> -            } else if (!strcmp(featurestr, "hv-spinlocks")) {
> -                object_property_parse(OBJECT(cpu), val, featurestr, errp);
>              } else {
> -                error_setg(errp, "unrecognized feature %s\n", featurestr);
> -                goto out;
> +                object_property_parse(OBJECT(cpu), val, featurestr, errp);
>              }
>          } else {
>              feat2prop(featurestr);
> -- 
> 1.7.1
> 
>

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index a22d3a6..fcfe8ec 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1545,15 +1545,7 @@  static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
         } else if ((val = strchr(featurestr, '='))) {
             feat2prop(featurestr);
             *val = 0; val++;
-            if (!strcmp(featurestr, "family")) {
-                object_property_parse(OBJECT(cpu), val, featurestr, errp);
-            } else if (!strcmp(featurestr, "model")) {
-                object_property_parse(OBJECT(cpu), val, featurestr, errp);
-            } else if (!strcmp(featurestr, "stepping")) {
-                object_property_parse(OBJECT(cpu), val, featurestr, errp);
-            } else if (!strcmp(featurestr, "level")) {
-                object_property_parse(OBJECT(cpu), val, featurestr, errp);
-            } else if (!strcmp(featurestr, "xlevel")) {
+            if (!strcmp(featurestr, "xlevel")) {
                 char *err;
                 char num[32];
 
@@ -1569,11 +1561,7 @@  static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
                 }
                 snprintf(num, sizeof(num), "%" PRIu32, numvalue);
                 object_property_parse(OBJECT(cpu), num, featurestr, errp);
-            } else if (!strcmp(featurestr, "vendor")) {
-                object_property_parse(OBJECT(cpu), val, featurestr, errp);
-            } else if (!strcmp(featurestr, "model-id")) {
-                object_property_parse(OBJECT(cpu), val, featurestr, errp);
-            } else if (!strcmp(featurestr, "tsc-freq")) {
+           } else if (!strcmp(featurestr, "tsc-freq")) {
                 int64_t tsc_freq;
                 char *err;
                 char num[32];
@@ -1586,11 +1574,8 @@  static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
                 }
                 snprintf(num, sizeof(num), "%" PRId64, tsc_freq);
                 object_property_parse(OBJECT(cpu), num, "tsc-frequency", errp);
-            } else if (!strcmp(featurestr, "hv-spinlocks")) {
-                object_property_parse(OBJECT(cpu), val, featurestr, errp);
             } else {
-                error_setg(errp, "unrecognized feature %s\n", featurestr);
-                goto out;
+                object_property_parse(OBJECT(cpu), val, featurestr, errp);
             }
         } else {
             feat2prop(featurestr);