Re: [Xen-devel] [PATCH v3 18/52] xen/arch/x86/psr.c: let custom parameter parsing routines return errno

2017-08-23 Thread Juergen Gross
On 22/08/17 11:51, Jan Beulich wrote:
 On 16.08.17 at 14:51,  wrote:
>> Modify the custom parameter parsing routines in:
>>
>> xen/arch/x86/psr.c
>>
>> to indicate whether the parameter value was parsed successfully.
>>
>> Cc: Jan Beulich 
>> Cc: Andrew Cooper 
>> Signed-off-by: Juergen Gross 
> 
> Reviewed-by: Jan Beulich 

This patch suffered from the parse_bool() problem, too.


Juergen


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v3 18/52] xen/arch/x86/psr.c: let custom parameter parsing routines return errno

2017-08-22 Thread Jan Beulich
>>> On 16.08.17 at 14:51,  wrote:
> Modify the custom parameter parsing routines in:
> 
> xen/arch/x86/psr.c
> 
> to indicate whether the parameter value was parsed successfully.
> 
> Cc: Jan Beulich 
> Cc: Andrew Cooper 
> Signed-off-by: Juergen Gross 

Reviewed-by: Jan Beulich 



___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v3 18/52] xen/arch/x86/psr.c: let custom parameter parsing routines return errno

2017-08-16 Thread Juergen Gross
Modify the custom parameter parsing routines in:

xen/arch/x86/psr.c

to indicate whether the parameter value was parsed successfully.

Cc: Jan Beulich 
Cc: Andrew Cooper 
Signed-off-by: Juergen Gross 
---
V3:
- let parse_psr_bool() return bool value (Jan Beulich)
- return error in case no string matches (Jan Beulich)
- dont modify option value in parsing function
---
 xen/arch/x86/psr.c | 57 ++
 1 file changed, 36 insertions(+), 21 deletions(-)

diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c
index c2036cbed4..fe4f59b651 100644
--- a/xen/arch/x86/psr.c
+++ b/xen/arch/x86/psr.c
@@ -418,50 +418,65 @@ static const struct feat_props l2_cat_props = {
 .write_msr = l2_cat_write_msr,
 };
 
-static void __init parse_psr_bool(char *s, char *value, char *feature,
-  unsigned int mask)
+static bool __init parse_psr_bool(const char *s, const char *value,
+  const char *feature, unsigned int mask)
 {
-if ( !strcmp(s, feature) )
+if ( !strncmp(s, feature, value - s) )
 {
-if ( !value )
+if ( !*value )
 opt_psr |= mask;
 else
 {
-int val_int = parse_bool(value);
+int val_int = parse_bool(value + 1);
 
 if ( val_int == 0 )
 opt_psr &= ~mask;
 else if ( val_int == 1 )
 opt_psr |= mask;
+else
+return false;
 }
+return true;
 }
+return false;
 }
 
-static void __init parse_psr_param(char *s)
+static int __init parse_psr_param(const char *s)
 {
-char *ss, *val_str;
+const char *ss, *val_str;
+const char *q;
+int rc = 0;
 
 do {
 ss = strchr(s, ',');
-if ( ss )
-*ss = '\0';
+if ( !ss )
+ss = strchr(s, '\0');
 
 val_str = strchr(s, ':');
-if ( val_str )
-*val_str++ = '\0';
-
-parse_psr_bool(s, val_str, "cmt", PSR_CMT);
-parse_psr_bool(s, val_str, "cat", PSR_CAT);
-parse_psr_bool(s, val_str, "cdp", PSR_CDP);
+if ( !val_str )
+val_str = strchr(s, '\0');
 
-if ( val_str && !strcmp(s, "rmid_max") )
-opt_rmid_max = simple_strtoul(val_str, NULL, 0);
-
-if ( val_str && !strcmp(s, "cos_max") )
-opt_cos_max = simple_strtoul(val_str, NULL, 0);
+if ( *val_str && !strncmp(s, "rmid_max", val_str - s) )
+{
+opt_rmid_max = simple_strtoul(val_str + 1, , 0);
+if ( *q && *q != ',' )
+rc = -EINVAL;
+}
+else if ( *val_str && !strncmp(s, "cos_max", val_str - s) )
+{
+opt_cos_max = simple_strtoul(val_str + 1, , 0);
+if ( *q && *q != ',' )
+rc = -EINVAL;
+}
+else if ( !parse_psr_bool(s, val_str, "cmt", PSR_CMT) &&
+  !parse_psr_bool(s, val_str, "cat", PSR_CAT) &&
+  !parse_psr_bool(s, val_str, "cdp", PSR_CDP) )
+rc = -EINVAL;
 
 s = ss + 1;
-} while ( ss );
+} while ( *ss );
+
+return rc;
 }
 custom_param("psr", parse_psr_param);
 
-- 
2.12.3


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel