* [PATCH v1] PCI/AER: use match_string() helper to simplify the code
@ 2019-01-28 11:57 Andy Shevchenko
2019-01-29 22:37 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2019-01-28 11:57 UTC (permalink / raw)
To: Russell Currey, Sam Bobroff, Oliver O'Halloran, linuxppc-dev,
Bjorn Helgaas, linux-pci
Cc: Andy Shevchenko
match_string() returns the index of an array for a matching string,
which can be used intead of open coded implementation.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/pci/pcie/aer.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index fed29de783e0..f8fc2114ad39 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -117,7 +117,7 @@ bool pci_aer_available(void)
static int ecrc_policy = ECRC_POLICY_DEFAULT;
-static const char *ecrc_policy_str[] = {
+static const char * const ecrc_policy_str[] = {
[ECRC_POLICY_DEFAULT] = "bios",
[ECRC_POLICY_OFF] = "off",
[ECRC_POLICY_ON] = "on"
@@ -203,11 +203,8 @@ void pcie_ecrc_get_policy(char *str)
{
int i;
- for (i = 0; i < ARRAY_SIZE(ecrc_policy_str); i++)
- if (!strncmp(str, ecrc_policy_str[i],
- strlen(ecrc_policy_str[i])))
- break;
- if (i >= ARRAY_SIZE(ecrc_policy_str))
+ i = match_string(ecrc_policy_str, ARRAY_SIZE(ecrc_policy_str), str);
+ if (i < 0)
return;
ecrc_policy = i;
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] PCI/AER: use match_string() helper to simplify the code
2019-01-28 11:57 [PATCH v1] PCI/AER: use match_string() helper to simplify the code Andy Shevchenko
@ 2019-01-29 22:37 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2019-01-29 22:37 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Russell Currey, Sam Bobroff, Oliver O'Halloran, linuxppc-dev,
linux-pci
On Mon, Jan 28, 2019 at 01:57:28PM +0200, Andy Shevchenko wrote:
> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded implementation.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Applied to pci/aer for v5.1, thanks!
> ---
> drivers/pci/pcie/aer.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
> index fed29de783e0..f8fc2114ad39 100644
> --- a/drivers/pci/pcie/aer.c
> +++ b/drivers/pci/pcie/aer.c
> @@ -117,7 +117,7 @@ bool pci_aer_available(void)
>
> static int ecrc_policy = ECRC_POLICY_DEFAULT;
>
> -static const char *ecrc_policy_str[] = {
> +static const char * const ecrc_policy_str[] = {
> [ECRC_POLICY_DEFAULT] = "bios",
> [ECRC_POLICY_OFF] = "off",
> [ECRC_POLICY_ON] = "on"
> @@ -203,11 +203,8 @@ void pcie_ecrc_get_policy(char *str)
> {
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(ecrc_policy_str); i++)
> - if (!strncmp(str, ecrc_policy_str[i],
> - strlen(ecrc_policy_str[i])))
> - break;
> - if (i >= ARRAY_SIZE(ecrc_policy_str))
> + i = match_string(ecrc_policy_str, ARRAY_SIZE(ecrc_policy_str), str);
> + if (i < 0)
> return;
>
> ecrc_policy = i;
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-29 22:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28 11:57 [PATCH v1] PCI/AER: use match_string() helper to simplify the code Andy Shevchenko
2019-01-29 22:37 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).