From: "Jan Beulich" Subject: [PATCH] consolidate custom parameter parsing routines looking for boolean values Date: Thu, 18 Nov 2010 16:57:31 +0000 Message-ID: <4CE5690B020000780002313B@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part705DD4EB.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part705DD4EB.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Have a single function for this, rather than doing the same in half a dozen places. Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -240,13 +240,18 @@ int cpu_has_amd_erratum(const struct cpu * amd_flush_filter=3D{on,off}. Forcibly Enable or disable the TLB flush * filter on AMD 64-bit processors. */ -static int flush_filter_force; -static void flush_filter(char *s) +static int __read_mostly flush_filter_force; +static void __init flush_filter(char *s) { - if (!strcmp(s, "off")) + switch (parse_bool(s)) + { + case 0: flush_filter_force =3D -1; - if (!strcmp(s, "on")) + break; + case 1: flush_filter_force =3D 1; + break; + } } custom_param("amd_flush_filter", flush_filter); =20 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -113,7 +113,7 @@ static void __init parse_acpi_param(char safe_strcpy(acpi_param, s); =20 /* Interpret the parameter for use within Xen. */ - if ( !strcmp(s, "off") ) + if ( !parse_bool(s) ) { disable_acpi(); } --- a/xen/arch/x86/x86_64/mmconfig-shared.c +++ b/xen/arch/x86/x86_64/mmconfig-shared.c @@ -37,8 +37,7 @@ static void __init parse_mmcfg(char *s) if ( ss ) *ss =3D '\0'; =20 - if ( !strcmp(s, "off") || !strcmp(s, "no") || !strcmp(s, "false") = || - !strcmp(s, "0") || !strcmp(s, "disable") ) + if ( !parse_bool(s) ) pci_probe &=3D ~PCI_PROBE_MMCONF; else if ( !strcmp(s, "amd_fam10") || !strcmp(s, "amd-fam10") ) pci_probe |=3D PCI_CHECK_ENABLE_AMD_MMCONF; --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -26,7 +26,7 @@ int tainted; =20 xen_commandline_t saved_cmdline; =20 -void cmdline_parse(char *cmdline) +void __init cmdline_parse(char *cmdline) { char opt[100], *optval, *optkey, *q; const char *p =3D cmdline; @@ -83,10 +83,7 @@ void cmdline_parse(char *cmdline) break; case OPT_BOOL: case OPT_INVBOOL: - if ( !strcmp("no", optval) || - !strcmp("off", optval) || - !strcmp("false", optval) || - !strcmp("0", optval) ) + if ( !parse_bool(optval) ) bool_assert =3D !bool_assert; if ( param->type =3D=3D OPT_INVBOOL ) bool_assert =3D !bool_assert; @@ -115,6 +112,25 @@ void cmdline_parse(char *cmdline) } } =20 +int __init parse_bool(const char *s) +{ + if ( !strcmp("no", s) || + !strcmp("off", s) || + !strcmp("false", s) || + !strcmp("disable", s) || + !strcmp("0", s) ) + return 0; + + if ( !strcmp("yes", s) || + !strcmp("on", s) || + !strcmp("true", s) || + !strcmp("enable", s) || + !strcmp("1", s) ) + return 1; + + return -1; +} + /** * print_tainted - return a string to represent the kernel taint = state. * --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -59,8 +59,7 @@ static void __init parse_iommu_param(cha if ( ss ) *ss =3D '\0'; =20 - if ( !strcmp(s, "off") || !strcmp(s, "no") || !strcmp(s, "false") = || - !strcmp(s, "0") || !strcmp(s, "disable") ) + if ( !parse_bool(s) ) iommu_enabled =3D 0; else if ( !strcmp(s, "force") || !strcmp(s, "required") ) force_iommu =3D 1; --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -58,13 +58,15 @@ static void __init parse_ats_param(char=20 if ( ss ) *ss =3D '\0'; =20 - if ( !strcmp(s, "off") || !strcmp(s, "no") || !strcmp(s, "false") = || - !strcmp(s, "0") || !strcmp(s, "disable") ) + switch ( parse_bool(s) ) + { + case 0: ats_enabled =3D 0; - - if ( !strcmp(s, "on") || !strcmp(s, "yes") || !strcmp(s, "true") = || - !strcmp(s, "1") || !strcmp(s, "enable") ) + break; + case 1: ats_enabled =3D 1; + break; + } =20 s =3D ss + 1; } while ( ss ); --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -57,6 +57,7 @@ do { =20 struct domain; =20 void cmdline_parse(char *cmdline); +int parse_bool(const char *s); =20 /*#define DEBUG_TRACE_DUMP*/ #ifdef DEBUG_TRACE_DUMP --=__Part705DD4EB.0__= Content-Type: text/plain; name="cmdline-bool-parse.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="cmdline-bool-parse.patch" Have a single function for this, rather than doing the same in half = a=0Adozen places.=0A=0ASigned-off-by: Jan Beulich =0A= =0A--- a/xen/arch/x86/cpu/amd.c=0A+++ b/xen/arch/x86/cpu/amd.c=0A@@ = -240,13 +240,18 @@ int cpu_has_amd_erratum(const struct cpu=0A * = amd_flush_filter=3D{on,off}. Forcibly Enable or disable the TLB flush=0A = * filter on AMD 64-bit processors.=0A */=0A-static int flush_filter_force;= =0A-static void flush_filter(char *s)=0A+static int __read_mostly = flush_filter_force;=0A+static void __init flush_filter(char *s)=0A {=0A- = if (!strcmp(s, "off"))=0A+ switch (parse_bool(s))=0A+ {=0A+ = case 0:=0A flush_filter_force =3D -1;=0A- if (!strcmp(s, = "on"))=0A+ break;=0A+ case 1:=0A flush_filte= r_force =3D 1;=0A+ break;=0A+ }=0A }=0A custom_param("amd= _flush_filter", flush_filter);=0A =0A--- a/xen/arch/x86/setup.c=0A+++ = b/xen/arch/x86/setup.c=0A@@ -113,7 +113,7 @@ static void __init parse_acpi_= param(char=0A safe_strcpy(acpi_param, s);=0A =0A /* Interpret the = parameter for use within Xen. */=0A- if ( !strcmp(s, "off") )=0A+ if = ( !parse_bool(s) )=0A {=0A disable_acpi();=0A }=0A--- = a/xen/arch/x86/x86_64/mmconfig-shared.c=0A+++ b/xen/arch/x86/x86_64/mmconfi= g-shared.c=0A@@ -37,8 +37,7 @@ static void __init parse_mmcfg(char *s)=0A = if ( ss )=0A *ss =3D '\0';=0A =0A- if ( = !strcmp(s, "off") || !strcmp(s, "no") || !strcmp(s, "false") ||=0A- = !strcmp(s, "0") || !strcmp(s, "disable") )=0A+ if ( !parse_bool= (s) )=0A pci_probe &=3D ~PCI_PROBE_MMCONF;=0A else if = ( !strcmp(s, "amd_fam10") || !strcmp(s, "amd-fam10") )=0A = pci_probe |=3D PCI_CHECK_ENABLE_AMD_MMCONF;=0A--- a/xen/common/kernel.c=0A+= ++ b/xen/common/kernel.c=0A@@ -26,7 +26,7 @@ int tainted;=0A =0A xen_comman= dline_t saved_cmdline;=0A =0A-void cmdline_parse(char *cmdline)=0A+void = __init cmdline_parse(char *cmdline)=0A {=0A char opt[100], *optval, = *optkey, *q;=0A const char *p =3D cmdline;=0A@@ -83,10 +83,7 @@ void = cmdline_parse(char *cmdline)=0A break;=0A case = OPT_BOOL:=0A case OPT_INVBOOL:=0A- if ( = !strcmp("no", optval) ||=0A- !strcmp("off", optval) = ||=0A- !strcmp("false", optval) ||=0A- = !strcmp("0", optval) )=0A+ if ( !parse_bool(optval) = )=0A bool_assert =3D !bool_assert;=0A = if ( param->type =3D=3D OPT_INVBOOL )=0A bool_assert = =3D !bool_assert;=0A@@ -115,6 +112,25 @@ void cmdline_parse(char = *cmdline)=0A }=0A }=0A =0A+int __init parse_bool(const char *s)=0A+{=0A= + if ( !strcmp("no", s) ||=0A+ !strcmp("off", s) ||=0A+ = !strcmp("false", s) ||=0A+ !strcmp("disable", s) ||=0A+ = !strcmp("0", s) )=0A+ return 0;=0A+=0A+ if ( !strcmp("yes", s) = ||=0A+ !strcmp("on", s) ||=0A+ !strcmp("true", s) ||=0A+ = !strcmp("enable", s) ||=0A+ !strcmp("1", s) )=0A+ = return 1;=0A+=0A+ return -1;=0A+}=0A+=0A /**=0A * print_tainted - = return a string to represent the kernel taint state.=0A *=0A--- a/xen/driv= ers/passthrough/iommu.c=0A+++ b/xen/drivers/passthrough/iommu.c=0A@@ -59,8 = +59,7 @@ static void __init parse_iommu_param(cha=0A if ( ss )=0A = *ss =3D '\0';=0A =0A- if ( !strcmp(s, "off") || = !strcmp(s, "no") || !strcmp(s, "false") ||=0A- !strcmp(s, "0") = || !strcmp(s, "disable") )=0A+ if ( !parse_bool(s) )=0A = iommu_enabled =3D 0;=0A else if ( !strcmp(s, "force") || !strcmp(s,= "required") )=0A force_iommu =3D 1;=0A--- a/xen/drivers/passth= rough/vtd/x86/ats.c=0A+++ b/xen/drivers/passthrough/vtd/x86/ats.c=0A@@ = -58,13 +58,15 @@ static void __init parse_ats_param(char =0A if ( = ss )=0A *ss =3D '\0';=0A =0A- if ( !strcmp(s, "off") || = !strcmp(s, "no") || !strcmp(s, "false") ||=0A- !strcmp(s, "0") = || !strcmp(s, "disable") )=0A+ switch ( parse_bool(s) )=0A+ = {=0A+ case 0:=0A ats_enabled =3D 0;=0A-=0A- if ( = !strcmp(s, "on") || !strcmp(s, "yes") || !strcmp(s, "true") ||=0A- = !strcmp(s, "1") || !strcmp(s, "enable") )=0A+ break;=0A+ = case 1:=0A ats_enabled =3D 1;=0A+ break;=0A+ = }=0A =0A s =3D ss + 1;=0A } while ( ss );=0A--- a/xen/inclu= de/xen/lib.h=0A+++ b/xen/include/xen/lib.h=0A@@ -57,6 +57,7 @@ do { = =0A struct domain;=0A =0A void cmdline_parse(ch= ar *cmdline);=0A+int parse_bool(const char *s);=0A =0A /*#define DEBUG_TRAC= E_DUMP*/=0A #ifdef DEBUG_TRACE_DUMP=0A --=__Part705DD4EB.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part705DD4EB.0__=--