]> xenbits.xensource.com Git - xen.git/commitdiff
xen: add an optional string end parameter to parse_bool()
authorJuergen Gross <jgross@suse.com>
Wed, 23 Aug 2017 17:34:00 +0000 (19:34 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 25 Aug 2017 14:11:42 +0000 (16:11 +0200)
Add a parameter to parse_bool() to specify the end of the to be
parsed string. Specifying it as NULL will preserve the current
behavior to parse until the end of the input string, while passing
a non-NULL pointer will specify the first character after the input
string.

This will allow to parse boolean sub-strings without having to
write a NUL byte into the input string.

Modify all users of parse_bool() to pass NULL for the new parameter.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
13 files changed:
xen/arch/arm/acpi/boot.c
xen/arch/x86/cpu/vpmu.c
xen/arch/x86/mm.c
xen/arch/x86/nmi.c
xen/arch/x86/psr.c
xen/arch/x86/setup.c
xen/arch/x86/x86_64/mmconfig-shared.c
xen/common/kernel.c
xen/drivers/char/console.c
xen/drivers/cpufreq/cpufreq.c
xen/drivers/passthrough/iommu.c
xen/drivers/passthrough/vtd/quirks.c
xen/include/xen/lib.h

index 889208a0ea6130bb2ee4d00cac51a3d490237759..a5a6f55f0e8c6c9291fd98e2703017d49876ace8 100644 (file)
@@ -199,7 +199,7 @@ static void __init parse_acpi_param(char *arg)
         return;
 
     /* Interpret the parameter for use within Xen. */
-    if ( !parse_bool(arg) )
+    if ( !parse_bool(arg, NULL) )
         param_acpi_off = true;
     else if ( !strcmp(arg, "force") ) /* force ACPI to be enabled */
         param_acpi_force = true;
index 90954ca884684f2d42dcf23e461908c1ec6efd47..1c0ea10777c97d3a305b4e535fd35ae08ca8a842 100644 (file)
@@ -80,7 +80,7 @@ static void __init parse_vpmu_params(char *s)
 {
     char *sep, *p = s;
 
-    switch ( parse_bool(s) )
+    switch ( parse_bool(s, NULL) )
     {
     case 0:
         break;
index c3bc7a65fe6aaa398fb818c043b7b1a427947b4f..9a643af61d94a4928ced71140d899948fbdc4fa5 100644 (file)
@@ -184,7 +184,7 @@ static void __init parse_mmio_relax(const char *s)
     if ( !*s )
         opt_mmio_relax = 1;
     else
-        opt_mmio_relax = parse_bool(s);
+        opt_mmio_relax = parse_bool(s, NULL);
     if ( opt_mmio_relax < 0 && strcmp(s, "all") )
         opt_mmio_relax = 0;
 }
index 8914581f66b491a58cb8bd6304f6c1af94de0fa8..e44f88045ef1daf1c0327285a31bd315b54e8777 100644 (file)
@@ -54,7 +54,7 @@ static void __init parse_watchdog(char *s)
         return;
     }
 
-    switch ( parse_bool(s) )
+    switch ( parse_bool(s, NULL) )
     {
     case 0:
         opt_watchdog = false;
index c2036cbed4ab5cbd3d4e88b52afb20220e97ae25..25a85b65b250010d51e5d308200aae396d2275c0 100644 (file)
@@ -427,7 +427,7 @@ static void __init parse_psr_bool(char *s, char *value, char *feature,
             opt_psr |= mask;
         else
         {
-            int val_int = parse_bool(value);
+            int val_int = parse_bool(value, NULL);
 
             if ( val_int == 0 )
                 opt_psr &= ~mask;
index db5df6956de3449d8e235ce4c4425d9b9f0eaebf..414681d5a1bd62525d3a2217df4f614ede77a16f 100644 (file)
@@ -110,7 +110,7 @@ static void __init parse_smep_param(char *s)
         return;
     }
 
-    switch ( parse_bool(s) )
+    switch ( parse_bool(s, NULL) )
     {
     case 0:
         opt_smep = 0;
@@ -136,7 +136,7 @@ static void __init parse_smap_param(char *s)
         return;
     }
 
-    switch ( parse_bool(s) )
+    switch ( parse_bool(s, NULL) )
     {
     case 0:
         opt_smap = 0;
@@ -160,7 +160,7 @@ static void __init parse_acpi_param(char *s)
     safe_strcpy(acpi_param, s);
 
     /* Interpret the parameter for use within Xen. */
-    if ( !parse_bool(s) )
+    if ( !parse_bool(s, NULL) )
     {
         disable_acpi();
     }
index 488470bfebfa82715b40af43c49e74c3edea4d03..dbf9ff07fa1692cc2375ffbbf76a7f77b80aea0d 100644 (file)
@@ -37,7 +37,7 @@ static void __init parse_mmcfg(char *s)
         if ( ss )
             *ss = '\0';
 
-        if ( !parse_bool(s) )
+        if ( !parse_bool(s, NULL) )
             pci_probe &= ~PCI_PROBE_MMCONF;
         else if ( !strcmp(s, "amd_fam10") || !strcmp(s, "amd-fam10") )
             pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
index ce7cb8adb5b57bb5d161169d72644ee681f31614..ec7714961aec1b9eea62b24d52d13720723ab51a 100644 (file)
@@ -114,7 +114,7 @@ static void __init _cmdline_parse(const char *cmdline)
                     simple_strtoll(optval, NULL, 0));
                 break;
             case OPT_BOOL:
-                if ( !parse_bool(optval) )
+                if ( !parse_bool(optval, NULL) )
                     bool_assert = !bool_assert;
                 assign_integer_param(param, bool_assert);
                 break;
@@ -163,20 +163,24 @@ void __init cmdline_parse(const char *cmdline)
 #endif
 }
 
-int __init parse_bool(const char *s)
+int __init parse_bool(const char *s, const char *e)
 {
-    if ( !strcmp("no", s) ||
-         !strcmp("off", s) ||
-         !strcmp("false", s) ||
-         !strcmp("disable", s) ||
-         !strcmp("0", s) )
+    unsigned int len;
+
+    len = e ? ({ ASSERT(e >= s); e - s; }) : strlen(s);
+
+    if ( !strncmp("no", s, len) ||
+         !strncmp("off", s, len) ||
+         !strncmp("false", s, len) ||
+         !strncmp("disable", s, len) ||
+         !strncmp("0", s, len) )
         return 0;
 
-    if ( !strcmp("yes", s) ||
-         !strcmp("on", s) ||
-         !strcmp("true", s) ||
-         !strcmp("enable", s) ||
-         !strcmp("1", s) )
+    if ( !strncmp("yes", s, len) ||
+         !strncmp("on", s, len) ||
+         !strncmp("true", s, len) ||
+         !strncmp("enable", s, len) ||
+         !strncmp("1", s, len) )
         return 1;
 
     return -1;
index f0659fba1b0d91e7d8b860bf2c15b018d29ad1f8..8f2a24496a16c7a50cfd530d3bc468c7706cda9a 100644 (file)
@@ -605,7 +605,7 @@ static int printk_prefix_check(char *p, char **pp)
 
 static void __init parse_console_timestamps(char *s)
 {
-    switch ( parse_bool(s) )
+    switch ( parse_bool(s, NULL) )
     {
     case 0:
         opt_con_timestamp_mode = TSM_NONE;
index fd82ef5dced61d59bcd557a9720f75df55067cd9..5580bd370dbcdc1b652c7fdd949030fc80cac13f 100644 (file)
@@ -69,7 +69,7 @@ static void __init setup_cpufreq_option(char *str)
 
     if ( arg )
         *arg++ = '\0';
-    choice = parse_bool(str);
+    choice = parse_bool(str, NULL);
 
     if ( choice < 0 && !strcmp(str, "dom0-kernel") )
     {
index 5e81813942687d82e367e53913263fb029315807..f1aefc47cee9dc5ec1298e2a6981f303b97fb746 100644 (file)
@@ -92,7 +92,7 @@ static void __init parse_iommu_param(char *s)
         if ( ss )
             *ss = '\0';
 
-        if ( !parse_bool(s) )
+        if ( !parse_bool(s, NULL) )
             iommu_enable = 0;
         else if ( !strcmp(s, "force") || !strcmp(s, "required") )
             force_iommu = val;
index 5bbbd96d51b530c763e805bf444e64c243516845..d6dd671dbf96451a6bbf5fe3a5f488eb8f87d8f3 100644 (file)
@@ -251,7 +251,7 @@ static void __init parse_snb_timeout(const char *s)
 {
     int t;
 
-    t = parse_bool(s);
+    t = parse_bool(s, NULL);
     if ( t < 0 )
     {
         if ( *s == '\0' )
index 995a85a7db2dbcdf9e3778c0376ea161e3e39917..8e57bbd0212cf66ddc6387fa460cb0524d060c05 100644 (file)
@@ -71,7 +71,7 @@
 struct domain;
 
 void cmdline_parse(const char *cmdline);
-int parse_bool(const char *s);
+int parse_bool(const char *s, const char *e);
 
 /*#define DEBUG_TRACE_DUMP*/
 #ifdef DEBUG_TRACE_DUMP