[PATCH] leds: pwm: fix max_brightness works abnormal when active_low

2019-02-10 Thread Yisheng Xie
When leds-pwm is active_low, smaller number of  duty kept in led_dat
means less brighness, so we should disable pwm when led_dat->duty is
equal to period instead of zero, which means max_brightness.

Signed-off-by: Yisheng Xie 
---
 drivers/leds/leds-pwm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index df80c89..07fb772 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -41,7 +41,7 @@ static void __led_pwm_set(struct led_pwm_data *led_dat)
 
pwm_config(led_dat->pwm, new_duty, led_dat->period);
 
-   if (new_duty == 0)
+   if (led_dat->active_low ? new_duty == led_dat->period : new_duty == 0)
pwm_disable(led_dat->pwm);
else
pwm_enable(led_dat->pwm);
-- 
1.9.1




[PATCH v4 21/21] sparc64: use match_string() helper

2018-06-20 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

As Andy's suggestion, this patch add string literal instead of NULL
for crypto in array of hwcaps and make an additional condition after
match_string() in all users of it.

Cc: "David S. Miller" 
Cc: Anthony Yznaga 
Cc: Pavel Tatashin 
Cc: sparcli...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
 arch/sparc/kernel/setup_64.c | 24 +---
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 7944b3c..6fa0c78 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -401,8 +401,7 @@ void __init start_early_boot(void)
 */
"mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
"ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-   "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
-   "adp",
+   "ima", "cspare", "pause", "cbcond", "crypto", "adp",
 };

 static const char *crypto_hwcaps[] = {
@@ -418,7 +417,7 @@ void cpucap_info(struct seq_file *m)
seq_puts(m, "cpucaps\t\t: ");
for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;
-   if (hwcaps[i] && (caps & bit)) {
+   if ((caps & bit) && bit != HWCAP_SPARC_CRYPTO) {
seq_printf(m, "%s%s",
   printed ? "," : "", hwcaps[i]);
printed++;
@@ -472,7 +471,7 @@ static void __init report_hwcaps(unsigned long caps)

for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;
-   if (hwcaps[i] && (caps & bit))
+   if ((caps & bit) && bit != HWCAP_SPARC_CRYPTO)
report_one_hwcap(, hwcaps[i]);
}
if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +503,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
while (len) {
int i, plen;

-   for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-   unsigned long bit = 1UL << i;
+   i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+   if (i >= 0)
+   caps |= 1UL << i;

-   if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-   caps |= bit;
-   break;
-   }
-   }
-   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-   if (!strcmp(prop, crypto_hwcaps[i]))
-   caps |= HWCAP_SPARC_CRYPTO;
-   }
+   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
prop);
+   if (i >= 0)
+   caps |= HWCAP_SPARC_CRYPTO;

plen = strlen(prop) + 1;
prop += plen;
-- 
1.7.12.4




[PATCH v4 21/21] sparc64: use match_string() helper

2018-06-20 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

As Andy's suggestion, this patch add string literal instead of NULL
for crypto in array of hwcaps and make an additional condition after
match_string() in all users of it.

Cc: "David S. Miller" 
Cc: Anthony Yznaga 
Cc: Pavel Tatashin 
Cc: sparcli...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
 arch/sparc/kernel/setup_64.c | 24 +---
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 7944b3c..6fa0c78 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -401,8 +401,7 @@ void __init start_early_boot(void)
 */
"mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
"ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-   "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
-   "adp",
+   "ima", "cspare", "pause", "cbcond", "crypto", "adp",
 };

 static const char *crypto_hwcaps[] = {
@@ -418,7 +417,7 @@ void cpucap_info(struct seq_file *m)
seq_puts(m, "cpucaps\t\t: ");
for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;
-   if (hwcaps[i] && (caps & bit)) {
+   if ((caps & bit) && bit != HWCAP_SPARC_CRYPTO) {
seq_printf(m, "%s%s",
   printed ? "," : "", hwcaps[i]);
printed++;
@@ -472,7 +471,7 @@ static void __init report_hwcaps(unsigned long caps)

for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;
-   if (hwcaps[i] && (caps & bit))
+   if ((caps & bit) && bit != HWCAP_SPARC_CRYPTO)
report_one_hwcap(, hwcaps[i]);
}
if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +503,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
while (len) {
int i, plen;

-   for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-   unsigned long bit = 1UL << i;
+   i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+   if (i >= 0)
+   caps |= 1UL << i;

-   if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-   caps |= bit;
-   break;
-   }
-   }
-   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-   if (!strcmp(prop, crypto_hwcaps[i]))
-   caps |= HWCAP_SPARC_CRYPTO;
-   }
+   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
prop);
+   if (i >= 0)
+   caps |= HWCAP_SPARC_CRYPTO;

plen = strlen(prop) + 1;
prop += plen;
-- 
1.7.12.4




Re: [PATCH v3 21/21] sparc64: use match_string() helper

2018-06-20 Thread Yisheng Xie
Hi Andy,

Sorry for late response. I will take your suggestion in next version.

Thanks
Yisheng

On 2018/6/6 13:01, Andy Shevchenko wrote:
> On Wed, Jun 6, 2018 at 5:19 AM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
> 
> Thanks for an update.
> My comments below.
> 
> I think you need to mentioned the string literal change in the commit message.
> 
>> Cc: "David S. Miller" 
>> Cc: Anthony Yznaga 
>> Cc: Pavel Tatashin 
>> Cc: sparcli...@vger.kernel.org
>> Signed-off-by: Yisheng Xie 
>> ---
>> v3:
>>  - add string literal instead of NULL for array hwcaps to make it
>>can use match_string() too.  - per Andy
>> v2
>>  - new add for use match_string() helper patchset.
>>
>>  arch/sparc/kernel/setup_64.c | 23 +--
>>  1 file changed, 9 insertions(+), 14 deletions(-)
>>
>> diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
>> index 7944b3c..4f0ec0c 100644
>> --- a/arch/sparc/kernel/setup_64.c
>> +++ b/arch/sparc/kernel/setup_64.c
>> @@ -401,7 +401,7 @@ void __init start_early_boot(void)
>>  */
>> "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
>> "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
>> -   "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
>> +   "ima", "cspare", "pause", "cbcond", "resv" /*reserved for crypto */,
>> "adp",
> 
> Why not to spell "crypto" explicitly and remove comment?
> 
>>  };
>>
>> @@ -418,7 +418,7 @@ void cpucap_info(struct seq_file *m)
>> seq_puts(m, "cpucaps\t\t: ");
>> for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
>> unsigned long bit = 1UL << i;
>> -   if (hwcaps[i] && (caps & bit)) {
>> +   if (bit != HWCAP_SPARC_CRYPTO && (caps & bit)) {
> 
> I would rather swap the order of subsonditions to check if caps has a
> bit first, and then exclude CRYPTO.
> 
>> seq_printf(m, "%s%s",
>>printed ? "," : "", hwcaps[i]);
>> printed++;
>> @@ -472,7 +472,7 @@ static void __init report_hwcaps(unsigned long caps)
>>
>> for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
>> unsigned long bit = 1UL << i;
>> -   if (hwcaps[i] && (caps & bit))
>> +   if (bit != HWCAP_SPARC_CRYPTO && (caps & bit))
>> report_one_hwcap(, hwcaps[i]);
> 
> Ditto.
> 
>> }
>> if (caps & HWCAP_SPARC_CRYPTO)
>> @@ -504,18 +504,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
>> while (len) {
>> int i, plen;
>>
>> -   for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
>> -   unsigned long bit = 1UL << i;
>> +   i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
>> +   if (i >= 0)
>> +   caps |= (1UL << i);
> 
> Parens are redundant (and actually didn't present in the original code above).
> 
>>
>> -   if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
>> -   caps |= bit;
>> -   break;
>> -   }
>> -   }
>> -   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
>> -   if (!strcmp(prop, crypto_hwcaps[i]))
>> -   caps |= HWCAP_SPARC_CRYPTO;
>> -   }
>> +   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
>> prop);
>> +   if (i >= 0)
>> +   caps |= HWCAP_SPARC_CRYPTO;
>>
>> plen = strlen(prop) + 1;
>> prop += plen;
>> --
>> 1.7.12.4
>>
>>
>>
> 
> 
> 



Re: [PATCH v3 21/21] sparc64: use match_string() helper

2018-06-20 Thread Yisheng Xie
Hi Andy,

Sorry for late response. I will take your suggestion in next version.

Thanks
Yisheng

On 2018/6/6 13:01, Andy Shevchenko wrote:
> On Wed, Jun 6, 2018 at 5:19 AM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
> 
> Thanks for an update.
> My comments below.
> 
> I think you need to mentioned the string literal change in the commit message.
> 
>> Cc: "David S. Miller" 
>> Cc: Anthony Yznaga 
>> Cc: Pavel Tatashin 
>> Cc: sparcli...@vger.kernel.org
>> Signed-off-by: Yisheng Xie 
>> ---
>> v3:
>>  - add string literal instead of NULL for array hwcaps to make it
>>can use match_string() too.  - per Andy
>> v2
>>  - new add for use match_string() helper patchset.
>>
>>  arch/sparc/kernel/setup_64.c | 23 +--
>>  1 file changed, 9 insertions(+), 14 deletions(-)
>>
>> diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
>> index 7944b3c..4f0ec0c 100644
>> --- a/arch/sparc/kernel/setup_64.c
>> +++ b/arch/sparc/kernel/setup_64.c
>> @@ -401,7 +401,7 @@ void __init start_early_boot(void)
>>  */
>> "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
>> "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
>> -   "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
>> +   "ima", "cspare", "pause", "cbcond", "resv" /*reserved for crypto */,
>> "adp",
> 
> Why not to spell "crypto" explicitly and remove comment?
> 
>>  };
>>
>> @@ -418,7 +418,7 @@ void cpucap_info(struct seq_file *m)
>> seq_puts(m, "cpucaps\t\t: ");
>> for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
>> unsigned long bit = 1UL << i;
>> -   if (hwcaps[i] && (caps & bit)) {
>> +   if (bit != HWCAP_SPARC_CRYPTO && (caps & bit)) {
> 
> I would rather swap the order of subsonditions to check if caps has a
> bit first, and then exclude CRYPTO.
> 
>> seq_printf(m, "%s%s",
>>printed ? "," : "", hwcaps[i]);
>> printed++;
>> @@ -472,7 +472,7 @@ static void __init report_hwcaps(unsigned long caps)
>>
>> for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
>> unsigned long bit = 1UL << i;
>> -   if (hwcaps[i] && (caps & bit))
>> +   if (bit != HWCAP_SPARC_CRYPTO && (caps & bit))
>> report_one_hwcap(, hwcaps[i]);
> 
> Ditto.
> 
>> }
>> if (caps & HWCAP_SPARC_CRYPTO)
>> @@ -504,18 +504,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
>> while (len) {
>> int i, plen;
>>
>> -   for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
>> -   unsigned long bit = 1UL << i;
>> +   i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
>> +   if (i >= 0)
>> +   caps |= (1UL << i);
> 
> Parens are redundant (and actually didn't present in the original code above).
> 
>>
>> -   if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
>> -   caps |= bit;
>> -   break;
>> -   }
>> -   }
>> -   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
>> -   if (!strcmp(prop, crypto_hwcaps[i]))
>> -   caps |= HWCAP_SPARC_CRYPTO;
>> -   }
>> +   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
>> prop);
>> +   if (i >= 0)
>> +   caps |= HWCAP_SPARC_CRYPTO;
>>
>> plen = strlen(prop) + 1;
>> prop += plen;
>> --
>> 1.7.12.4
>>
>>
>>
> 
> 
> 



[PATCH v3 03/21] Staging: gdm724x: use match_string() helper

2018-06-05 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Greg Kroah-Hartman 
Cc: Quytelda Kahja 
Cc: de...@driverdev.osuosl.org
Signed-off-by: Yisheng Xie 
---
v3:
 - no need to check input tty's index - per Greg
v2:
 - const DRIVER_STRING instead  - per Andy

 drivers/staging/gdm724x/gdm_tty.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_tty.c 
b/drivers/staging/gdm724x/gdm_tty.c
index 3cdebb8..29ac6b5 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -43,7 +43,7 @@
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
 static DEFINE_MUTEX(gdm_table_lock);

-static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
 static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};

 static void gdm_port_destruct(struct tty_port *port)
@@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, 
struct tty_struct *tty)
 {
struct gdm *gdm = NULL;
int ret;
-   int i;
-   int j;
-
-   j = GDM_TTY_MINOR;
-   for (i = 0; i < TTY_MAX_COUNT; i++) {
-   if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
-   j = tty->index;
-   break;
-   }
-   }

-   if (j == GDM_TTY_MINOR)
+   ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
+  tty->driver->driver_name);
+   if (ret < 0)
return -ENODEV;

mutex_lock(_table_lock);
-   gdm = gdm_table[i][j];
+   gdm = gdm_table[ret][tty->index];
if (!gdm) {
mutex_unlock(_table_lock);
return -ENODEV;
-- 
1.7.12.4





[PATCH v3 03/21] Staging: gdm724x: use match_string() helper

2018-06-05 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Greg Kroah-Hartman 
Cc: Quytelda Kahja 
Cc: de...@driverdev.osuosl.org
Signed-off-by: Yisheng Xie 
---
v3:
 - no need to check input tty's index - per Greg
v2:
 - const DRIVER_STRING instead  - per Andy

 drivers/staging/gdm724x/gdm_tty.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_tty.c 
b/drivers/staging/gdm724x/gdm_tty.c
index 3cdebb8..29ac6b5 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -43,7 +43,7 @@
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
 static DEFINE_MUTEX(gdm_table_lock);

-static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
 static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};

 static void gdm_port_destruct(struct tty_port *port)
@@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, 
struct tty_struct *tty)
 {
struct gdm *gdm = NULL;
int ret;
-   int i;
-   int j;
-
-   j = GDM_TTY_MINOR;
-   for (i = 0; i < TTY_MAX_COUNT; i++) {
-   if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
-   j = tty->index;
-   break;
-   }
-   }

-   if (j == GDM_TTY_MINOR)
+   ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
+  tty->driver->driver_name);
+   if (ret < 0)
return -ENODEV;

mutex_lock(_table_lock);
-   gdm = gdm_table[i][j];
+   gdm = gdm_table[ret][tty->index];
if (!gdm) {
mutex_unlock(_table_lock);
return -ENODEV;
-- 
1.7.12.4





[PATCH v3 21/21] sparc64: use match_string() helper

2018-06-05 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: "David S. Miller" 
Cc: Anthony Yznaga 
Cc: Pavel Tatashin 
Cc: sparcli...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v3:
 - add string literal instead of NULL for array hwcaps to make it
   can use match_string() too.  - per Andy
v2
 - new add for use match_string() helper patchset.

 arch/sparc/kernel/setup_64.c | 23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 7944b3c..4f0ec0c 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -401,7 +401,7 @@ void __init start_early_boot(void)
 */
"mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
"ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-   "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
+   "ima", "cspare", "pause", "cbcond", "resv" /*reserved for crypto */,
"adp",
 };

@@ -418,7 +418,7 @@ void cpucap_info(struct seq_file *m)
seq_puts(m, "cpucaps\t\t: ");
for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;
-   if (hwcaps[i] && (caps & bit)) {
+   if (bit != HWCAP_SPARC_CRYPTO && (caps & bit)) {
seq_printf(m, "%s%s",
   printed ? "," : "", hwcaps[i]);
printed++;
@@ -472,7 +472,7 @@ static void __init report_hwcaps(unsigned long caps)

for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;
-   if (hwcaps[i] && (caps & bit))
+   if (bit != HWCAP_SPARC_CRYPTO && (caps & bit))
report_one_hwcap(, hwcaps[i]);
}
if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +504,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
while (len) {
int i, plen;

-   for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-   unsigned long bit = 1UL << i;
+   i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+   if (i >= 0)
+   caps |= (1UL << i);

-   if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-   caps |= bit;
-   break;
-   }
-   }
-   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-   if (!strcmp(prop, crypto_hwcaps[i]))
-   caps |= HWCAP_SPARC_CRYPTO;
-   }
+   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
prop);
+   if (i >= 0)
+   caps |= HWCAP_SPARC_CRYPTO;

plen = strlen(prop) + 1;
prop += plen;
-- 
1.7.12.4





[PATCH v3 21/21] sparc64: use match_string() helper

2018-06-05 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: "David S. Miller" 
Cc: Anthony Yznaga 
Cc: Pavel Tatashin 
Cc: sparcli...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v3:
 - add string literal instead of NULL for array hwcaps to make it
   can use match_string() too.  - per Andy
v2
 - new add for use match_string() helper patchset.

 arch/sparc/kernel/setup_64.c | 23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 7944b3c..4f0ec0c 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -401,7 +401,7 @@ void __init start_early_boot(void)
 */
"mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
"ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-   "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
+   "ima", "cspare", "pause", "cbcond", "resv" /*reserved for crypto */,
"adp",
 };

@@ -418,7 +418,7 @@ void cpucap_info(struct seq_file *m)
seq_puts(m, "cpucaps\t\t: ");
for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;
-   if (hwcaps[i] && (caps & bit)) {
+   if (bit != HWCAP_SPARC_CRYPTO && (caps & bit)) {
seq_printf(m, "%s%s",
   printed ? "," : "", hwcaps[i]);
printed++;
@@ -472,7 +472,7 @@ static void __init report_hwcaps(unsigned long caps)

for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
unsigned long bit = 1UL << i;
-   if (hwcaps[i] && (caps & bit))
+   if (bit != HWCAP_SPARC_CRYPTO && (caps & bit))
report_one_hwcap(, hwcaps[i]);
}
if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +504,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
while (len) {
int i, plen;

-   for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-   unsigned long bit = 1UL << i;
+   i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+   if (i >= 0)
+   caps |= (1UL << i);

-   if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-   caps |= bit;
-   break;
-   }
-   }
-   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-   if (!strcmp(prop, crypto_hwcaps[i]))
-   caps |= HWCAP_SPARC_CRYPTO;
-   }
+   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
prop);
+   if (i >= 0)
+   caps |= HWCAP_SPARC_CRYPTO;

plen = strlen(prop) + 1;
prop += plen;
-- 
1.7.12.4





Re: [PATCH v3 1/2] PCI: Avoid panic when PCI IO resource's size is not page aligned

2018-06-05 Thread Yisheng Xie
Hi Bjorn,

On 2018/6/6 7:53, Bjorn Helgaas wrote:
> On Tue, May 29, 2018 at 08:18:18PM +0800, Yisheng Xie wrote:
>> Zhou reported a bug on Hisilicon arm64 D06 platform with 64KB page size:
>>
>>  [2.470908] kernel BUG at lib/ioremap.c:72!
>>  [2.475079] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
>>  [2.480551] Modules linked in:
>>  [2.483594] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 
>> 4.16.0-rc7-00062-g0b41260-dirty #23
>>  [2.491756] Hardware name: Huawei D06/D06, BIOS Hisilicon D06 UEFI Nemo 
>> 2.0 RC0 - B120 03/23/2018
>>  [2.500614] pstate: 80c9 (Nzcv daif +PAN +UAO)
>>  [2.505395] pc : ioremap_page_range+0x268/0x36c
>>  [2.509912] lr : pci_remap_iospace+0xe4/0x100
>>  [...]
>>  [2.603733] Call trace:
>>  [2.606168]  ioremap_page_range+0x268/0x36c
>>  [2.610337]  pci_remap_iospace+0xe4/0x100
>>  [2.614334]  acpi_pci_probe_root_resources+0x1d4/0x214
>>  [2.619460]  pci_acpi_root_prepare_resources+0x18/0xa8
>>  [2.624585]  acpi_pci_root_create+0x98/0x214
>>  [2.628843]  pci_acpi_scan_root+0x124/0x20c
>>  [2.633013]  acpi_pci_root_add+0x224/0x494
>>  [2.637096]  acpi_bus_attach+0xf8/0x200
>>  [2.640918]  acpi_bus_attach+0x98/0x200
>>  [2.644740]  acpi_bus_attach+0x98/0x200
>>  [2.648562]  acpi_bus_scan+0x48/0x9c
>>  [2.652125]  acpi_scan_init+0x104/0x268
>>  [2.655948]  acpi_init+0x308/0x374
>>  [2.659337]  do_one_initcall+0x48/0x14c
>>  [2.663160]  kernel_init_freeable+0x19c/0x250
>>  [2.667504]  kernel_init+0x10/0x100
>>  [2.670979]  ret_from_fork+0x10/0x18
>>
>> The cause is the size of PCI IO resource is 32KB, which is 4K aligned but
>> not 64KB aligned, however, ioremap_page_range() request the range as page
>> aligned or it will trigger a BUG_ON() on ioremap_pte_range() it calls, as
>> ioremap_pte_range increase the addr by PAGE_SIZE, which makes addr != end
>> until trigger BUG_ON, if its incoming end is not page aligned. More detail
>> trace is as following:
>>
>>  ioremap_page_range
>>  -> ioremap_p4d_range
>> -> ioremap_p4d_range
>>    -> ioremap_pud_range
>>   -> ioremap_pmd_range
>>  -> ioremap_pte_range
>>
>> This patch avoid panic by return -EINVAL if vaddr or resource size is not
>> page aligned.
>>
>> Reported-by: Zhou Wang 
>> Tested-by: Xiaojun Tan 
>> Signed-off-by: Yisheng Xie 
>> ---
>> v3:
>>  - pci_remap_iospace() sanitize its arguments instead - per Rafael
>>
>> v2:
>>  - Let the caller of ioremap_page_range() align the request by PAGE_SIZE - 
>> per Toshi
>>
>>  drivers/pci/pci.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>> index dbfe7c4..0eb0381 100644
>> --- a/drivers/pci/pci.c
>> +++ b/drivers/pci/pci.c
>> @@ -3544,6 +3544,9 @@ int pci_remap_iospace(const struct resource *res, 
>> phys_addr_t phys_addr)
>>  if (res->end > IO_SPACE_LIMIT)
>>  return -EINVAL;
>>  
>> +if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res)))
>> +return -EINVAL;
> 
> Most other callers of ioremap_page_range() are in the ioremap() path,
> and they align phys_addr themselves.  In some cases that results in a
> mapping that covers more than necessary.  For instance, see the
> function comment at the x86 version of __ioremap_caller().
> 
> Is there any reason we couldn't similarly align vaddr and phys_addr
> here?
> 
> The acpi_pci_probe_root_resources() path you mention above basically
> ignores the errors you're returning.  Your patches will avoid the
> panic, which is an improvement, but I/O port space will not work, and
> I don't see anything that gives the user a hint about why not.
> 
> If we could align vaddr and phys_addr (and possibly map more than
> necessary), I/O port space would still work.

Right, I will send another version, soon.

Thanks
Yisheng
> 
>>  return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
>>pgprot_device(PAGE_KERNEL));
>>  #else
>> -- 
>> 1.7.12.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
>> the body of a message to majord...@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> .
> 



Re: [PATCH v3 1/2] PCI: Avoid panic when PCI IO resource's size is not page aligned

2018-06-05 Thread Yisheng Xie
Hi Bjorn,

On 2018/6/6 7:53, Bjorn Helgaas wrote:
> On Tue, May 29, 2018 at 08:18:18PM +0800, Yisheng Xie wrote:
>> Zhou reported a bug on Hisilicon arm64 D06 platform with 64KB page size:
>>
>>  [2.470908] kernel BUG at lib/ioremap.c:72!
>>  [2.475079] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
>>  [2.480551] Modules linked in:
>>  [2.483594] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 
>> 4.16.0-rc7-00062-g0b41260-dirty #23
>>  [2.491756] Hardware name: Huawei D06/D06, BIOS Hisilicon D06 UEFI Nemo 
>> 2.0 RC0 - B120 03/23/2018
>>  [2.500614] pstate: 80c9 (Nzcv daif +PAN +UAO)
>>  [2.505395] pc : ioremap_page_range+0x268/0x36c
>>  [2.509912] lr : pci_remap_iospace+0xe4/0x100
>>  [...]
>>  [2.603733] Call trace:
>>  [2.606168]  ioremap_page_range+0x268/0x36c
>>  [2.610337]  pci_remap_iospace+0xe4/0x100
>>  [2.614334]  acpi_pci_probe_root_resources+0x1d4/0x214
>>  [2.619460]  pci_acpi_root_prepare_resources+0x18/0xa8
>>  [2.624585]  acpi_pci_root_create+0x98/0x214
>>  [2.628843]  pci_acpi_scan_root+0x124/0x20c
>>  [2.633013]  acpi_pci_root_add+0x224/0x494
>>  [2.637096]  acpi_bus_attach+0xf8/0x200
>>  [2.640918]  acpi_bus_attach+0x98/0x200
>>  [2.644740]  acpi_bus_attach+0x98/0x200
>>  [2.648562]  acpi_bus_scan+0x48/0x9c
>>  [2.652125]  acpi_scan_init+0x104/0x268
>>  [2.655948]  acpi_init+0x308/0x374
>>  [2.659337]  do_one_initcall+0x48/0x14c
>>  [2.663160]  kernel_init_freeable+0x19c/0x250
>>  [2.667504]  kernel_init+0x10/0x100
>>  [2.670979]  ret_from_fork+0x10/0x18
>>
>> The cause is the size of PCI IO resource is 32KB, which is 4K aligned but
>> not 64KB aligned, however, ioremap_page_range() request the range as page
>> aligned or it will trigger a BUG_ON() on ioremap_pte_range() it calls, as
>> ioremap_pte_range increase the addr by PAGE_SIZE, which makes addr != end
>> until trigger BUG_ON, if its incoming end is not page aligned. More detail
>> trace is as following:
>>
>>  ioremap_page_range
>>  -> ioremap_p4d_range
>> -> ioremap_p4d_range
>>    -> ioremap_pud_range
>>   -> ioremap_pmd_range
>>  -> ioremap_pte_range
>>
>> This patch avoid panic by return -EINVAL if vaddr or resource size is not
>> page aligned.
>>
>> Reported-by: Zhou Wang 
>> Tested-by: Xiaojun Tan 
>> Signed-off-by: Yisheng Xie 
>> ---
>> v3:
>>  - pci_remap_iospace() sanitize its arguments instead - per Rafael
>>
>> v2:
>>  - Let the caller of ioremap_page_range() align the request by PAGE_SIZE - 
>> per Toshi
>>
>>  drivers/pci/pci.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>> index dbfe7c4..0eb0381 100644
>> --- a/drivers/pci/pci.c
>> +++ b/drivers/pci/pci.c
>> @@ -3544,6 +3544,9 @@ int pci_remap_iospace(const struct resource *res, 
>> phys_addr_t phys_addr)
>>  if (res->end > IO_SPACE_LIMIT)
>>  return -EINVAL;
>>  
>> +if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res)))
>> +return -EINVAL;
> 
> Most other callers of ioremap_page_range() are in the ioremap() path,
> and they align phys_addr themselves.  In some cases that results in a
> mapping that covers more than necessary.  For instance, see the
> function comment at the x86 version of __ioremap_caller().
> 
> Is there any reason we couldn't similarly align vaddr and phys_addr
> here?
> 
> The acpi_pci_probe_root_resources() path you mention above basically
> ignores the errors you're returning.  Your patches will avoid the
> panic, which is an improvement, but I/O port space will not work, and
> I don't see anything that gives the user a hint about why not.
> 
> If we could align vaddr and phys_addr (and possibly map more than
> necessary), I/O port space would still work.

Right, I will send another version, soon.

Thanks
Yisheng
> 
>>  return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
>>pgprot_device(PAGE_KERNEL));
>>  #else
>> -- 
>> 1.7.12.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
>> the body of a message to majord...@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> .
> 



Re: [PATCH v2 21/21] sparc64: use match_string() helper

2018-06-05 Thread Yisheng Xie
Hi Andy,

On 2018/6/4 18:06, Andy Shevchenko wrote:
> On Mon, Jun 4, 2018 at 4:06 AM, Yisheng Xie  wrote:
>> Hi Andy,
>>
>> On 2018/6/1 19:34, Andy Shevchenko wrote:
>>> On Thu, May 31, 2018 at 2:11 PM, Yisheng Xie  wrote:
>>>> match_string() returns the index of an array for a matching string,
>>>> which can be used instead of open coded variant.
>>>
>>>> @@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
>>>> break;
>>>> }
>>>> }
>>>
>>> It seems previous loop also can be replaced.
>>
>> No, because the there is an NULL in the middle of the array hwcaps:
>>  static const char *hwcaps[] = {
>>   "flush", "stbar", "swap", "muldiv", "v9",
>>   "ultra3", "blkinit", "n2",
>>
>>   /* These strings are as they appear in the machine description
>>* 'hwcap-list' property for cpu nodes.
>>*/
>>   "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
>>   "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
>>   "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
>>   "adp",
>>   };
> 
> Actually you can.
> What you need is to add string literal instead of NULL and make an
> additional condition after match_string() in all users (not to many),
> something like
> 
> i = match_string();
> if (i < 0)
>  ...
> if (BIT(i) == HWCAP_SPARC_CRYPTO) // or !=

OK, I get your point.

Thanks
Yisheng
>  ...
> 



Re: [PATCH v2 21/21] sparc64: use match_string() helper

2018-06-05 Thread Yisheng Xie
Hi Andy,

On 2018/6/4 18:06, Andy Shevchenko wrote:
> On Mon, Jun 4, 2018 at 4:06 AM, Yisheng Xie  wrote:
>> Hi Andy,
>>
>> On 2018/6/1 19:34, Andy Shevchenko wrote:
>>> On Thu, May 31, 2018 at 2:11 PM, Yisheng Xie  wrote:
>>>> match_string() returns the index of an array for a matching string,
>>>> which can be used instead of open coded variant.
>>>
>>>> @@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
>>>> break;
>>>> }
>>>> }
>>>
>>> It seems previous loop also can be replaced.
>>
>> No, because the there is an NULL in the middle of the array hwcaps:
>>  static const char *hwcaps[] = {
>>   "flush", "stbar", "swap", "muldiv", "v9",
>>   "ultra3", "blkinit", "n2",
>>
>>   /* These strings are as they appear in the machine description
>>* 'hwcap-list' property for cpu nodes.
>>*/
>>   "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
>>   "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
>>   "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
>>   "adp",
>>   };
> 
> Actually you can.
> What you need is to add string literal instead of NULL and make an
> additional condition after match_string() in all users (not to many),
> something like
> 
> i = match_string();
> if (i < 0)
>  ...
> if (BIT(i) == HWCAP_SPARC_CRYPTO) // or !=

OK, I get your point.

Thanks
Yisheng
>  ...
> 



Re: [PATCH v2 02/21] mfd: omap-usb-host: use match_string() helper

2018-06-04 Thread Yisheng Xie
Hi Lee,

On 2018/6/4 15:44, Lee Jones wrote:
> On Thu, 31 May 2018, Yisheng Xie wrote:
> 
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
>> Acked-by: Tony Lindgren 
>> Reviewed-by: Andy Shevchenko 
>> Cc: Tony Lindgren 
>> Cc: Lee Jones 
>> Cc: linux-o...@vger.kernel.org
>> Signed-off-by: Yisheng Xie 
>> ---
>> v2:
>>  - add Acked-by and Reviewed-by tag.
>>
>>  drivers/mfd/omap-usb-host.c | 24 ++--
>>  1 file changed, 2 insertions(+), 22 deletions(-)
> 
> I already applied this with the tags

Thanks
Yisheng
> 



Re: [PATCH v2 02/21] mfd: omap-usb-host: use match_string() helper

2018-06-04 Thread Yisheng Xie
Hi Lee,

On 2018/6/4 15:44, Lee Jones wrote:
> On Thu, 31 May 2018, Yisheng Xie wrote:
> 
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
>> Acked-by: Tony Lindgren 
>> Reviewed-by: Andy Shevchenko 
>> Cc: Tony Lindgren 
>> Cc: Lee Jones 
>> Cc: linux-o...@vger.kernel.org
>> Signed-off-by: Yisheng Xie 
>> ---
>> v2:
>>  - add Acked-by and Reviewed-by tag.
>>
>>  drivers/mfd/omap-usb-host.c | 24 ++--
>>  1 file changed, 2 insertions(+), 22 deletions(-)
> 
> I already applied this with the tags

Thanks
Yisheng
> 



Re: [PATCH v2 21/21] sparc64: use match_string() helper

2018-06-03 Thread Yisheng Xie
Hi Andy,

On 2018/6/1 19:34, Andy Shevchenko wrote:
> On Thu, May 31, 2018 at 2:11 PM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
> 
>> @@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
>> break;
>> }
>> }
> 
> It seems previous loop also can be replaced.

No, because the there is an NULL in the middle of the array hwcaps:
 static const char *hwcaps[] = {
  "flush", "stbar", "swap", "muldiv", "v9",
  "ultra3", "blkinit", "n2",

  /* These strings are as they appear in the machine description
   * 'hwcap-list' property for cpu nodes.
   */
  "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
  "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
  "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
  "adp",
  };

Thanks
Yisheng
> 
>> -   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
>> -   if (!strcmp(prop, crypto_hwcaps[i]))
>> -   caps |= HWCAP_SPARC_CRYPTO;
>> -   }
>> +   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
>> prop);
>> +   if (i >= 0)
>> +   caps |= HWCAP_SPARC_CRYPTO;
>>
>> plen = strlen(prop) + 1;
>> prop += plen;
>> --
>> 1.7.12.4
>>
> 
> 
> 



Re: [PATCH v2 21/21] sparc64: use match_string() helper

2018-06-03 Thread Yisheng Xie
Hi Andy,

On 2018/6/1 19:34, Andy Shevchenko wrote:
> On Thu, May 31, 2018 at 2:11 PM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
> 
>> @@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
>> break;
>> }
>> }
> 
> It seems previous loop also can be replaced.

No, because the there is an NULL in the middle of the array hwcaps:
 static const char *hwcaps[] = {
  "flush", "stbar", "swap", "muldiv", "v9",
  "ultra3", "blkinit", "n2",

  /* These strings are as they appear in the machine description
   * 'hwcap-list' property for cpu nodes.
   */
  "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
  "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
  "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
  "adp",
  };

Thanks
Yisheng
> 
>> -   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
>> -   if (!strcmp(prop, crypto_hwcaps[i]))
>> -   caps |= HWCAP_SPARC_CRYPTO;
>> -   }
>> +   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
>> prop);
>> +   if (i >= 0)
>> +   caps |= HWCAP_SPARC_CRYPTO;
>>
>> plen = strlen(prop) + 1;
>> prop += plen;
>> --
>> 1.7.12.4
>>
> 
> 
> 



Re: [PATCH v2 19/21] bcache: use match_string() helper

2018-05-31 Thread Yisheng Xie
Hi Coly,

On 2018/6/1 11:45, Coly Li wrote:
> On 2018/5/31 7:11 PM, Yisheng Xie wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
>> Cc: Kent Overstreet 
>> Cc: linux-bca...@vger.kernel.org 
>> Signed-off-by: Yisheng Xie 
> 
> Hi Yishenng,
> 
> Andy Shevchenko  submitted a patch to
> replace the whole bch_read_string_list() with __sysfs_match_string().
> And this patch is applied in Jens' block tree, will go into mainline
> kernel in v4.18.
> 
> If you search bcache mailing list, you may find a patch named with
> "bcache: Replace bch_read_string_list() by __sysfs_match_string()".
> 
> That means this patch will conflict with existing changes.

Get it, and thanks for this information.

Sorry Andy, for doing this once more.

Thanks
Yisheng
> 
> Thanks.
> 
> Coly Li
> 
>> ---
>>  drivers/md/bcache/util.c | 9 ++---
>>  1 file changed, 2 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
>> index 74febd5..cd1f4fd 100644
>> --- a/drivers/md/bcache/util.c
>> +++ b/drivers/md/bcache/util.c
>> @@ -136,22 +136,17 @@ ssize_t bch_snprint_string_list(char *buf, size_t 
>> size, const char * const list[
>>  
>>  ssize_t bch_read_string_list(const char *buf, const char * const list[])
>>  {
>> -size_t i;
>> +ssize_t i;
>>  char *s, *d = kstrndup(buf, PAGE_SIZE - 1, GFP_KERNEL);
>>  if (!d)
>>  return -ENOMEM;
>>  
>>  s = strim(d);
>>  
>> -for (i = 0; list[i]; i++)
>> -if (!strcmp(list[i], s))
>> -break;
>> +i = match_string(list, -1, s);
>>  
>>  kfree(d);
>>  
>> -if (!list[i])
>> -return -EINVAL;
>> -
>>  return i;
>>  }
>>  
>>
> 
> 
> 



Re: [PATCH v2 19/21] bcache: use match_string() helper

2018-05-31 Thread Yisheng Xie
Hi Coly,

On 2018/6/1 11:45, Coly Li wrote:
> On 2018/5/31 7:11 PM, Yisheng Xie wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
>> Cc: Kent Overstreet 
>> Cc: linux-bca...@vger.kernel.org 
>> Signed-off-by: Yisheng Xie 
> 
> Hi Yishenng,
> 
> Andy Shevchenko  submitted a patch to
> replace the whole bch_read_string_list() with __sysfs_match_string().
> And this patch is applied in Jens' block tree, will go into mainline
> kernel in v4.18.
> 
> If you search bcache mailing list, you may find a patch named with
> "bcache: Replace bch_read_string_list() by __sysfs_match_string()".
> 
> That means this patch will conflict with existing changes.

Get it, and thanks for this information.

Sorry Andy, for doing this once more.

Thanks
Yisheng
> 
> Thanks.
> 
> Coly Li
> 
>> ---
>>  drivers/md/bcache/util.c | 9 ++---
>>  1 file changed, 2 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
>> index 74febd5..cd1f4fd 100644
>> --- a/drivers/md/bcache/util.c
>> +++ b/drivers/md/bcache/util.c
>> @@ -136,22 +136,17 @@ ssize_t bch_snprint_string_list(char *buf, size_t 
>> size, const char * const list[
>>  
>>  ssize_t bch_read_string_list(const char *buf, const char * const list[])
>>  {
>> -size_t i;
>> +ssize_t i;
>>  char *s, *d = kstrndup(buf, PAGE_SIZE - 1, GFP_KERNEL);
>>  if (!d)
>>  return -ENOMEM;
>>  
>>  s = strim(d);
>>  
>> -for (i = 0; list[i]; i++)
>> -if (!strcmp(list[i], s))
>> -break;
>> +i = match_string(list, -1, s);
>>  
>>  kfree(d);
>>  
>> -if (!list[i])
>> -return -EINVAL;
>> -
>>  return i;
>>  }
>>  
>>
> 
> 
> 



Re: [PATCH v2 16/21] ASoC: max98088: use match_string() helper

2018-05-31 Thread Yisheng Xie
Hi Mark,

On 2018/6/1 0:02, Mark Brown wrote:
> On Thu, May 31, 2018 at 08:25:39PM +0800, Yisheng Xie wrote:
> 
>> Anyway, Here is the cover letter of v1 and I have add v2's cover letter to 
>> you:
>>   https://lkml.org/lkml/2018/5/21/303
> 
>> Each patch in this patchset is a separate one, for what this patchset want 
>> to do
>> is use match_string() helper for echo subsystem.
> 
> For something like this it's generally easier to not send everything as
> one big series - it avoids any confusion about dependencies and there's
> no actual relationship between the patches.  Instead just sending each
> subsystem as a series or perhaps even just a bunch of separate patches
> should make things smoother.

Thanks, will take this suggestion maybe next time.

Thanks
Yisheng
> 



Re: [PATCH v2 16/21] ASoC: max98088: use match_string() helper

2018-05-31 Thread Yisheng Xie
Hi Mark,

On 2018/6/1 0:02, Mark Brown wrote:
> On Thu, May 31, 2018 at 08:25:39PM +0800, Yisheng Xie wrote:
> 
>> Anyway, Here is the cover letter of v1 and I have add v2's cover letter to 
>> you:
>>   https://lkml.org/lkml/2018/5/21/303
> 
>> Each patch in this patchset is a separate one, for what this patchset want 
>> to do
>> is use match_string() helper for echo subsystem.
> 
> For something like this it's generally easier to not send everything as
> one big series - it avoids any confusion about dependencies and there's
> no actual relationship between the patches.  Instead just sending each
> subsystem as a series or perhaps even just a bunch of separate patches
> should make things smoother.

Thanks, will take this suggestion maybe next time.

Thanks
Yisheng
> 



Re: [PATCH v2 16/21] ASoC: max98088: use match_string() helper

2018-05-31 Thread Yisheng Xie
Hi Mark,

On 2018/5/31 19:49, Mark Brown wrote:
> On Thu, May 31, 2018 at 07:11:21PM +0800, Yisheng Xie wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
> 
> I don't have either the cover letter or the rest of the series here so
> I've no context - what is the story here with regard to dependencies and
> things?
Sorry about that I should have sent cover letter to you, but for too many 
maintainer
to sent, I ignore this to avoid make too much noisy.

Anyway, Here is the cover letter of v1 and I have add v2's cover letter to you:
  https://lkml.org/lkml/2018/5/21/303

Each patch in this patchset is a separate one, for what this patchset want to do
is use match_string() helper for echo subsystem.

Thanks
Yisheng
> 



Re: [PATCH v2 16/21] ASoC: max98088: use match_string() helper

2018-05-31 Thread Yisheng Xie
Hi Mark,

On 2018/5/31 19:49, Mark Brown wrote:
> On Thu, May 31, 2018 at 07:11:21PM +0800, Yisheng Xie wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
> 
> I don't have either the cover letter or the rest of the series here so
> I've no context - what is the story here with regard to dependencies and
> things?
Sorry about that I should have sent cover letter to you, but for too many 
maintainer
to sent, I ignore this to avoid make too much noisy.

Anyway, Here is the cover letter of v1 and I have add v2's cover letter to you:
  https://lkml.org/lkml/2018/5/21/303

Each patch in this patchset is a separate one, for what this patchset want to do
is use match_string() helper for echo subsystem.

Thanks
Yisheng
> 



Re: [PATCH v2 00/21] use match_string() helper

2018-05-31 Thread Yisheng Xie
+ Mark

On 2018/5/31 19:11, Yisheng Xie wrote:
> Andy introduce helper function match_string() which can be used to return
> the index of array for a matching string. so we can use it in many places
> instead of open coded variant.
> 
> I just try to make this API be used more commonly, sorry if this makes
> too much big patchset.
> 
> v2:
>  - Remove the Patches which Andy already sent out, or maintainer already
>picked up.
>  - Add Reviewed-by or Acked-by tags for some patchs.
>  - Add some new patches[19-21].
> 
> Yisheng Xie (21):
>   usb: phy: use match_string() helper
>   mfd: omap-usb-host: use match_string() helper
>   Staging: gdm724x: use match_string() helper
>   cxgb4: use match_string() helper
>   hp100: use match_string() helper
>   iwlwifi: mvm: use match_string() helper
>   bus: fsl-mc: use match_string() helper
>   clk: bcm2835: use match_string() helper
>   clk: use match_string() helper
>   cpufreq: intel_pstate: use match_string() helper
>   drm/nouveau: use match_string() helper
>   drm: i2c: ch7006: use match_string() helper
>   ima: use match_string() helper
>   sched/debug: use match_string() helper
>   ALSA: oxygen: use match_string() helper
>   ASoC: max98088: use match_string() helper
>   ASoC: max98095: use match_string() helper
>   ASoC: dapm: use match_string() helper
>   bcache: use match_string() helper
>   powerpc/xmon: use match_string() helper
>   sparc64: use match_string() helper
> 
>  arch/powerpc/xmon/xmon.c | 23 +-
>  arch/sparc/kernel/setup_64.c |  7 +++---
>  drivers/bus/fsl-mc/fsl-mc-allocator.c| 24 --
>  drivers/clk/bcm/clk-bcm2835.c| 13 +-
>  drivers/clk/clk.c|  8 ++
>  drivers/cpufreq/intel_pstate.c   | 15 +---
>  drivers/gpu/drm/i2c/ch7006_drv.c | 13 --
>  drivers/gpu/drm/nouveau/dispnv04/tvnv17.c| 13 --
>  drivers/md/bcache/util.c |  9 ++-
>  drivers/mfd/omap-usb-host.c  | 24 ++
>  drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c   | 14 +++
>  drivers/net/ethernet/hp/hp100.c  |  9 +--
>  drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 +++---
>  drivers/staging/gdm724x/gdm_tty.c| 18 --
>  drivers/usb/phy/of.c | 10 
>  kernel/sched/debug.c | 31 
> 
>  security/integrity/ima/ima_main.c| 11 +++--
>  sound/pci/oxygen/oxygen_mixer.c  | 14 +--
>  sound/soc/codecs/max98088.c  | 13 --
>  sound/soc/codecs/max98095.c  | 13 --
>  sound/soc/soc-dapm.c | 18 ++
>  21 files changed, 109 insertions(+), 204 deletions(-)
> 



Re: [PATCH v2 00/21] use match_string() helper

2018-05-31 Thread Yisheng Xie
+ Mark

On 2018/5/31 19:11, Yisheng Xie wrote:
> Andy introduce helper function match_string() which can be used to return
> the index of array for a matching string. so we can use it in many places
> instead of open coded variant.
> 
> I just try to make this API be used more commonly, sorry if this makes
> too much big patchset.
> 
> v2:
>  - Remove the Patches which Andy already sent out, or maintainer already
>picked up.
>  - Add Reviewed-by or Acked-by tags for some patchs.
>  - Add some new patches[19-21].
> 
> Yisheng Xie (21):
>   usb: phy: use match_string() helper
>   mfd: omap-usb-host: use match_string() helper
>   Staging: gdm724x: use match_string() helper
>   cxgb4: use match_string() helper
>   hp100: use match_string() helper
>   iwlwifi: mvm: use match_string() helper
>   bus: fsl-mc: use match_string() helper
>   clk: bcm2835: use match_string() helper
>   clk: use match_string() helper
>   cpufreq: intel_pstate: use match_string() helper
>   drm/nouveau: use match_string() helper
>   drm: i2c: ch7006: use match_string() helper
>   ima: use match_string() helper
>   sched/debug: use match_string() helper
>   ALSA: oxygen: use match_string() helper
>   ASoC: max98088: use match_string() helper
>   ASoC: max98095: use match_string() helper
>   ASoC: dapm: use match_string() helper
>   bcache: use match_string() helper
>   powerpc/xmon: use match_string() helper
>   sparc64: use match_string() helper
> 
>  arch/powerpc/xmon/xmon.c | 23 +-
>  arch/sparc/kernel/setup_64.c |  7 +++---
>  drivers/bus/fsl-mc/fsl-mc-allocator.c| 24 --
>  drivers/clk/bcm/clk-bcm2835.c| 13 +-
>  drivers/clk/clk.c|  8 ++
>  drivers/cpufreq/intel_pstate.c   | 15 +---
>  drivers/gpu/drm/i2c/ch7006_drv.c | 13 --
>  drivers/gpu/drm/nouveau/dispnv04/tvnv17.c| 13 --
>  drivers/md/bcache/util.c |  9 ++-
>  drivers/mfd/omap-usb-host.c  | 24 ++
>  drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c   | 14 +++
>  drivers/net/ethernet/hp/hp100.c  |  9 +--
>  drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 +++---
>  drivers/staging/gdm724x/gdm_tty.c| 18 --
>  drivers/usb/phy/of.c | 10 
>  kernel/sched/debug.c | 31 
> 
>  security/integrity/ima/ima_main.c| 11 +++--
>  sound/pci/oxygen/oxygen_mixer.c  | 14 +--
>  sound/soc/codecs/max98088.c  | 13 --
>  sound/soc/codecs/max98095.c  | 13 --
>  sound/soc/soc-dapm.c | 18 ++
>  21 files changed, 109 insertions(+), 204 deletions(-)
> 



Re: [PATCH v2 03/21] Staging: gdm724x: use match_string() helper

2018-05-31 Thread Yisheng Xie
Hi Greg,

On 2018/5/31 19:44, Greg Kroah-Hartman wrote:
> On Thu, May 31, 2018 at 07:11:08PM +0800, Yisheng Xie wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
>> Cc: Greg Kroah-Hartman 
>> Cc: Quytelda Kahja 
>> Cc: de...@driverdev.osuosl.org
>> Signed-off-by: Yisheng Xie 
>> ---
>> v2:
>>  - const DRIVER_STRING instead  - per Andy
>>
>>  drivers/staging/gdm724x/gdm_tty.c | 18 +-
>>  1 file changed, 5 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/staging/gdm724x/gdm_tty.c 
>> b/drivers/staging/gdm724x/gdm_tty.c
>> index 3cdebb8..397ecaa 100644
>> --- a/drivers/staging/gdm724x/gdm_tty.c
>> +++ b/drivers/staging/gdm724x/gdm_tty.c
>> @@ -43,7 +43,7 @@
>>  static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
>>  static DEFINE_MUTEX(gdm_table_lock);
>>  
>> -static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
>> +static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
>>  static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
>>  
>>  static void gdm_port_destruct(struct tty_port *port)
>> @@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, 
>> struct tty_struct *tty)
>>  {
>>  struct gdm *gdm = NULL;
>>  int ret;
>> -int i;
>> -int j;
>> -
>> -j = GDM_TTY_MINOR;
>> -for (i = 0; i < TTY_MAX_COUNT; i++) {
>> -if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
>> -j = tty->index;
>> -break;
>> -}
>> -}
>>  
>> -if (j == GDM_TTY_MINOR)
>> +ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
>> +   tty->driver->driver_name);
>> +if (ret < 0 || tty->index == GDM_TTY_MINOR)
>>  return -ENODEV;
> 
> Very odd rewrite here.  Why call this function if you think the initial
> parameters are not correct?  Are you sure about your test for
> tty->index?

Hmm, actually, I thought it no need to test tty->index here, but I not so sure
about that so I kept it, I will remove this check next version.

> 
> This should be cleaned up more please.
Sure!


Thanks
Yisheng
> 
> thanks,
> 
> greg k-h
> 
> .
> 



Re: [PATCH v2 03/21] Staging: gdm724x: use match_string() helper

2018-05-31 Thread Yisheng Xie
Hi Greg,

On 2018/5/31 19:44, Greg Kroah-Hartman wrote:
> On Thu, May 31, 2018 at 07:11:08PM +0800, Yisheng Xie wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
>> Cc: Greg Kroah-Hartman 
>> Cc: Quytelda Kahja 
>> Cc: de...@driverdev.osuosl.org
>> Signed-off-by: Yisheng Xie 
>> ---
>> v2:
>>  - const DRIVER_STRING instead  - per Andy
>>
>>  drivers/staging/gdm724x/gdm_tty.c | 18 +-
>>  1 file changed, 5 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/staging/gdm724x/gdm_tty.c 
>> b/drivers/staging/gdm724x/gdm_tty.c
>> index 3cdebb8..397ecaa 100644
>> --- a/drivers/staging/gdm724x/gdm_tty.c
>> +++ b/drivers/staging/gdm724x/gdm_tty.c
>> @@ -43,7 +43,7 @@
>>  static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
>>  static DEFINE_MUTEX(gdm_table_lock);
>>  
>> -static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
>> +static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
>>  static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
>>  
>>  static void gdm_port_destruct(struct tty_port *port)
>> @@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, 
>> struct tty_struct *tty)
>>  {
>>  struct gdm *gdm = NULL;
>>  int ret;
>> -int i;
>> -int j;
>> -
>> -j = GDM_TTY_MINOR;
>> -for (i = 0; i < TTY_MAX_COUNT; i++) {
>> -if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
>> -j = tty->index;
>> -break;
>> -}
>> -}
>>  
>> -if (j == GDM_TTY_MINOR)
>> +ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
>> +   tty->driver->driver_name);
>> +if (ret < 0 || tty->index == GDM_TTY_MINOR)
>>  return -ENODEV;
> 
> Very odd rewrite here.  Why call this function if you think the initial
> parameters are not correct?  Are you sure about your test for
> tty->index?

Hmm, actually, I thought it no need to test tty->index here, but I not so sure
about that so I kept it, I will remove this check next version.

> 
> This should be cleaned up more please.
Sure!


Thanks
Yisheng
> 
> thanks,
> 
> greg k-h
> 
> .
> 



[PATCH v2 03/21] Staging: gdm724x: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Greg Kroah-Hartman 
Cc: Quytelda Kahja 
Cc: de...@driverdev.osuosl.org
Signed-off-by: Yisheng Xie 
---
v2:
 - const DRIVER_STRING instead  - per Andy

 drivers/staging/gdm724x/gdm_tty.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_tty.c 
b/drivers/staging/gdm724x/gdm_tty.c
index 3cdebb8..397ecaa 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -43,7 +43,7 @@
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
 static DEFINE_MUTEX(gdm_table_lock);
 
-static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
 static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
 
 static void gdm_port_destruct(struct tty_port *port)
@@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, 
struct tty_struct *tty)
 {
struct gdm *gdm = NULL;
int ret;
-   int i;
-   int j;
-
-   j = GDM_TTY_MINOR;
-   for (i = 0; i < TTY_MAX_COUNT; i++) {
-   if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
-   j = tty->index;
-   break;
-   }
-   }
 
-   if (j == GDM_TTY_MINOR)
+   ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
+  tty->driver->driver_name);
+   if (ret < 0 || tty->index == GDM_TTY_MINOR)
return -ENODEV;
 
mutex_lock(_table_lock);
-   gdm = gdm_table[i][j];
+   gdm = gdm_table[ret][tty->index];
if (!gdm) {
mutex_unlock(_table_lock);
return -ENODEV;
-- 
1.7.12.4



[PATCH v2 03/21] Staging: gdm724x: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Greg Kroah-Hartman 
Cc: Quytelda Kahja 
Cc: de...@driverdev.osuosl.org
Signed-off-by: Yisheng Xie 
---
v2:
 - const DRIVER_STRING instead  - per Andy

 drivers/staging/gdm724x/gdm_tty.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_tty.c 
b/drivers/staging/gdm724x/gdm_tty.c
index 3cdebb8..397ecaa 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -43,7 +43,7 @@
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
 static DEFINE_MUTEX(gdm_table_lock);
 
-static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
 static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
 
 static void gdm_port_destruct(struct tty_port *port)
@@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, 
struct tty_struct *tty)
 {
struct gdm *gdm = NULL;
int ret;
-   int i;
-   int j;
-
-   j = GDM_TTY_MINOR;
-   for (i = 0; i < TTY_MAX_COUNT; i++) {
-   if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
-   j = tty->index;
-   break;
-   }
-   }
 
-   if (j == GDM_TTY_MINOR)
+   ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
+  tty->driver->driver_name);
+   if (ret < 0 || tty->index == GDM_TTY_MINOR)
return -ENODEV;
 
mutex_lock(_table_lock);
-   gdm = gdm_table[i][j];
+   gdm = gdm_table[ret][tty->index];
if (!gdm) {
mutex_unlock(_table_lock);
return -ENODEV;
-- 
1.7.12.4



[PATCH v2 02/21] mfd: omap-usb-host: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Acked-by: Tony Lindgren 
Reviewed-by: Andy Shevchenko 
Cc: Tony Lindgren 
Cc: Lee Jones 
Cc: linux-o...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - add Acked-by and Reviewed-by tag.

 drivers/mfd/omap-usb-host.c | 24 ++--
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
index 7aab376..e11ab12 100644
--- a/drivers/mfd/omap-usb-host.c
+++ b/drivers/mfd/omap-usb-host.c
@@ -153,27 +153,6 @@ static inline u32 usbhs_read(void __iomem *base, u32 reg)
[OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM] = "ohci-tll-2pin-dpdm",
 };
 
-/**
- * omap_usbhs_get_dt_port_mode - Get the 'enum usbhs_omap_port_mode'
- * from the port mode string.
- * @mode: The port mode string, usually obtained from device tree.
- *
- * The function returns the 'enum usbhs_omap_port_mode' that matches the
- * provided port mode string as per the port_modes table.
- * If no match is found it returns -ENODEV
- */
-static int omap_usbhs_get_dt_port_mode(const char *mode)
-{
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(port_modes); i++) {
-   if (!strcmp(mode, port_modes[i]))
-   return i;
-   }
-
-   return -ENODEV;
-}
-
 static struct platform_device *omap_usbhs_alloc_child(const char *name,
struct resource *res, int num_resources, void *pdata,
size_t pdata_size, struct device *dev)
@@ -529,7 +508,8 @@ static int usbhs_omap_get_dt_pdata(struct device *dev,
if (ret < 0)
continue;
 
-   ret = omap_usbhs_get_dt_port_mode(mode);
+   /* get 'enum usbhs_omap_port_mode' from port mode string */
+   ret = match_string(port_modes, ARRAY_SIZE(port_modes), mode);
if (ret < 0) {
dev_warn(dev, "Invalid port%d-mode \"%s\" in device 
tree\n",
i, mode);
-- 
1.7.12.4



[PATCH v2 02/21] mfd: omap-usb-host: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Acked-by: Tony Lindgren 
Reviewed-by: Andy Shevchenko 
Cc: Tony Lindgren 
Cc: Lee Jones 
Cc: linux-o...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - add Acked-by and Reviewed-by tag.

 drivers/mfd/omap-usb-host.c | 24 ++--
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
index 7aab376..e11ab12 100644
--- a/drivers/mfd/omap-usb-host.c
+++ b/drivers/mfd/omap-usb-host.c
@@ -153,27 +153,6 @@ static inline u32 usbhs_read(void __iomem *base, u32 reg)
[OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM] = "ohci-tll-2pin-dpdm",
 };
 
-/**
- * omap_usbhs_get_dt_port_mode - Get the 'enum usbhs_omap_port_mode'
- * from the port mode string.
- * @mode: The port mode string, usually obtained from device tree.
- *
- * The function returns the 'enum usbhs_omap_port_mode' that matches the
- * provided port mode string as per the port_modes table.
- * If no match is found it returns -ENODEV
- */
-static int omap_usbhs_get_dt_port_mode(const char *mode)
-{
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(port_modes); i++) {
-   if (!strcmp(mode, port_modes[i]))
-   return i;
-   }
-
-   return -ENODEV;
-}
-
 static struct platform_device *omap_usbhs_alloc_child(const char *name,
struct resource *res, int num_resources, void *pdata,
size_t pdata_size, struct device *dev)
@@ -529,7 +508,8 @@ static int usbhs_omap_get_dt_pdata(struct device *dev,
if (ret < 0)
continue;
 
-   ret = omap_usbhs_get_dt_port_mode(mode);
+   /* get 'enum usbhs_omap_port_mode' from port mode string */
+   ret = match_string(port_modes, ARRAY_SIZE(port_modes), mode);
if (ret < 0) {
dev_warn(dev, "Invalid port%d-mode \"%s\" in device 
tree\n",
i, mode);
-- 
1.7.12.4



[PATCH v2 00/21] use match_string() helper

2018-05-31 Thread Yisheng Xie
Andy introduce helper function match_string() which can be used to return
the index of array for a matching string. so we can use it in many places
instead of open coded variant.

I just try to make this API be used more commonly, sorry if this makes
too much big patchset.

v2:
 - Remove the Patches which Andy already sent out, or maintainer already
   picked up.
 - Add Reviewed-by or Acked-by tags for some patchs.
 - Add some new patches[19-21].

Yisheng Xie (21):
  usb: phy: use match_string() helper
  mfd: omap-usb-host: use match_string() helper
  Staging: gdm724x: use match_string() helper
  cxgb4: use match_string() helper
  hp100: use match_string() helper
  iwlwifi: mvm: use match_string() helper
  bus: fsl-mc: use match_string() helper
  clk: bcm2835: use match_string() helper
  clk: use match_string() helper
  cpufreq: intel_pstate: use match_string() helper
  drm/nouveau: use match_string() helper
  drm: i2c: ch7006: use match_string() helper
  ima: use match_string() helper
  sched/debug: use match_string() helper
  ALSA: oxygen: use match_string() helper
  ASoC: max98088: use match_string() helper
  ASoC: max98095: use match_string() helper
  ASoC: dapm: use match_string() helper
  bcache: use match_string() helper
  powerpc/xmon: use match_string() helper
  sparc64: use match_string() helper

 arch/powerpc/xmon/xmon.c | 23 +-
 arch/sparc/kernel/setup_64.c |  7 +++---
 drivers/bus/fsl-mc/fsl-mc-allocator.c| 24 --
 drivers/clk/bcm/clk-bcm2835.c| 13 +-
 drivers/clk/clk.c|  8 ++
 drivers/cpufreq/intel_pstate.c   | 15 +---
 drivers/gpu/drm/i2c/ch7006_drv.c | 13 --
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c| 13 --
 drivers/md/bcache/util.c |  9 ++-
 drivers/mfd/omap-usb-host.c  | 24 ++
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c   | 14 +++
 drivers/net/ethernet/hp/hp100.c  |  9 +--
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 +++---
 drivers/staging/gdm724x/gdm_tty.c| 18 --
 drivers/usb/phy/of.c | 10 
 kernel/sched/debug.c | 31 
 security/integrity/ima/ima_main.c| 11 +++--
 sound/pci/oxygen/oxygen_mixer.c  | 14 +--
 sound/soc/codecs/max98088.c  | 13 --
 sound/soc/codecs/max98095.c  | 13 --
 sound/soc/soc-dapm.c | 18 ++
 21 files changed, 109 insertions(+), 204 deletions(-)

-- 
1.7.12.4



[PATCH v2 09/21] clk: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Michael Turquette 
Cc: Stephen Boyd 
Cc: linux-...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - leave second parameter on the first line  - per Andy

 drivers/clk/clk.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7af555f..d01bdda 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2171,7 +2171,6 @@ void clk_hw_reparent(struct clk_hw *hw, struct clk_hw 
*new_parent)
 bool clk_has_parent(struct clk *clk, struct clk *parent)
 {
struct clk_core *core, *parent_core;
-   unsigned int i;
 
/* NULL clocks should be nops, so return success if either is NULL. */
if (!clk || !parent)
@@ -2184,11 +2183,8 @@ bool clk_has_parent(struct clk *clk, struct clk *parent)
if (core->parent == parent_core)
return true;
 
-   for (i = 0; i < core->num_parents; i++)
-   if (strcmp(core->parent_names[i], parent_core->name) == 0)
-   return true;
-
-   return false;
+   return match_string(core->parent_names, core->num_parents,
+   parent_core->name) >= 0;
 }
 EXPORT_SYMBOL_GPL(clk_has_parent);
 
-- 
1.7.12.4



[PATCH v2 09/21] clk: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Michael Turquette 
Cc: Stephen Boyd 
Cc: linux-...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - leave second parameter on the first line  - per Andy

 drivers/clk/clk.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7af555f..d01bdda 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2171,7 +2171,6 @@ void clk_hw_reparent(struct clk_hw *hw, struct clk_hw 
*new_parent)
 bool clk_has_parent(struct clk *clk, struct clk *parent)
 {
struct clk_core *core, *parent_core;
-   unsigned int i;
 
/* NULL clocks should be nops, so return success if either is NULL. */
if (!clk || !parent)
@@ -2184,11 +2183,8 @@ bool clk_has_parent(struct clk *clk, struct clk *parent)
if (core->parent == parent_core)
return true;
 
-   for (i = 0; i < core->num_parents; i++)
-   if (strcmp(core->parent_names[i], parent_core->name) == 0)
-   return true;
-
-   return false;
+   return match_string(core->parent_names, core->num_parents,
+   parent_core->name) >= 0;
 }
 EXPORT_SYMBOL_GPL(clk_has_parent);
 
-- 
1.7.12.4



[PATCH v2 00/21] use match_string() helper

2018-05-31 Thread Yisheng Xie
Andy introduce helper function match_string() which can be used to return
the index of array for a matching string. so we can use it in many places
instead of open coded variant.

I just try to make this API be used more commonly, sorry if this makes
too much big patchset.

v2:
 - Remove the Patches which Andy already sent out, or maintainer already
   picked up.
 - Add Reviewed-by or Acked-by tags for some patchs.
 - Add some new patches[19-21].

Yisheng Xie (21):
  usb: phy: use match_string() helper
  mfd: omap-usb-host: use match_string() helper
  Staging: gdm724x: use match_string() helper
  cxgb4: use match_string() helper
  hp100: use match_string() helper
  iwlwifi: mvm: use match_string() helper
  bus: fsl-mc: use match_string() helper
  clk: bcm2835: use match_string() helper
  clk: use match_string() helper
  cpufreq: intel_pstate: use match_string() helper
  drm/nouveau: use match_string() helper
  drm: i2c: ch7006: use match_string() helper
  ima: use match_string() helper
  sched/debug: use match_string() helper
  ALSA: oxygen: use match_string() helper
  ASoC: max98088: use match_string() helper
  ASoC: max98095: use match_string() helper
  ASoC: dapm: use match_string() helper
  bcache: use match_string() helper
  powerpc/xmon: use match_string() helper
  sparc64: use match_string() helper

 arch/powerpc/xmon/xmon.c | 23 +-
 arch/sparc/kernel/setup_64.c |  7 +++---
 drivers/bus/fsl-mc/fsl-mc-allocator.c| 24 --
 drivers/clk/bcm/clk-bcm2835.c| 13 +-
 drivers/clk/clk.c|  8 ++
 drivers/cpufreq/intel_pstate.c   | 15 +---
 drivers/gpu/drm/i2c/ch7006_drv.c | 13 --
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c| 13 --
 drivers/md/bcache/util.c |  9 ++-
 drivers/mfd/omap-usb-host.c  | 24 ++
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c   | 14 +++
 drivers/net/ethernet/hp/hp100.c  |  9 +--
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 +++---
 drivers/staging/gdm724x/gdm_tty.c| 18 --
 drivers/usb/phy/of.c | 10 
 kernel/sched/debug.c | 31 
 security/integrity/ima/ima_main.c| 11 +++--
 sound/pci/oxygen/oxygen_mixer.c  | 14 +--
 sound/soc/codecs/max98088.c  | 13 --
 sound/soc/codecs/max98095.c  | 13 --
 sound/soc/soc-dapm.c | 18 ++
 21 files changed, 109 insertions(+), 204 deletions(-)

-- 
1.7.12.4



[PATCH v2 13/21] ima: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Mimi Zohar 
Reviewed-by: Andy Shevchenko 
Cc: Mimi Zohar 
Cc: Dmitry Kasatkin 
Cc: James Morris 
Cc: "Serge E. Hallyn" 
Cc: linux-integr...@vger.kernel.org
Cc: linux-security-mod...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - add Reviewed-by tag.

 security/integrity/ima/ima_main.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/security/integrity/ima/ima_main.c 
b/security/integrity/ima/ima_main.c
index 74d0bd7..f807093 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -61,14 +61,11 @@ static int __init hash_setup(char *str)
goto out;
}
 
-   for (i = 0; i < HASH_ALGO__LAST; i++) {
-   if (strcmp(str, hash_algo_name[i]) == 0) {
-   ima_hash_algo = i;
-   break;
-   }
-   }
-   if (i == HASH_ALGO__LAST)
+   i = match_string(hash_algo_name, HASH_ALGO__LAST, str);
+   if (i < 0)
return 1;
+
+   ima_hash_algo = i;
 out:
hash_setup_done = 1;
return 1;
-- 
1.7.12.4



[PATCH v2 13/21] ima: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Mimi Zohar 
Reviewed-by: Andy Shevchenko 
Cc: Mimi Zohar 
Cc: Dmitry Kasatkin 
Cc: James Morris 
Cc: "Serge E. Hallyn" 
Cc: linux-integr...@vger.kernel.org
Cc: linux-security-mod...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - add Reviewed-by tag.

 security/integrity/ima/ima_main.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/security/integrity/ima/ima_main.c 
b/security/integrity/ima/ima_main.c
index 74d0bd7..f807093 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -61,14 +61,11 @@ static int __init hash_setup(char *str)
goto out;
}
 
-   for (i = 0; i < HASH_ALGO__LAST; i++) {
-   if (strcmp(str, hash_algo_name[i]) == 0) {
-   ima_hash_algo = i;
-   break;
-   }
-   }
-   if (i == HASH_ALGO__LAST)
+   i = match_string(hash_algo_name, HASH_ALGO__LAST, str);
+   if (i < 0)
return 1;
+
+   ima_hash_algo = i;
 out:
hash_setup_done = 1;
return 1;
-- 
1.7.12.4



[PATCH v2 08/21] clk: bcm2835: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Eric Anholt 
Cc: Michael Turquette 
Cc: Stephen Boyd 
Cc: Eric Anholt 
Cc: Stefan Wahren 
Cc: linux-...@vger.kernel.org
Cc: linux-rpi-ker...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Signed-off-by: Yisheng Xie 
---
v2:
 - donot change the type of i  - per Andy

 drivers/clk/bcm/clk-bcm2835.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index fa0d5c8..5e18433 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -1395,7 +1395,7 @@ static struct clk_hw *bcm2835_register_clock(struct 
bcm2835_cprman *cprman,
struct bcm2835_clock *clock;
struct clk_init_data init;
const char *parents[1 << CM_SRC_BITS];
-   size_t i, j;
+   size_t i;
int ret;
 
/*
@@ -1405,12 +1405,11 @@ static struct clk_hw *bcm2835_register_clock(struct 
bcm2835_cprman *cprman,
for (i = 0; i < data->num_mux_parents; i++) {
parents[i] = data->parents[i];
 
-   for (j = 0; j < ARRAY_SIZE(cprman_parent_names); j++) {
-   if (strcmp(parents[i], cprman_parent_names[j]) == 0) {
-   parents[i] = cprman->real_parent_names[j];
-   break;
-   }
-   }
+   ret = match_string(cprman_parent_names,
+  ARRAY_SIZE(cprman_parent_names),
+  parents[i]);
+   if (ret >= 0)
+   parents[i] = cprman->real_parent_names[ret];
}
 
memset(, 0, sizeof(init));
-- 
1.7.12.4



[PATCH v2 08/21] clk: bcm2835: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Eric Anholt 
Cc: Michael Turquette 
Cc: Stephen Boyd 
Cc: Eric Anholt 
Cc: Stefan Wahren 
Cc: linux-...@vger.kernel.org
Cc: linux-rpi-ker...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Signed-off-by: Yisheng Xie 
---
v2:
 - donot change the type of i  - per Andy

 drivers/clk/bcm/clk-bcm2835.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index fa0d5c8..5e18433 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -1395,7 +1395,7 @@ static struct clk_hw *bcm2835_register_clock(struct 
bcm2835_cprman *cprman,
struct bcm2835_clock *clock;
struct clk_init_data init;
const char *parents[1 << CM_SRC_BITS];
-   size_t i, j;
+   size_t i;
int ret;
 
/*
@@ -1405,12 +1405,11 @@ static struct clk_hw *bcm2835_register_clock(struct 
bcm2835_cprman *cprman,
for (i = 0; i < data->num_mux_parents; i++) {
parents[i] = data->parents[i];
 
-   for (j = 0; j < ARRAY_SIZE(cprman_parent_names); j++) {
-   if (strcmp(parents[i], cprman_parent_names[j]) == 0) {
-   parents[i] = cprman->real_parent_names[j];
-   break;
-   }
-   }
+   ret = match_string(cprman_parent_names,
+  ARRAY_SIZE(cprman_parent_names),
+  parents[i]);
+   if (ret >= 0)
+   parents[i] = cprman->real_parent_names[ret];
}
 
memset(, 0, sizeof(init));
-- 
1.7.12.4



[PATCH v2 10/21] cpufreq: intel_pstate: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Andy Shevchenko 
Cc: Srinivas Pandruvada 
Cc: Len Brown 
Cc: "Rafael J. Wysocki" 
Cc: Viresh Kumar 
Cc: linux...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - add Reviewed-by tag.

 drivers/cpufreq/intel_pstate.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 17e566af..d701e26 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -645,21 +645,18 @@ static ssize_t store_energy_performance_preference(
 {
struct cpudata *cpu_data = all_cpu_data[policy->cpu];
char str_preference[21];
-   int ret, i = 0;
+   int ret;
 
ret = sscanf(buf, "%20s", str_preference);
if (ret != 1)
return -EINVAL;
 
-   while (energy_perf_strings[i] != NULL) {
-   if (!strcmp(str_preference, energy_perf_strings[i])) {
-   intel_pstate_set_energy_pref_index(cpu_data, i);
-   return count;
-   }
-   ++i;
-   }
+   ret = match_string(energy_perf_strings, -1, str_preference);
+   if (ret < 0)
+   return ret;
 
-   return -EINVAL;
+   intel_pstate_set_energy_pref_index(cpu_data, ret);
+   return count;
 }
 
 static ssize_t show_energy_performance_preference(
-- 
1.7.12.4



[PATCH v2 04/21] cxgb4: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Ganesh Goudar 
Cc: net...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - no change from v1.

 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c 
b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
index 9da6f57..bd61610 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
@@ -782,17 +782,11 @@ static int cudbg_get_mem_region(struct adapter *padap,
if (rc)
return rc;
 
-   for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
-   if (!strcmp(cudbg_region[i], region_name)) {
-   found = 1;
-   idx = i;
-   break;
-   }
-   }
-   if (!found)
-   return -EINVAL;
+   rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
+   if (rc < 0)
+   return rc;
 
-   found = 0;
+   idx = rc;
for (i = 0; i < meminfo->mem_c; i++) {
if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
continue; /* Skip holes */
-- 
1.7.12.4



[PATCH v2 14/21] sched/debug: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Signed-off-by: Yisheng Xie 
---
v2:
 - rename i to ret to show the change in returned value meaning - per Andy

 kernel/sched/debug.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 15b10e2..5591147 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -111,20 +111,19 @@ static int sched_feat_set(char *cmp)
cmp += 3;
}
 
-   for (i = 0; i < __SCHED_FEAT_NR; i++) {
-   if (strcmp(cmp, sched_feat_names[i]) == 0) {
-   if (neg) {
-   sysctl_sched_features &= ~(1UL << i);
-   sched_feat_disable(i);
-   } else {
-   sysctl_sched_features |= (1UL << i);
-   sched_feat_enable(i);
-   }
-   break;
-   }
+   i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
+   if (i < 0)
+   return i;
+
+   if (neg) {
+   sysctl_sched_features &= ~(1UL << i);
+   sched_feat_disable(i);
+   } else {
+   sysctl_sched_features |= (1UL << i);
+   sched_feat_enable(i);
}
 
-   return i;
+   return 0;
 }
 
 static ssize_t
@@ -133,7 +132,7 @@ static int sched_feat_set(char *cmp)
 {
char buf[64];
char *cmp;
-   int i;
+   int ret;
struct inode *inode;
 
if (cnt > 63)
@@ -148,10 +147,10 @@ static int sched_feat_set(char *cmp)
/* Ensure the static_key remains in a consistent state */
inode = file_inode(filp);
inode_lock(inode);
-   i = sched_feat_set(cmp);
+   ret = sched_feat_set(cmp);
inode_unlock(inode);
-   if (i == __SCHED_FEAT_NR)
-   return -EINVAL;
+   if (ret < 0)
+   return ret;
 
*ppos += cnt;
 
-- 
1.7.12.4



[PATCH v2 10/21] cpufreq: intel_pstate: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Andy Shevchenko 
Cc: Srinivas Pandruvada 
Cc: Len Brown 
Cc: "Rafael J. Wysocki" 
Cc: Viresh Kumar 
Cc: linux...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - add Reviewed-by tag.

 drivers/cpufreq/intel_pstate.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 17e566af..d701e26 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -645,21 +645,18 @@ static ssize_t store_energy_performance_preference(
 {
struct cpudata *cpu_data = all_cpu_data[policy->cpu];
char str_preference[21];
-   int ret, i = 0;
+   int ret;
 
ret = sscanf(buf, "%20s", str_preference);
if (ret != 1)
return -EINVAL;
 
-   while (energy_perf_strings[i] != NULL) {
-   if (!strcmp(str_preference, energy_perf_strings[i])) {
-   intel_pstate_set_energy_pref_index(cpu_data, i);
-   return count;
-   }
-   ++i;
-   }
+   ret = match_string(energy_perf_strings, -1, str_preference);
+   if (ret < 0)
+   return ret;
 
-   return -EINVAL;
+   intel_pstate_set_energy_pref_index(cpu_data, ret);
+   return count;
 }
 
 static ssize_t show_energy_performance_preference(
-- 
1.7.12.4



[PATCH v2 04/21] cxgb4: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Ganesh Goudar 
Cc: net...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
v2:
 - no change from v1.

 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c 
b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
index 9da6f57..bd61610 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
@@ -782,17 +782,11 @@ static int cudbg_get_mem_region(struct adapter *padap,
if (rc)
return rc;
 
-   for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
-   if (!strcmp(cudbg_region[i], region_name)) {
-   found = 1;
-   idx = i;
-   break;
-   }
-   }
-   if (!found)
-   return -EINVAL;
+   rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
+   if (rc < 0)
+   return rc;
 
-   found = 0;
+   idx = rc;
for (i = 0; i < meminfo->mem_c; i++) {
if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
continue; /* Skip holes */
-- 
1.7.12.4



[PATCH v2 14/21] sched/debug: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Signed-off-by: Yisheng Xie 
---
v2:
 - rename i to ret to show the change in returned value meaning - per Andy

 kernel/sched/debug.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 15b10e2..5591147 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -111,20 +111,19 @@ static int sched_feat_set(char *cmp)
cmp += 3;
}
 
-   for (i = 0; i < __SCHED_FEAT_NR; i++) {
-   if (strcmp(cmp, sched_feat_names[i]) == 0) {
-   if (neg) {
-   sysctl_sched_features &= ~(1UL << i);
-   sched_feat_disable(i);
-   } else {
-   sysctl_sched_features |= (1UL << i);
-   sched_feat_enable(i);
-   }
-   break;
-   }
+   i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
+   if (i < 0)
+   return i;
+
+   if (neg) {
+   sysctl_sched_features &= ~(1UL << i);
+   sched_feat_disable(i);
+   } else {
+   sysctl_sched_features |= (1UL << i);
+   sched_feat_enable(i);
}
 
-   return i;
+   return 0;
 }
 
 static ssize_t
@@ -133,7 +132,7 @@ static int sched_feat_set(char *cmp)
 {
char buf[64];
char *cmp;
-   int i;
+   int ret;
struct inode *inode;
 
if (cnt > 63)
@@ -148,10 +147,10 @@ static int sched_feat_set(char *cmp)
/* Ensure the static_key remains in a consistent state */
inode = file_inode(filp);
inode_lock(inode);
-   i = sched_feat_set(cmp);
+   ret = sched_feat_set(cmp);
inode_unlock(inode);
-   if (i == __SCHED_FEAT_NR)
-   return -EINVAL;
+   if (ret < 0)
+   return ret;
 
*ppos += cnt;
 
-- 
1.7.12.4



[PATCH v2 07/21] bus: fsl-mc: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Andy Shevchenko 
Cc: Stuart Yoder 
Cc: Laurentiu Tudor 
Signed-off-by: Yisheng Xie 
---
v2:
 - add Reviewed-by tag.

 drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c 
b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index fb1442b..63c4735 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -156,22 +156,6 @@ static int __must_check 
fsl_mc_resource_pool_remove_device(struct fsl_mc_device
[FSL_MC_POOL_IRQ] = "irq",
 };
 
-static int __must_check object_type_to_pool_type(const char *object_type,
-enum fsl_mc_pool_type
-   *pool_type)
-{
-   unsigned int i;
-
-   for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) {
-   if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) {
-   *pool_type = i;
-   return 0;
-   }
-   }
-
-   return -EINVAL;
-}
-
 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
  enum fsl_mc_pool_type pool_type,
  struct fsl_mc_resource **new_resource)
@@ -581,9 +565,11 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device 
*mc_dev)
return -EINVAL;
 
mc_bus = to_fsl_mc_bus(mc_bus_dev);
-   error = object_type_to_pool_type(mc_dev->obj_desc.type, _type);
-   if (error < 0)
-   return error;
+   pool_type = match_string(fsl_mc_pool_type_strings,
+ARRAY_SIZE(fsl_mc_pool_type_strings),
+mc_dev->obj_desc.type);
+   if (pool_type < 0)
+   return pool_type;
 
error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev);
if (error < 0)
-- 
1.7.12.4



[PATCH v2 07/21] bus: fsl-mc: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Andy Shevchenko 
Cc: Stuart Yoder 
Cc: Laurentiu Tudor 
Signed-off-by: Yisheng Xie 
---
v2:
 - add Reviewed-by tag.

 drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c 
b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index fb1442b..63c4735 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -156,22 +156,6 @@ static int __must_check 
fsl_mc_resource_pool_remove_device(struct fsl_mc_device
[FSL_MC_POOL_IRQ] = "irq",
 };
 
-static int __must_check object_type_to_pool_type(const char *object_type,
-enum fsl_mc_pool_type
-   *pool_type)
-{
-   unsigned int i;
-
-   for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) {
-   if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) {
-   *pool_type = i;
-   return 0;
-   }
-   }
-
-   return -EINVAL;
-}
-
 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
  enum fsl_mc_pool_type pool_type,
  struct fsl_mc_resource **new_resource)
@@ -581,9 +565,11 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device 
*mc_dev)
return -EINVAL;
 
mc_bus = to_fsl_mc_bus(mc_bus_dev);
-   error = object_type_to_pool_type(mc_dev->obj_desc.type, _type);
-   if (error < 0)
-   return error;
+   pool_type = match_string(fsl_mc_pool_type_strings,
+ARRAY_SIZE(fsl_mc_pool_type_strings),
+mc_dev->obj_desc.type);
+   if (pool_type < 0)
+   return pool_type;
 
error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev);
if (error < 0)
-- 
1.7.12.4



[PATCH v2 21/21] sparc64: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: "David S. Miller" 
Cc: Anthony Yznaga 
Cc: Pavel Tatashin 
Cc: sparcli...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
 arch/sparc/kernel/setup_64.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 7944b3c..7af8c7e 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
break;
}
}
-   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-   if (!strcmp(prop, crypto_hwcaps[i]))
-   caps |= HWCAP_SPARC_CRYPTO;
-   }
+   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
prop);
+   if (i >= 0)
+   caps |= HWCAP_SPARC_CRYPTO;
 
plen = strlen(prop) + 1;
prop += plen;
-- 
1.7.12.4



[PATCH v2 21/21] sparc64: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: "David S. Miller" 
Cc: Anthony Yznaga 
Cc: Pavel Tatashin 
Cc: sparcli...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
 arch/sparc/kernel/setup_64.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
index 7944b3c..7af8c7e 100644
--- a/arch/sparc/kernel/setup_64.c
+++ b/arch/sparc/kernel/setup_64.c
@@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
break;
}
}
-   for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-   if (!strcmp(prop, crypto_hwcaps[i]))
-   caps |= HWCAP_SPARC_CRYPTO;
-   }
+   i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), 
prop);
+   if (i >= 0)
+   caps |= HWCAP_SPARC_CRYPTO;
 
plen = strlen(prop) + 1;
prop += plen;
-- 
1.7.12.4



[PATCH v2 15/21] ALSA: oxygen: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Clemens Ladisch 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Signed-off-by: Yisheng Xie 
---
v2:
 - do not change the type of i - per Andy

 sound/pci/oxygen/oxygen_mixer.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 4ca1266..81af21a 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -1052,10 +1052,10 @@ static int add_controls(struct oxygen *chip,
[CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch",
[CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch",
};
-   unsigned int i, j;
+   unsigned int i;
struct snd_kcontrol_new template;
struct snd_kcontrol *ctl;
-   int err;
+   int j, err;
 
for (i = 0; i < count; ++i) {
template = controls[i];
@@ -1086,11 +1086,11 @@ static int add_controls(struct oxygen *chip,
err = snd_ctl_add(chip->card, ctl);
if (err < 0)
return err;
-   for (j = 0; j < CONTROL_COUNT; ++j)
-   if (!strcmp(ctl->id.name, known_ctl_names[j])) {
-   chip->controls[j] = ctl;
-   ctl->private_free = oxygen_any_ctl_free;
-   }
+   j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+   if (j >= 0) {
+   chip->controls[j] = ctl;
+   ctl->private_free = oxygen_any_ctl_free;
+   }
}
return 0;
 }
-- 
1.7.12.4



[PATCH v2 18/21] ASoC: dapm: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Andy Shevchenko 
Cc: Liam Girdwood 
Cc: Mark Brown 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Signed-off-by: Yisheng Xie 
---
v2:
 - add Reviewed-by tag.

 sound/soc/soc-dapm.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 2d97091..1e9a363 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -724,18 +724,14 @@ static int dapm_connect_mux(struct snd_soc_dapm_context 
*dapm,
item = 0;
}
 
-   for (i = 0; i < e->items; i++) {
-   if (!(strcmp(control_name, e->texts[i]))) {
-   path->name = e->texts[i];
-   if (i == item)
-   path->connect = 1;
-   else
-   path->connect = 0;
-   return 0;
-   }
-   }
+   i = match_string(e->texts, e->items, control_name);
+   if (i < 0)
+   return -ENODEV;
+
+   path->name = e->texts[i];
+   path->connect = (i == item);
+   return 0;
 
-   return -ENODEV;
 }
 
 /* set up initial codec paths */
-- 
1.7.12.4



[PATCH v2 17/21] ASoC: max98095: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Liam Girdwood 
Cc: Mark Brown 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Signed-off-by: Yisheng Xie 
---
v2:
 - split ret= and move assignment to the line before 'if' - per Andy

 sound/soc/codecs/max98095.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 6bf2d0b..3b3a10d 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -1634,15 +1634,12 @@ static void max98095_handle_eq_pdata(struct 
snd_soc_component *component)
 static int max98095_get_bq_channel(struct snd_soc_component *component,
   const char *name)
 {
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++)
-   if (strcmp(name, bq_mode_name[i]) == 0)
-   return i;
+   int ret;
 
-   /* Shouldn't happen */
-   dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
-   return -EINVAL;
+   ret = match_string(bq_mode_name, ARRAY_SIZE(bq_mode_name), name);
+   if (ret < 0)
+   dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
+   return ret;
 }
 
 static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
-- 
1.7.12.4



[PATCH v2 15/21] ALSA: oxygen: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Clemens Ladisch 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Signed-off-by: Yisheng Xie 
---
v2:
 - do not change the type of i - per Andy

 sound/pci/oxygen/oxygen_mixer.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 4ca1266..81af21a 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -1052,10 +1052,10 @@ static int add_controls(struct oxygen *chip,
[CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch",
[CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch",
};
-   unsigned int i, j;
+   unsigned int i;
struct snd_kcontrol_new template;
struct snd_kcontrol *ctl;
-   int err;
+   int j, err;
 
for (i = 0; i < count; ++i) {
template = controls[i];
@@ -1086,11 +1086,11 @@ static int add_controls(struct oxygen *chip,
err = snd_ctl_add(chip->card, ctl);
if (err < 0)
return err;
-   for (j = 0; j < CONTROL_COUNT; ++j)
-   if (!strcmp(ctl->id.name, known_ctl_names[j])) {
-   chip->controls[j] = ctl;
-   ctl->private_free = oxygen_any_ctl_free;
-   }
+   j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+   if (j >= 0) {
+   chip->controls[j] = ctl;
+   ctl->private_free = oxygen_any_ctl_free;
+   }
}
return 0;
 }
-- 
1.7.12.4



[PATCH v2 18/21] ASoC: dapm: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Reviewed-by: Andy Shevchenko 
Cc: Liam Girdwood 
Cc: Mark Brown 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Signed-off-by: Yisheng Xie 
---
v2:
 - add Reviewed-by tag.

 sound/soc/soc-dapm.c | 18 +++---
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 2d97091..1e9a363 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -724,18 +724,14 @@ static int dapm_connect_mux(struct snd_soc_dapm_context 
*dapm,
item = 0;
}
 
-   for (i = 0; i < e->items; i++) {
-   if (!(strcmp(control_name, e->texts[i]))) {
-   path->name = e->texts[i];
-   if (i == item)
-   path->connect = 1;
-   else
-   path->connect = 0;
-   return 0;
-   }
-   }
+   i = match_string(e->texts, e->items, control_name);
+   if (i < 0)
+   return -ENODEV;
+
+   path->name = e->texts[i];
+   path->connect = (i == item);
+   return 0;
 
-   return -ENODEV;
 }
 
 /* set up initial codec paths */
-- 
1.7.12.4



[PATCH v2 17/21] ASoC: max98095: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Liam Girdwood 
Cc: Mark Brown 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Signed-off-by: Yisheng Xie 
---
v2:
 - split ret= and move assignment to the line before 'if' - per Andy

 sound/soc/codecs/max98095.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 6bf2d0b..3b3a10d 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -1634,15 +1634,12 @@ static void max98095_handle_eq_pdata(struct 
snd_soc_component *component)
 static int max98095_get_bq_channel(struct snd_soc_component *component,
   const char *name)
 {
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++)
-   if (strcmp(name, bq_mode_name[i]) == 0)
-   return i;
+   int ret;
 
-   /* Shouldn't happen */
-   dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
-   return -EINVAL;
+   ret = match_string(bq_mode_name, ARRAY_SIZE(bq_mode_name), name);
+   if (ret < 0)
+   dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
+   return ret;
 }
 
 static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
-- 
1.7.12.4



[PATCH v2 19/21] bcache: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Kent Overstreet 
Cc: linux-bca...@vger.kernel.org 
Signed-off-by: Yisheng Xie 
---
 drivers/md/bcache/util.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
index 74febd5..cd1f4fd 100644
--- a/drivers/md/bcache/util.c
+++ b/drivers/md/bcache/util.c
@@ -136,22 +136,17 @@ ssize_t bch_snprint_string_list(char *buf, size_t size, 
const char * const list[
 
 ssize_t bch_read_string_list(const char *buf, const char * const list[])
 {
-   size_t i;
+   ssize_t i;
char *s, *d = kstrndup(buf, PAGE_SIZE - 1, GFP_KERNEL);
if (!d)
return -ENOMEM;
 
s = strim(d);
 
-   for (i = 0; list[i]; i++)
-   if (!strcmp(list[i], s))
-   break;
+   i = match_string(list, -1, s);
 
kfree(d);
 
-   if (!list[i])
-   return -EINVAL;
-
return i;
 }
 
-- 
1.7.12.4



[PATCH v2 19/21] bcache: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Kent Overstreet 
Cc: linux-bca...@vger.kernel.org 
Signed-off-by: Yisheng Xie 
---
 drivers/md/bcache/util.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
index 74febd5..cd1f4fd 100644
--- a/drivers/md/bcache/util.c
+++ b/drivers/md/bcache/util.c
@@ -136,22 +136,17 @@ ssize_t bch_snprint_string_list(char *buf, size_t size, 
const char * const list[
 
 ssize_t bch_read_string_list(const char *buf, const char * const list[])
 {
-   size_t i;
+   ssize_t i;
char *s, *d = kstrndup(buf, PAGE_SIZE - 1, GFP_KERNEL);
if (!d)
return -ENOMEM;
 
s = strim(d);
 
-   for (i = 0; list[i]; i++)
-   if (!strcmp(list[i], s))
-   break;
+   i = match_string(list, -1, s);
 
kfree(d);
 
-   if (!list[i])
-   return -EINVAL;
-
return i;
 }
 
-- 
1.7.12.4



[PATCH v2 16/21] ASoC: max98088: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Liam Girdwood 
Cc: Mark Brown 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Signed-off-by: Yisheng Xie 
---
v2:
 - split ret=xxx and move assignment to the line before 'if'
 - fix error return value - both per Andy

 sound/soc/codecs/max98088.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 865f64c..fb515aa 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -1382,15 +1382,12 @@ static int max98088_set_bias_level(struct 
snd_soc_component *component,
 
 static int max98088_get_channel(struct snd_soc_component *component, const 
char *name)
 {
-   int i;
+   int ret;
 
-   for (i = 0; i < ARRAY_SIZE(eq_mode_name); i++)
-   if (strcmp(name, eq_mode_name[i]) == 0)
-   return i;
-
-   /* Shouldn't happen */
-   dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
-   return -EINVAL;
+   ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
+   if (ret < 0)
+   dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
+   return ret;
 }
 
 static void max98088_setup_eq1(struct snd_soc_component *component)
-- 
1.7.12.4



[PATCH v2 20/21] powerpc/xmon: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linuxppc-...@lists.ozlabs.org
Signed-off-by: Yisheng Xie 
---
 arch/powerpc/xmon/xmon.c | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index a0842f1..872ac8c 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -3161,7 +3161,7 @@ static void proccall(void)
 }
 
 #define N_PTREGS   44
-static char *regnames[N_PTREGS] = {
+static const char *regnames[N_PTREGS] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
@@ -3196,18 +3196,17 @@ static void proccall(void)
regname[i] = c;
}
regname[i] = 0;
-   for (i = 0; i < N_PTREGS; ++i) {
-   if (strcmp(regnames[i], regname) == 0) {
-   if (xmon_regs == NULL) {
-   printf("regs not available\n");
-   return 0;
-   }
-   *vp = ((unsigned long *)xmon_regs)[i];
-   return 1;
-   }
+   i = match_string(regnames, N_PTREGS, regname);
+   if (i < 0) {
+   printf("invalid register name '%%%s'\n", regname);
+   return 0;
}
-   printf("invalid register name '%%%s'\n", regname);
-   return 0;
+   if (xmon_regs == NULL) {
+   printf("regs not available\n");
+   return 0;
+   }
+   *vp = ((unsigned long *)xmon_regs)[i];
+   return 1;
}
 
/* skip leading "0x" if any */
-- 
1.7.12.4



[PATCH v2 16/21] ASoC: max98088: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Liam Girdwood 
Cc: Mark Brown 
Cc: Jaroslav Kysela 
Cc: Takashi Iwai 
Cc: alsa-de...@alsa-project.org
Signed-off-by: Yisheng Xie 
---
v2:
 - split ret=xxx and move assignment to the line before 'if'
 - fix error return value - both per Andy

 sound/soc/codecs/max98088.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 865f64c..fb515aa 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -1382,15 +1382,12 @@ static int max98088_set_bias_level(struct 
snd_soc_component *component,
 
 static int max98088_get_channel(struct snd_soc_component *component, const 
char *name)
 {
-   int i;
+   int ret;
 
-   for (i = 0; i < ARRAY_SIZE(eq_mode_name); i++)
-   if (strcmp(name, eq_mode_name[i]) == 0)
-   return i;
-
-   /* Shouldn't happen */
-   dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
-   return -EINVAL;
+   ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
+   if (ret < 0)
+   dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
+   return ret;
 }
 
 static void max98088_setup_eq1(struct snd_soc_component *component)
-- 
1.7.12.4



[PATCH v2 20/21] powerpc/xmon: use match_string() helper

2018-05-31 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used instead of open coded variant.

Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linuxppc-...@lists.ozlabs.org
Signed-off-by: Yisheng Xie 
---
 arch/powerpc/xmon/xmon.c | 23 +++
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index a0842f1..872ac8c 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -3161,7 +3161,7 @@ static void proccall(void)
 }
 
 #define N_PTREGS   44
-static char *regnames[N_PTREGS] = {
+static const char *regnames[N_PTREGS] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
@@ -3196,18 +3196,17 @@ static void proccall(void)
regname[i] = c;
}
regname[i] = 0;
-   for (i = 0; i < N_PTREGS; ++i) {
-   if (strcmp(regnames[i], regname) == 0) {
-   if (xmon_regs == NULL) {
-   printf("regs not available\n");
-   return 0;
-   }
-   *vp = ((unsigned long *)xmon_regs)[i];
-   return 1;
-   }
+   i = match_string(regnames, N_PTREGS, regname);
+   if (i < 0) {
+   printf("invalid register name '%%%s'\n", regname);
+   return 0;
}
-   printf("invalid register name '%%%s'\n", regname);
-   return 0;
+   if (xmon_regs == NULL) {
+   printf("regs not available\n");
+   return 0;
+   }
+   *vp = ((unsigned long *)xmon_regs)[i];
+   return 1;
}
 
/* skip leading "0x" if any */
-- 
1.7.12.4



[PATCH v3 2/2] PCI: Check phys_addr for pci_remap_iospace

2018-05-29 Thread Yisheng Xie
If phys_addr is not page aligned, ioremap_page_range() will align down it
when get pfn by phys_addr >> PAGE_SHIFT. An example in arm64 system with
64KB page size:

 phys_addr:  0xefff8000
 res->start: 0x0
 res->end:   0x0
 PCI_IOBASE: 0x7fdffee0

This will remap virtual address 0x7fdffee0 to phys_addr 0xefff,
but what we really want is 0xefff8000, which makes later IO access to a
mess. And users may even donot know this until find some odd phenemenon.

This patch checks whether phys_addr is PAGE_ALIGNED or not to find the
primary scene.

Signed-off-by: Zhou Wang 
Signed-off-by: Yisheng Xie 
---
 drivers/pci/pci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 0eb0381..117ca6a 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3547,6 +3547,9 @@ int pci_remap_iospace(const struct resource *res, 
phys_addr_t phys_addr)
if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res)))
return -EINVAL;
 
+   if (!PAGE_ALIGNED(phys_addr))
+   return -EINVAL;
+
return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
  pgprot_device(PAGE_KERNEL));
 #else
-- 
1.7.12.4



[PATCH v3 2/2] PCI: Check phys_addr for pci_remap_iospace

2018-05-29 Thread Yisheng Xie
If phys_addr is not page aligned, ioremap_page_range() will align down it
when get pfn by phys_addr >> PAGE_SHIFT. An example in arm64 system with
64KB page size:

 phys_addr:  0xefff8000
 res->start: 0x0
 res->end:   0x0
 PCI_IOBASE: 0x7fdffee0

This will remap virtual address 0x7fdffee0 to phys_addr 0xefff,
but what we really want is 0xefff8000, which makes later IO access to a
mess. And users may even donot know this until find some odd phenemenon.

This patch checks whether phys_addr is PAGE_ALIGNED or not to find the
primary scene.

Signed-off-by: Zhou Wang 
Signed-off-by: Yisheng Xie 
---
 drivers/pci/pci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 0eb0381..117ca6a 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3547,6 +3547,9 @@ int pci_remap_iospace(const struct resource *res, 
phys_addr_t phys_addr)
if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res)))
return -EINVAL;
 
+   if (!PAGE_ALIGNED(phys_addr))
+   return -EINVAL;
+
return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
  pgprot_device(PAGE_KERNEL));
 #else
-- 
1.7.12.4



[PATCH v3 1/2] PCI: Avoid panic when PCI IO resource's size is not page aligned

2018-05-29 Thread Yisheng Xie
Zhou reported a bug on Hisilicon arm64 D06 platform with 64KB page size:

 [2.470908] kernel BUG at lib/ioremap.c:72!
 [2.475079] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
 [2.480551] Modules linked in:
 [2.483594] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 
4.16.0-rc7-00062-g0b41260-dirty #23
 [2.491756] Hardware name: Huawei D06/D06, BIOS Hisilicon D06 UEFI Nemo 2.0 
RC0 - B120 03/23/2018
 [2.500614] pstate: 80c9 (Nzcv daif +PAN +UAO)
 [2.505395] pc : ioremap_page_range+0x268/0x36c
 [2.509912] lr : pci_remap_iospace+0xe4/0x100
 [...]
 [2.603733] Call trace:
 [2.606168]  ioremap_page_range+0x268/0x36c
 [2.610337]  pci_remap_iospace+0xe4/0x100
 [2.614334]  acpi_pci_probe_root_resources+0x1d4/0x214
 [2.619460]  pci_acpi_root_prepare_resources+0x18/0xa8
 [2.624585]  acpi_pci_root_create+0x98/0x214
 [2.628843]  pci_acpi_scan_root+0x124/0x20c
 [2.633013]  acpi_pci_root_add+0x224/0x494
 [2.637096]  acpi_bus_attach+0xf8/0x200
 [2.640918]  acpi_bus_attach+0x98/0x200
 [2.644740]  acpi_bus_attach+0x98/0x200
 [2.648562]  acpi_bus_scan+0x48/0x9c
 [2.652125]  acpi_scan_init+0x104/0x268
 [2.655948]  acpi_init+0x308/0x374
 [2.659337]  do_one_initcall+0x48/0x14c
 [2.663160]  kernel_init_freeable+0x19c/0x250
 [2.667504]  kernel_init+0x10/0x100
 [2.670979]  ret_from_fork+0x10/0x18

The cause is the size of PCI IO resource is 32KB, which is 4K aligned but
not 64KB aligned, however, ioremap_page_range() request the range as page
aligned or it will trigger a BUG_ON() on ioremap_pte_range() it calls, as
ioremap_pte_range increase the addr by PAGE_SIZE, which makes addr != end
until trigger BUG_ON, if its incoming end is not page aligned. More detail
trace is as following:

 ioremap_page_range
 -> ioremap_p4d_range
-> ioremap_p4d_range
   -> ioremap_pud_range
  -> ioremap_pmd_range
 -> ioremap_pte_range

This patch avoid panic by return -EINVAL if vaddr or resource size is not
page aligned.

Reported-by: Zhou Wang 
Tested-by: Xiaojun Tan 
Signed-off-by: Yisheng Xie 
---
v3:
 - pci_remap_iospace() sanitize its arguments instead - per Rafael

v2:
 - Let the caller of ioremap_page_range() align the request by PAGE_SIZE - per 
Toshi

 drivers/pci/pci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index dbfe7c4..0eb0381 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3544,6 +3544,9 @@ int pci_remap_iospace(const struct resource *res, 
phys_addr_t phys_addr)
if (res->end > IO_SPACE_LIMIT)
return -EINVAL;
 
+   if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res)))
+   return -EINVAL;
+
return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
  pgprot_device(PAGE_KERNEL));
 #else
-- 
1.7.12.4



[PATCH v3 1/2] PCI: Avoid panic when PCI IO resource's size is not page aligned

2018-05-29 Thread Yisheng Xie
Zhou reported a bug on Hisilicon arm64 D06 platform with 64KB page size:

 [2.470908] kernel BUG at lib/ioremap.c:72!
 [2.475079] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
 [2.480551] Modules linked in:
 [2.483594] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 
4.16.0-rc7-00062-g0b41260-dirty #23
 [2.491756] Hardware name: Huawei D06/D06, BIOS Hisilicon D06 UEFI Nemo 2.0 
RC0 - B120 03/23/2018
 [2.500614] pstate: 80c9 (Nzcv daif +PAN +UAO)
 [2.505395] pc : ioremap_page_range+0x268/0x36c
 [2.509912] lr : pci_remap_iospace+0xe4/0x100
 [...]
 [2.603733] Call trace:
 [2.606168]  ioremap_page_range+0x268/0x36c
 [2.610337]  pci_remap_iospace+0xe4/0x100
 [2.614334]  acpi_pci_probe_root_resources+0x1d4/0x214
 [2.619460]  pci_acpi_root_prepare_resources+0x18/0xa8
 [2.624585]  acpi_pci_root_create+0x98/0x214
 [2.628843]  pci_acpi_scan_root+0x124/0x20c
 [2.633013]  acpi_pci_root_add+0x224/0x494
 [2.637096]  acpi_bus_attach+0xf8/0x200
 [2.640918]  acpi_bus_attach+0x98/0x200
 [2.644740]  acpi_bus_attach+0x98/0x200
 [2.648562]  acpi_bus_scan+0x48/0x9c
 [2.652125]  acpi_scan_init+0x104/0x268
 [2.655948]  acpi_init+0x308/0x374
 [2.659337]  do_one_initcall+0x48/0x14c
 [2.663160]  kernel_init_freeable+0x19c/0x250
 [2.667504]  kernel_init+0x10/0x100
 [2.670979]  ret_from_fork+0x10/0x18

The cause is the size of PCI IO resource is 32KB, which is 4K aligned but
not 64KB aligned, however, ioremap_page_range() request the range as page
aligned or it will trigger a BUG_ON() on ioremap_pte_range() it calls, as
ioremap_pte_range increase the addr by PAGE_SIZE, which makes addr != end
until trigger BUG_ON, if its incoming end is not page aligned. More detail
trace is as following:

 ioremap_page_range
 -> ioremap_p4d_range
-> ioremap_p4d_range
   -> ioremap_pud_range
  -> ioremap_pmd_range
 -> ioremap_pte_range

This patch avoid panic by return -EINVAL if vaddr or resource size is not
page aligned.

Reported-by: Zhou Wang 
Tested-by: Xiaojun Tan 
Signed-off-by: Yisheng Xie 
---
v3:
 - pci_remap_iospace() sanitize its arguments instead - per Rafael

v2:
 - Let the caller of ioremap_page_range() align the request by PAGE_SIZE - per 
Toshi

 drivers/pci/pci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index dbfe7c4..0eb0381 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3544,6 +3544,9 @@ int pci_remap_iospace(const struct resource *res, 
phys_addr_t phys_addr)
if (res->end > IO_SPACE_LIMIT)
return -EINVAL;
 
+   if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res)))
+   return -EINVAL;
+
return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
  pgprot_device(PAGE_KERNEL));
 #else
-- 
1.7.12.4



Re: [PATCH 19/33] thermal: db8500: use match_string() helper

2018-05-23 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:00, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>> +   i = match_string((const char **)trip_point->cdev_name,
> 
> Casting looks ugly. You need to constify the variable itself.
When I tried to const cdev_name like:
+++ b/include/linux/platform_data/db8500_thermal.h
@@ -27,7 +27,7 @@
 struct db8500_trip_point {
unsigned long temp;
enum thermal_trip_type type;
-   char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH];
+   char const cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH]; // const 
char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH] will also the same
 };

The compiler will also warning:
drivers/thermal/db8500_thermal.c: In function ‘db8500_thermal_match_cdev’:
drivers/thermal/db8500_thermal.c:53:2: warning: passing argument 1 of 
‘match_string’ from incompatible pointer type [enabled by default]
  i = match_string(trip_point->cdev_name, COOLING_DEV_MAX, cdev->type);
  ^
In file included from include/linux/bitmap.h:9:0,
 from include/linux/cpumask.h:12,
 from include/linux/rcupdate.h:44,
 from include/linux/radix-tree.h:28,
 from include/linux/idr.h:15,
 from include/linux/kernfs.h:14,
 from include/linux/sysfs.h:16,
 from kernel/include/linux/kobject.h:20,
 from kernel/include/linux/of.h:17,
 from include/linux/cpu_cooling.h:27,
 from drivers/thermal/db8500_thermal.c:20:
include/linux/string.h:184:5: note: expected ‘const char * const*’ but argument 
is of type ‘const char (*)[20]’

Any idea?

Thanks
Yisheng
> 
>> +COOLING_DEV_MAX, cdev->type);
>>
>> -   return -ENODEV;
>> +   return (i < 0) ? -ENODEV : 0;
> 
> I would rather go with
> 
> if (ret < 0)
>  return -ENODEV;
> 
> return 0;
> 



Re: [PATCH 19/33] thermal: db8500: use match_string() helper

2018-05-23 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:00, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>> +   i = match_string((const char **)trip_point->cdev_name,
> 
> Casting looks ugly. You need to constify the variable itself.
When I tried to const cdev_name like:
+++ b/include/linux/platform_data/db8500_thermal.h
@@ -27,7 +27,7 @@
 struct db8500_trip_point {
unsigned long temp;
enum thermal_trip_type type;
-   char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH];
+   char const cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH]; // const 
char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH] will also the same
 };

The compiler will also warning:
drivers/thermal/db8500_thermal.c: In function ‘db8500_thermal_match_cdev’:
drivers/thermal/db8500_thermal.c:53:2: warning: passing argument 1 of 
‘match_string’ from incompatible pointer type [enabled by default]
  i = match_string(trip_point->cdev_name, COOLING_DEV_MAX, cdev->type);
  ^
In file included from include/linux/bitmap.h:9:0,
 from include/linux/cpumask.h:12,
 from include/linux/rcupdate.h:44,
 from include/linux/radix-tree.h:28,
 from include/linux/idr.h:15,
 from include/linux/kernfs.h:14,
 from include/linux/sysfs.h:16,
 from kernel/include/linux/kobject.h:20,
 from kernel/include/linux/of.h:17,
 from include/linux/cpu_cooling.h:27,
 from drivers/thermal/db8500_thermal.c:20:
include/linux/string.h:184:5: note: expected ‘const char * const*’ but argument 
is of type ‘const char (*)[20]’

Any idea?

Thanks
Yisheng
> 
>> +COOLING_DEV_MAX, cdev->type);
>>
>> -   return -ENODEV;
>> +   return (i < 0) ? -ENODEV : 0;
> 
> I would rather go with
> 
> if (ret < 0)
>  return -ENODEV;
> 
> return 0;
> 



Re: [PATCH 31/33] ASoC: max98088: use match_string() helper

2018-05-22 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:24, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:58 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>>  static int max98088_get_channel(struct snd_soc_component *component, const 
>> char *name)
>>  {
> 
>> +   int ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
> I would rather split this and move an assignment to the line before 'if'

hmm, you mean something like:

int ret;

ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
if (ret < 0) /* Shouldn't happen */
dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
return ret;
>>
>> /* Shouldn't happen */
> 
>> +   if (ret < 0)
>> +   dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
> 
>> return -EINVAL;
> 
> return ret;
Right, sorry for this big mistake.

Thanks
Yisheng
> 
> ?
> 
>>  }
>>
>> --
>> 1.7.12.4
>>
> 
> 
> 



Re: [PATCH 31/33] ASoC: max98088: use match_string() helper

2018-05-22 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:24, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:58 PM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>>  static int max98088_get_channel(struct snd_soc_component *component, const 
>> char *name)
>>  {
> 
>> +   int ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
> I would rather split this and move an assignment to the line before 'if'

hmm, you mean something like:

int ret;

ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
if (ret < 0) /* Shouldn't happen */
dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
return ret;
>>
>> /* Shouldn't happen */
> 
>> +   if (ret < 0)
>> +   dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
> 
>> return -EINVAL;
> 
> return ret;
Right, sorry for this big mistake.

Thanks
Yisheng
> 
> ?
> 
>>  }
>>
>> --
>> 1.7.12.4
>>
> 
> 
> 



Re: [PATCH 27/33] sched/debug: use match_string() helper

2018-05-22 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:13, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:58 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
>>
>> Cc: Ingo Molnar <mi...@redhat.com>
>> Cc: Peter Zijlstra <pet...@infradead.org>
>> Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
>> ---
>>  kernel/sched/debug.c | 20 +---
>>  1 file changed, 9 insertions(+), 11 deletions(-)
>>
>> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
>> index 15b10e2..9e34499 100644
>> --- a/kernel/sched/debug.c
>> +++ b/kernel/sched/debug.c
>> @@ -111,16 +111,14 @@ static int sched_feat_set(char *cmp)
>> cmp += 3;
>> }
>>
>> -   for (i = 0; i < __SCHED_FEAT_NR; i++) {
>> -   if (strcmp(cmp, sched_feat_names[i]) == 0) {
>> -   if (neg) {
>> -   sysctl_sched_features &= ~(1UL << i);
>> -   sched_feat_disable(i);
>> -   } else {
>> -   sysctl_sched_features |= (1UL << i);
>> -   sched_feat_enable(i);
>> -   }
>> -   break;
>> +   i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
> 
>> +   if (i >= 0) {
> 
> Why not
> 
> if (i < 0)
>  return i;

if i >=0 it will also return i. so need return i just if (i < 0), right ?

> 
> ?
> 
>> +   if (neg) {
>> +   sysctl_sched_features &= ~(1UL << i);
>> +   sched_feat_disable(i);
>> +   } else {
>> +   sysctl_sched_features |= (1UL << i);
>> +   sched_feat_enable(i);
>> }
>> }
>>
>> @@ -150,7 +148,7 @@ static int sched_feat_set(char *cmp)
>> inode_lock(inode);
>> i = sched_feat_set(cmp);
>> inode_unlock(inode);
> 
>> -   if (i == __SCHED_FEAT_NR)
>> +   if (i < 0)
>> return -EINVAL;
> 
> Now it would be
> 
> if (i < 0)
>  return i;

Right, will change it in next version

Thanks
Yisheng Xie
> 



Re: [PATCH 27/33] sched/debug: use match_string() helper

2018-05-22 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:13, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:58 PM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
>>
>> Cc: Ingo Molnar 
>> Cc: Peter Zijlstra 
>> Signed-off-by: Yisheng Xie 
>> ---
>>  kernel/sched/debug.c | 20 +---
>>  1 file changed, 9 insertions(+), 11 deletions(-)
>>
>> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
>> index 15b10e2..9e34499 100644
>> --- a/kernel/sched/debug.c
>> +++ b/kernel/sched/debug.c
>> @@ -111,16 +111,14 @@ static int sched_feat_set(char *cmp)
>> cmp += 3;
>> }
>>
>> -   for (i = 0; i < __SCHED_FEAT_NR; i++) {
>> -   if (strcmp(cmp, sched_feat_names[i]) == 0) {
>> -   if (neg) {
>> -   sysctl_sched_features &= ~(1UL << i);
>> -   sched_feat_disable(i);
>> -   } else {
>> -   sysctl_sched_features |= (1UL << i);
>> -   sched_feat_enable(i);
>> -   }
>> -   break;
>> +   i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
> 
>> +   if (i >= 0) {
> 
> Why not
> 
> if (i < 0)
>  return i;

if i >=0 it will also return i. so need return i just if (i < 0), right ?

> 
> ?
> 
>> +   if (neg) {
>> +   sysctl_sched_features &= ~(1UL << i);
>> +   sched_feat_disable(i);
>> +   } else {
>> +   sysctl_sched_features |= (1UL << i);
>> +   sched_feat_enable(i);
>> }
>> }
>>
>> @@ -150,7 +148,7 @@ static int sched_feat_set(char *cmp)
>> inode_lock(inode);
>> i = sched_feat_set(cmp);
>> inode_unlock(inode);
> 
>> -   if (i == __SCHED_FEAT_NR)
>> +   if (i < 0)
>> return -EINVAL;
> 
> Now it would be
> 
> if (i < 0)
>  return i;

Right, will change it in next version

Thanks
Yisheng Xie
> 



Re: [PATCH 01/33] usb: phy: use match_string() helper

2018-05-22 Thread Yisheng Xie
Hi,

On 2018/5/22 18:02, Greg Kroah-Hartman wrote:
> On Tue, May 22, 2018 at 01:20:01AM +0300, Andy Shevchenko wrote:
>> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>>> match_string() returns the index of an array for a matching string,
>>> which can be used intead of open coded variant.
>>
>>> -   int err, i;
>>> +   int ret;
>>
>> int err;
>>
>> would still work.
> 
> And it reduces churn.

I will keep it as err in next version.

Thanks
Yisheng
> 
> 



Re: [PATCH 01/33] usb: phy: use match_string() helper

2018-05-22 Thread Yisheng Xie
Hi,

On 2018/5/22 18:02, Greg Kroah-Hartman wrote:
> On Tue, May 22, 2018 at 01:20:01AM +0300, Andy Shevchenko wrote:
>> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie  wrote:
>>> match_string() returns the index of an array for a matching string,
>>> which can be used intead of open coded variant.
>>
>>> -   int err, i;
>>> +   int ret;
>>
>> int err;
>>
>> would still work.
> 
> And it reduces churn.

I will keep it as err in next version.

Thanks
Yisheng
> 
> 



Re: [PATCH 22/33] drm/i915: use match_string() helper

2018-05-22 Thread Yisheng Xie
Hi Jani,

On 2018/5/22 16:36, Jani Nikula wrote:
> On Tue, 22 May 2018, Andy Shevchenko <andy.shevche...@gmail.com> wrote:
>> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>>> match_string() returns the index of an array for a matching string,
>>> which can be used intead of open coded variant.
>>
>> https://patchwork.kernel.org/patch/10382323/
> 
> Even more convincingly,
> 
> 47d4cb8ae8e7 ("i915: Convert to use match_string() helper")

Sorry, but I will definitely remove them in next version, I just miss these.

Thanks
Yisheng
> 
> BR,
> Jani.
> 
>>
>>> Cc: Jani Nikula <jani.nik...@linux.intel.com>
>>> Cc: Joonas Lahtinen <joonas.lahti...@linux.intel.com>
>>> Cc: Rodrigo Vivi <rodrigo.v...@intel.com>
>>> Cc: David Airlie <airl...@linux.ie>
>>> Cc: intel-...@lists.freedesktop.org
>>> Cc: dri-de...@lists.freedesktop.org
> 



Re: [PATCH 22/33] drm/i915: use match_string() helper

2018-05-22 Thread Yisheng Xie
Hi Jani,

On 2018/5/22 16:36, Jani Nikula wrote:
> On Tue, 22 May 2018, Andy Shevchenko  wrote:
>> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie  wrote:
>>> match_string() returns the index of an array for a matching string,
>>> which can be used intead of open coded variant.
>>
>> https://patchwork.kernel.org/patch/10382323/
> 
> Even more convincingly,
> 
> 47d4cb8ae8e7 ("i915: Convert to use match_string() helper")

Sorry, but I will definitely remove them in next version, I just miss these.

Thanks
Yisheng
> 
> BR,
> Jani.
> 
>>
>>> Cc: Jani Nikula 
>>> Cc: Joonas Lahtinen 
>>> Cc: Rodrigo Vivi 
>>> Cc: David Airlie 
>>> Cc: intel-...@lists.freedesktop.org
>>> Cc: dri-de...@lists.freedesktop.org
> 



Re: [PATCH 12/33] clk: bcm2835: use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 5:50, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
>>
>> Cc: Michael Turquette <mturque...@baylibre.com>
>> Cc: Stephen Boyd <sb...@kernel.org>
>> Cc: Eric Anholt <e...@anholt.net>
>> Cc: Stefan Wahren <stefan.wah...@i2se.com>
>> Cc: linux-...@vger.kernel.org
>> Cc: linux-rpi-ker...@lists.infradead.org
>> Cc: linux-arm-ker...@lists.infradead.org
>> Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
> 
>> -   size_t i, j;
>> -   int ret;
>> +   int i, ret;
> 
> I do not see any need to change type for i.

Right, I just want to smaller the line of code, for unsinged int is also OK for 
i.
Anyway, I can change it as your suggestion in next version.

Thanks
Yisheng

> 
>> +   ret = match_string(cprman_parent_names,
>> +  ARRAY_SIZE(cprman_parent_names),
>> +  parents[i]);
>> +   if (ret >= 0)
>> +   parents[i] = cprman->real_parent_names[ret];
> 
> 



Re: [PATCH 12/33] clk: bcm2835: use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 5:50, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
>>
>> Cc: Michael Turquette 
>> Cc: Stephen Boyd 
>> Cc: Eric Anholt 
>> Cc: Stefan Wahren 
>> Cc: linux-...@vger.kernel.org
>> Cc: linux-rpi-ker...@lists.infradead.org
>> Cc: linux-arm-ker...@lists.infradead.org
>> Signed-off-by: Yisheng Xie 
> 
>> -   size_t i, j;
>> -   int ret;
>> +   int i, ret;
> 
> I do not see any need to change type for i.

Right, I just want to smaller the line of code, for unsinged int is also OK for 
i.
Anyway, I can change it as your suggestion in next version.

Thanks
Yisheng

> 
>> +   ret = match_string(cprman_parent_names,
>> +  ARRAY_SIZE(cprman_parent_names),
>> +  parents[i]);
>> +   if (ret >= 0)
>> +   parents[i] = cprman->real_parent_names[ret];
> 
> 



Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 5:43, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>> int ret, bt_force_ant_mode;
>>
>> -   for (bt_force_ant_mode = 0;
>> -bt_force_ant_mode < ARRAY_SIZE(modes_str);
>> -bt_force_ant_mode++) {
>> -   if (!strcmp(buf, modes_str[bt_force_ant_mode]))
>> -   break;
>> -   }
>> -
>> -   if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
> 
>> +   bt_force_ant_mode = match_string(modes_str,
>> +ARRAY_SIZE(modes_str), buf);
> 
> One line?

hmm, if use ret instead it will no over 80 chars.

> 
>> +   if (bt_force_ant_mode < 0)
>> return -EINVAL;
> 
> I would rather use
> 
> ret = match_string();
> if (ret < 0)
>  return ret;
> 
> bt_force_... = ret;
> 
> But it's up tu Loca.

OK, I will change it if Loca agree your opinion.

Thanks
Yisheng
> 
>>
>> ret = 0;
> 
> 
> 



Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 5:43, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>> int ret, bt_force_ant_mode;
>>
>> -   for (bt_force_ant_mode = 0;
>> -bt_force_ant_mode < ARRAY_SIZE(modes_str);
>> -bt_force_ant_mode++) {
>> -   if (!strcmp(buf, modes_str[bt_force_ant_mode]))
>> -   break;
>> -   }
>> -
>> -   if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
> 
>> +   bt_force_ant_mode = match_string(modes_str,
>> +ARRAY_SIZE(modes_str), buf);
> 
> One line?

hmm, if use ret instead it will no over 80 chars.

> 
>> +   if (bt_force_ant_mode < 0)
>> return -EINVAL;
> 
> I would rather use
> 
> ret = match_string();
> if (ret < 0)
>  return ret;
> 
> bt_force_... = ret;
> 
> But it's up tu Loca.

OK, I will change it if Loca agree your opinion.

Thanks
Yisheng
> 
>>
>> ret = 0;
> 
> 
> 



Re: [PATCH 26/33] apparmor: use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi John,

On 2018/5/21 23:33, John Johansen wrote:
> On 05/21/2018 04:58 AM, Yisheng Xie wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
>>
> 
> Andy Shevchenko patch to do the same thing is already in apparmor-next

Sorry, I will drop this one.

Thanks
Yisheng
> 
>> Cc: John Johansen <john.johan...@canonical.com>
>> Cc: James Morris <jmor...@namei.org>
>> Cc: "Serge E. Hallyn" <se...@hallyn.com>
>> Cc: linux-security-mod...@vger.kernel.org
>> Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
>> ---
>>  security/apparmor/lsm.c | 25 +++--
>>  1 file changed, 11 insertions(+), 14 deletions(-)
>>
>> diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
>> index ce2b89e..9b5904f 100644
>> --- a/security/apparmor/lsm.c
>> +++ b/security/apparmor/lsm.c
>> @@ -1378,14 +1378,12 @@ static int param_set_audit(const char *val, const 
>> struct kernel_param *kp)
>>  if (apparmor_initialized && !policy_admin_capable(NULL))
>>  return -EPERM;
>>  
>> -for (i = 0; i < AUDIT_MAX_INDEX; i++) {
>> -if (strcmp(val, audit_mode_names[i]) == 0) {
>> -aa_g_audit = i;
>> -return 0;
>> -}
>> -}
>> +i = match_string(audit_mode_names, AUDIT_MAX_INDEX, val);
>> +if (i < 0)
>> +return -EINVAL;
>>  
>> -return -EINVAL;
>> +aa_g_audit = i;
>> +return 0;
>>  }
>>  
>>  static int param_get_mode(char *buffer, const struct kernel_param *kp)
>> @@ -1409,14 +1407,13 @@ static int param_set_mode(const char *val, const 
>> struct kernel_param *kp)
>>  if (apparmor_initialized && !policy_admin_capable(NULL))
>>  return -EPERM;
>>  
>> -for (i = 0; i < APPARMOR_MODE_NAMES_MAX_INDEX; i++) {
>> -if (strcmp(val, aa_profile_mode_names[i]) == 0) {
>> -aa_g_profile_mode = i;
>> -return 0;
>> -}
>> -}
>> +i = match_string(aa_profile_mode_names,
>> + APPARMOR_MODE_NAMES_MAX_INDEX, val);
>> +if (i)
>> +return -EINVAL;
>>  
>> -return -EINVAL;
>> +aa_g_profile_mode = i;
>> +return 0;
>>  }
>>  
>>  /*
>>
> 
> 
> 



Re: [PATCH 26/33] apparmor: use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi John,

On 2018/5/21 23:33, John Johansen wrote:
> On 05/21/2018 04:58 AM, Yisheng Xie wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
>>
> 
> Andy Shevchenko patch to do the same thing is already in apparmor-next

Sorry, I will drop this one.

Thanks
Yisheng
> 
>> Cc: John Johansen 
>> Cc: James Morris 
>> Cc: "Serge E. Hallyn" 
>> Cc: linux-security-mod...@vger.kernel.org
>> Signed-off-by: Yisheng Xie 
>> ---
>>  security/apparmor/lsm.c | 25 +++--
>>  1 file changed, 11 insertions(+), 14 deletions(-)
>>
>> diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
>> index ce2b89e..9b5904f 100644
>> --- a/security/apparmor/lsm.c
>> +++ b/security/apparmor/lsm.c
>> @@ -1378,14 +1378,12 @@ static int param_set_audit(const char *val, const 
>> struct kernel_param *kp)
>>  if (apparmor_initialized && !policy_admin_capable(NULL))
>>  return -EPERM;
>>  
>> -for (i = 0; i < AUDIT_MAX_INDEX; i++) {
>> -if (strcmp(val, audit_mode_names[i]) == 0) {
>> -aa_g_audit = i;
>> -return 0;
>> -}
>> -}
>> +i = match_string(audit_mode_names, AUDIT_MAX_INDEX, val);
>> +if (i < 0)
>> +return -EINVAL;
>>  
>> -return -EINVAL;
>> +aa_g_audit = i;
>> +return 0;
>>  }
>>  
>>  static int param_get_mode(char *buffer, const struct kernel_param *kp)
>> @@ -1409,14 +1407,13 @@ static int param_set_mode(const char *val, const 
>> struct kernel_param *kp)
>>  if (apparmor_initialized && !policy_admin_capable(NULL))
>>  return -EPERM;
>>  
>> -for (i = 0; i < APPARMOR_MODE_NAMES_MAX_INDEX; i++) {
>> -if (strcmp(val, aa_profile_mode_names[i]) == 0) {
>> -aa_g_profile_mode = i;
>> -return 0;
>> -}
>> -}
>> +i = match_string(aa_profile_mode_names,
>> + APPARMOR_MODE_NAMES_MAX_INDEX, val);
>> +if (i)
>> +return -EINVAL;
>>  
>> -return -EINVAL;
>> +aa_g_profile_mode = i;
>> +return 0;
>>  }
>>  
>>  /*
>>
> 
> 
> 



Re: [PATCH 05/33] cxgb4: use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 5:39, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>> -   for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
>> -   if (!strcmp(cudbg_region[i], region_name)) {
>> -   found = 1;
>> -   idx = i;
>> -   break;
>> -   }
>> -   }
>> -   if (!found)
>> -   return -EINVAL;
>> +   rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), 
>> region_name);
>> +   if (rc < 0)
>> +   return rc;
>>
>> -   found = 0;
>> +   idx = rc;
> 
> Is found still in use after this?
> If so, is it initialized properly now?
it is initialized  when define 'found', so no need to be initialized once more.

Thanks
Yisheng

> 



Re: [PATCH 05/33] cxgb4: use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 5:39, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie  wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>> -   for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
>> -   if (!strcmp(cudbg_region[i], region_name)) {
>> -   found = 1;
>> -   idx = i;
>> -   break;
>> -   }
>> -   }
>> -   if (!found)
>> -   return -EINVAL;
>> +   rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), 
>> region_name);
>> +   if (rc < 0)
>> +   return rc;
>>
>> -   found = 0;
>> +   idx = rc;
> 
> Is found still in use after this?
> If so, is it initialized properly now?
it is initialized  when define 'found', so no need to be initialized once more.

Thanks
Yisheng

> 



Re: [PATCH 00/33] use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:27, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>> Andy introduce helper function match_string() which can be used to return
>> the index of array for a matching string. so we can use it in many places
>> intead of open coded variant.
> 
> You forgot to Cc that Andy.

Yeah, I just forgot it when send them out.
> 
> For the patches I didn't comment, LGTM
> 
> Reviewed-by: Andy Shevchenko <andy.shevche...@gmail.com>

Thanks, and I will drop the ones you already sent out, and make a v2 as your 
comment!

Thanks
Yisheng



Re: [PATCH 00/33] use match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:27, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie  wrote:
>> Andy introduce helper function match_string() which can be used to return
>> the index of array for a matching string. so we can use it in many places
>> intead of open coded variant.
> 
> You forgot to Cc that Andy.

Yeah, I just forgot it when send them out.
> 
> For the patches I didn't comment, LGTM
> 
> Reviewed-by: Andy Shevchenko 

Thanks, and I will drop the ones you already sent out, and make a v2 as your 
comment!

Thanks
Yisheng



Re: [PATCH] intel_th: pti: Convert to use sysfs_match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:16, Andy Shevchenko wrote:
> On Wed, May 16, 2018 at 12:15 PM, Yisheng Xie <xieyishe...@huawei.com> wrote:
>> The helper returns index of the matching string in an array,
>> use it to simpler the code.
> 
> IIRC I sent the patch with the same semantics week or so ago against this 
> file.

Right, I get it. Sorry about that.

Thanks
Yisheng
> 
>>
>> Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
>> ---
>>  drivers/hwtracing/intel_th/pti.c | 11 ---
>>  1 file changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/hwtracing/intel_th/pti.c 
>> b/drivers/hwtracing/intel_th/pti.c
>> index 5669433..75cb368 100644
>> --- a/drivers/hwtracing/intel_th/pti.c
>> +++ b/drivers/hwtracing/intel_th/pti.c
>> @@ -272,15 +272,12 @@ static ssize_t lpp_dest_store(struct device *dev, 
>> struct device_attribute *attr,
>>   const char *buf, size_t size)
>>  {
>> struct pti_device *pti = dev_get_drvdata(dev);
>> -   ssize_t ret = -EINVAL;
>> -   int i;
>> +   ssize_t ret;
>>
>> -   for (i = 0; i < ARRAY_SIZE(lpp_dest_str); i++)
>> -   if (sysfs_streq(buf, lpp_dest_str[i]))
>> -   break;
>> +   ret = sysfs_match_string(lpp_dest_str, buf);
>>
>> -   if (i < ARRAY_SIZE(lpp_dest_str) && pti->lpp_dest_mask & BIT(i)) {
>> -   pti->lpp_dest = i;
>> +   if (ret >= 0 && pti->lpp_dest_mask & BIT(ret)) {
>> +   pti->lpp_dest = ret;
>> ret = size;
>> }
>>
>> --
>> 1.7.12.4
>>
> 
> 
> 



Re: [PATCH] intel_th: pti: Convert to use sysfs_match_string() helper

2018-05-21 Thread Yisheng Xie
Hi Andy,

On 2018/5/22 6:16, Andy Shevchenko wrote:
> On Wed, May 16, 2018 at 12:15 PM, Yisheng Xie  wrote:
>> The helper returns index of the matching string in an array,
>> use it to simpler the code.
> 
> IIRC I sent the patch with the same semantics week or so ago against this 
> file.

Right, I get it. Sorry about that.

Thanks
Yisheng
> 
>>
>> Signed-off-by: Yisheng Xie 
>> ---
>>  drivers/hwtracing/intel_th/pti.c | 11 ---
>>  1 file changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/hwtracing/intel_th/pti.c 
>> b/drivers/hwtracing/intel_th/pti.c
>> index 5669433..75cb368 100644
>> --- a/drivers/hwtracing/intel_th/pti.c
>> +++ b/drivers/hwtracing/intel_th/pti.c
>> @@ -272,15 +272,12 @@ static ssize_t lpp_dest_store(struct device *dev, 
>> struct device_attribute *attr,
>>   const char *buf, size_t size)
>>  {
>> struct pti_device *pti = dev_get_drvdata(dev);
>> -   ssize_t ret = -EINVAL;
>> -   int i;
>> +   ssize_t ret;
>>
>> -   for (i = 0; i < ARRAY_SIZE(lpp_dest_str); i++)
>> -   if (sysfs_streq(buf, lpp_dest_str[i]))
>> -   break;
>> +   ret = sysfs_match_string(lpp_dest_str, buf);
>>
>> -   if (i < ARRAY_SIZE(lpp_dest_str) && pti->lpp_dest_mask & BIT(i)) {
>> -   pti->lpp_dest = i;
>> +   if (ret >= 0 && pti->lpp_dest_mask & BIT(ret)) {
>> +   pti->lpp_dest = ret;
>> ret = size;
>> }
>>
>> --
>> 1.7.12.4
>>
> 
> 
> 



[PATCH 07/33] iwlwifi: mvm: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Kalle Valo <kv...@codeaurora.org>
Cc: Intel Linux Wireless <linuxw...@intel.com>
Cc: Johannes Berg <johannes.b...@intel.com>
Cc: Emmanuel Grumbach <emmanuel.grumb...@intel.com>
Cc: linux-wirel...@vger.kernel.org
Cc: net...@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
---
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
index 0e6401c..e8249a6 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
@@ -671,14 +671,9 @@ static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, 
char __user *user_buf,
};
int ret, bt_force_ant_mode;
 
-   for (bt_force_ant_mode = 0;
-bt_force_ant_mode < ARRAY_SIZE(modes_str);
-bt_force_ant_mode++) {
-   if (!strcmp(buf, modes_str[bt_force_ant_mode]))
-   break;
-   }
-
-   if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
+   bt_force_ant_mode = match_string(modes_str,
+ARRAY_SIZE(modes_str), buf);
+   if (bt_force_ant_mode < 0)
return -EINVAL;
 
ret = 0;
-- 
1.7.12.4



[PATCH 07/33] iwlwifi: mvm: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Kalle Valo 
Cc: Intel Linux Wireless 
Cc: Johannes Berg 
Cc: Emmanuel Grumbach 
Cc: linux-wirel...@vger.kernel.org
Cc: net...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c 
b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
index 0e6401c..e8249a6 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
@@ -671,14 +671,9 @@ static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, 
char __user *user_buf,
};
int ret, bt_force_ant_mode;
 
-   for (bt_force_ant_mode = 0;
-bt_force_ant_mode < ARRAY_SIZE(modes_str);
-bt_force_ant_mode++) {
-   if (!strcmp(buf, modes_str[bt_force_ant_mode]))
-   break;
-   }
-
-   if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
+   bt_force_ant_mode = match_string(modes_str,
+ARRAY_SIZE(modes_str), buf);
+   if (bt_force_ant_mode < 0)
return -EINVAL;
 
ret = 0;
-- 
1.7.12.4



[PATCH 01/33] usb: phy: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: linux-...@vger.kernel.org
Cc: Felipe Balbi <ba...@kernel.org>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
---
 drivers/usb/phy/of.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
index 1ab134f..5777c9f 100644
--- a/drivers/usb/phy/of.c
+++ b/drivers/usb/phy/of.c
@@ -28,16 +28,14 @@
 enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
 {
const char *phy_type;
-   int err, i;
+   int ret;
 
-   err = of_property_read_string(np, "phy_type", _type);
-   if (err < 0)
+   ret = of_property_read_string(np, "phy_type", _type);
+   if (ret < 0)
return USBPHY_INTERFACE_MODE_UNKNOWN;
 
-   for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
-   if (!strcmp(phy_type, usbphy_modes[i]))
-   return i;
+   ret = match_string(usbphy_modes, ARRAY_SIZE(usbphy_modes), phy_type);
 
-   return USBPHY_INTERFACE_MODE_UNKNOWN;
+   return (ret < 0) ? USBPHY_INTERFACE_MODE_UNKNOWN : ret;
 }
 EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
-- 
1.7.12.4



[PATCH 00/33] use match_string() helper

2018-05-21 Thread Yisheng Xie
Andy introduce helper function match_string() which can be used to return
the index of array for a matching string. so we can use it in many places
intead of open coded variant.

I just try to make this API be used more commonly, sorry if this makes
too much big patchset.

Yisheng Xie (33):
  usb: phy: use match_string() helper
  mfd: omap-usb-host: use match_string() helper
  Staging: gdm724x: use match_string() helper
  gpiolib-of: use match_string() helper
  cxgb4: use match_string() helper
  hp100: use match_string() helper
  iwlwifi: mvm: use match_string() helper
  vfio: use match_string() helper
  phy: tegra: use match_string() helper
  pata_hpt37x: use match_string() helper
  bus: fsl-mc: use match_string() helper
  clk: bcm2835: use match_string() helper
  clk: rockchip: use match_string() helper
  clk: use match_string() helper
  cpufreq: intel_pstate: use match_string() helper
  mmc: sdhci-xenon: use match_string() helper
  pinctrl: armada-37xx: use match_string() helper
  power: supply: use match_string() helper
  thermal: db8500: use match_string() helper
  video: fbdev: pxafb: use match_string() helper
  drm/nouveau: use match_string() helper
  drm/i915: use match_string() helper
  drm: i2c: ch7006: use match_string() helper
  drm: use match_string() helper
  ima: use match_string() helper
  apparmor: use match_string() helper
  sched/debug: use match_string() helper
  ALSA: dice use match_string() helper
  ALSA: oxfw: use match_string() helper
  ALSA: oxygen: use match_string() helper
  ASoC: max98088: use match_string() helper
  ASoC: max98095: use match_string() helper
  ASoC: dapm: use match_string() helper

 drivers/ata/pata_hpt37x.c| 13 +---
 drivers/bus/fsl-mc/fsl-mc-allocator.c| 24 +--
 drivers/clk/bcm/clk-bcm2835.c| 14 ++---
 drivers/clk/clk.c|  8 ++--
 drivers/clk/rockchip/clk.c   | 16 +--
 drivers/cpufreq/intel_pstate.c   | 15 ++
 drivers/gpio/gpiolib-of.c|  7 +--
 drivers/gpu/drm/drm_panel_orientation_quirks.c   |  7 ++-
 drivers/gpu/drm/i2c/ch7006_drv.c | 13 +---
 drivers/gpu/drm/i915/intel_pipe_crc.c| 22 ++---
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c| 13 +---
 drivers/mfd/omap-usb-host.c  | 24 ++-
 drivers/mmc/host/sdhci-xenon-phy.c   | 11 +++
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c   | 14 -
 drivers/net/ethernet/hp/hp100.c  |  9 +
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++
 drivers/phy/tegra/xusb.c | 15 +-
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c  | 16 ++-
 drivers/power/supply/power_supply_core.c | 16 ++-
 drivers/staging/gdm724x/gdm_tty.c| 16 ---
 drivers/thermal/db8500_thermal.c |  8 +++-
 drivers/usb/phy/of.c | 12 +---
 drivers/vfio/vfio.c  | 11 +++
 drivers/video/fbdev/pxafb.c  |  6 ++
 kernel/sched/debug.c | 20 +--
 security/apparmor/lsm.c  | 25 +++-
 security/integrity/ima/ima_main.c| 11 ---
 sound/firewire/dice/dice.c   |  8 +---
 sound/firewire/oxfw/oxfw.c   |  8 +---
 sound/pci/oxygen/oxygen_mixer.c  | 13 ++--
 sound/soc/codecs/max98088.c  |  9 +++--
 sound/soc/codecs/max98095.c  | 11 ---
 sound/soc/soc-dapm.c | 18 +++--
 33 files changed, 137 insertions(+), 307 deletions(-)

-- 
1.7.12.4



[PATCH 01/33] usb: phy: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: linux-...@vger.kernel.org
Cc: Felipe Balbi 
Cc: Greg Kroah-Hartman 
Signed-off-by: Yisheng Xie 
---
 drivers/usb/phy/of.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
index 1ab134f..5777c9f 100644
--- a/drivers/usb/phy/of.c
+++ b/drivers/usb/phy/of.c
@@ -28,16 +28,14 @@
 enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
 {
const char *phy_type;
-   int err, i;
+   int ret;
 
-   err = of_property_read_string(np, "phy_type", _type);
-   if (err < 0)
+   ret = of_property_read_string(np, "phy_type", _type);
+   if (ret < 0)
return USBPHY_INTERFACE_MODE_UNKNOWN;
 
-   for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
-   if (!strcmp(phy_type, usbphy_modes[i]))
-   return i;
+   ret = match_string(usbphy_modes, ARRAY_SIZE(usbphy_modes), phy_type);
 
-   return USBPHY_INTERFACE_MODE_UNKNOWN;
+   return (ret < 0) ? USBPHY_INTERFACE_MODE_UNKNOWN : ret;
 }
 EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
-- 
1.7.12.4



[PATCH 00/33] use match_string() helper

2018-05-21 Thread Yisheng Xie
Andy introduce helper function match_string() which can be used to return
the index of array for a matching string. so we can use it in many places
intead of open coded variant.

I just try to make this API be used more commonly, sorry if this makes
too much big patchset.

Yisheng Xie (33):
  usb: phy: use match_string() helper
  mfd: omap-usb-host: use match_string() helper
  Staging: gdm724x: use match_string() helper
  gpiolib-of: use match_string() helper
  cxgb4: use match_string() helper
  hp100: use match_string() helper
  iwlwifi: mvm: use match_string() helper
  vfio: use match_string() helper
  phy: tegra: use match_string() helper
  pata_hpt37x: use match_string() helper
  bus: fsl-mc: use match_string() helper
  clk: bcm2835: use match_string() helper
  clk: rockchip: use match_string() helper
  clk: use match_string() helper
  cpufreq: intel_pstate: use match_string() helper
  mmc: sdhci-xenon: use match_string() helper
  pinctrl: armada-37xx: use match_string() helper
  power: supply: use match_string() helper
  thermal: db8500: use match_string() helper
  video: fbdev: pxafb: use match_string() helper
  drm/nouveau: use match_string() helper
  drm/i915: use match_string() helper
  drm: i2c: ch7006: use match_string() helper
  drm: use match_string() helper
  ima: use match_string() helper
  apparmor: use match_string() helper
  sched/debug: use match_string() helper
  ALSA: dice use match_string() helper
  ALSA: oxfw: use match_string() helper
  ALSA: oxygen: use match_string() helper
  ASoC: max98088: use match_string() helper
  ASoC: max98095: use match_string() helper
  ASoC: dapm: use match_string() helper

 drivers/ata/pata_hpt37x.c| 13 +---
 drivers/bus/fsl-mc/fsl-mc-allocator.c| 24 +--
 drivers/clk/bcm/clk-bcm2835.c| 14 ++---
 drivers/clk/clk.c|  8 ++--
 drivers/clk/rockchip/clk.c   | 16 +--
 drivers/cpufreq/intel_pstate.c   | 15 ++
 drivers/gpio/gpiolib-of.c|  7 +--
 drivers/gpu/drm/drm_panel_orientation_quirks.c   |  7 ++-
 drivers/gpu/drm/i2c/ch7006_drv.c | 13 +---
 drivers/gpu/drm/i915/intel_pipe_crc.c| 22 ++---
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c| 13 +---
 drivers/mfd/omap-usb-host.c  | 24 ++-
 drivers/mmc/host/sdhci-xenon-phy.c   | 11 +++
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c   | 14 -
 drivers/net/ethernet/hp/hp100.c  |  9 +
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++
 drivers/phy/tegra/xusb.c | 15 +-
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c  | 16 ++-
 drivers/power/supply/power_supply_core.c | 16 ++-
 drivers/staging/gdm724x/gdm_tty.c| 16 ---
 drivers/thermal/db8500_thermal.c |  8 +++-
 drivers/usb/phy/of.c | 12 +---
 drivers/vfio/vfio.c  | 11 +++
 drivers/video/fbdev/pxafb.c  |  6 ++
 kernel/sched/debug.c | 20 +--
 security/apparmor/lsm.c  | 25 +++-
 security/integrity/ima/ima_main.c| 11 ---
 sound/firewire/dice/dice.c   |  8 +---
 sound/firewire/oxfw/oxfw.c   |  8 +---
 sound/pci/oxygen/oxygen_mixer.c  | 13 ++--
 sound/soc/codecs/max98088.c  |  9 +++--
 sound/soc/codecs/max98095.c  | 11 ---
 sound/soc/soc-dapm.c | 18 +++--
 33 files changed, 137 insertions(+), 307 deletions(-)

-- 
1.7.12.4



[PATCH 14/33] clk: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Michael Turquette <mturque...@baylibre.com>
Cc: Stephen Boyd <sb...@kernel.org>
Cc: linux-...@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
---
 drivers/clk/clk.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7af555f..4469eca 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2171,7 +2171,6 @@ void clk_hw_reparent(struct clk_hw *hw, struct clk_hw 
*new_parent)
 bool clk_has_parent(struct clk *clk, struct clk *parent)
 {
struct clk_core *core, *parent_core;
-   unsigned int i;
 
/* NULL clocks should be nops, so return success if either is NULL. */
if (!clk || !parent)
@@ -2184,11 +2183,8 @@ bool clk_has_parent(struct clk *clk, struct clk *parent)
if (core->parent == parent_core)
return true;
 
-   for (i = 0; i < core->num_parents; i++)
-   if (strcmp(core->parent_names[i], parent_core->name) == 0)
-   return true;
-
-   return false;
+   return match_string(core->parent_names,
+   core->num_parents, parent_core->name) >= 0;
 }
 EXPORT_SYMBOL_GPL(clk_has_parent);
 
-- 
1.7.12.4



[PATCH 14/33] clk: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Michael Turquette 
Cc: Stephen Boyd 
Cc: linux-...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
 drivers/clk/clk.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7af555f..4469eca 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2171,7 +2171,6 @@ void clk_hw_reparent(struct clk_hw *hw, struct clk_hw 
*new_parent)
 bool clk_has_parent(struct clk *clk, struct clk *parent)
 {
struct clk_core *core, *parent_core;
-   unsigned int i;
 
/* NULL clocks should be nops, so return success if either is NULL. */
if (!clk || !parent)
@@ -2184,11 +2183,8 @@ bool clk_has_parent(struct clk *clk, struct clk *parent)
if (core->parent == parent_core)
return true;
 
-   for (i = 0; i < core->num_parents; i++)
-   if (strcmp(core->parent_names[i], parent_core->name) == 0)
-   return true;
-
-   return false;
+   return match_string(core->parent_names,
+   core->num_parents, parent_core->name) >= 0;
 }
 EXPORT_SYMBOL_GPL(clk_has_parent);
 
-- 
1.7.12.4



[PATCH 16/33] mmc: sdhci-xenon: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Adrian Hunter <adrian.hun...@intel.com>
Cc: Hu Ziji <huz...@marvell.com>
Cc: Ulf Hansson <ulf.hans...@linaro.org>
Cc: linux-...@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
---
 drivers/mmc/host/sdhci-xenon-phy.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/mmc/host/sdhci-xenon-phy.c 
b/drivers/mmc/host/sdhci-xenon-phy.c
index ec87943..a35804b 100644
--- a/drivers/mmc/host/sdhci-xenon-phy.c
+++ b/drivers/mmc/host/sdhci-xenon-phy.c
@@ -814,15 +814,10 @@ static int xenon_add_phy(struct device_node *np, struct 
sdhci_host *host,
 {
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
-   int i, ret;
+   int ret;
 
-   for (i = 0; i < NR_PHY_TYPES; i++) {
-   if (!strcmp(phy_name, phy_types[i])) {
-   priv->phy_type = i;
-   break;
-   }
-   }
-   if (i == NR_PHY_TYPES) {
+   priv->phy_type = match_string(phy_types, NR_PHY_TYPES, phy_name);
+   if (priv->phy_type < 0) {
dev_err(mmc_dev(host->mmc),
"Unable to determine PHY name %s. Use default eMMC 5.1 
PHY\n",
phy_name);
-- 
1.7.12.4



[PATCH 11/33] bus: fsl-mc: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Stuart Yoder <stuyo...@gmail.com>
Cc: Laurentiu Tudor <laurentiu.tu...@nxp.com>
Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
---
 drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c 
b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index fb1442b..63c4735 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -156,22 +156,6 @@ static int __must_check 
fsl_mc_resource_pool_remove_device(struct fsl_mc_device
[FSL_MC_POOL_IRQ] = "irq",
 };
 
-static int __must_check object_type_to_pool_type(const char *object_type,
-enum fsl_mc_pool_type
-   *pool_type)
-{
-   unsigned int i;
-
-   for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) {
-   if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) {
-   *pool_type = i;
-   return 0;
-   }
-   }
-
-   return -EINVAL;
-}
-
 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
  enum fsl_mc_pool_type pool_type,
  struct fsl_mc_resource **new_resource)
@@ -581,9 +565,11 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device 
*mc_dev)
return -EINVAL;
 
mc_bus = to_fsl_mc_bus(mc_bus_dev);
-   error = object_type_to_pool_type(mc_dev->obj_desc.type, _type);
-   if (error < 0)
-   return error;
+   pool_type = match_string(fsl_mc_pool_type_strings,
+ARRAY_SIZE(fsl_mc_pool_type_strings),
+mc_dev->obj_desc.type);
+   if (pool_type < 0)
+   return pool_type;
 
error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev);
if (error < 0)
-- 
1.7.12.4



[PATCH 16/33] mmc: sdhci-xenon: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Adrian Hunter 
Cc: Hu Ziji 
Cc: Ulf Hansson 
Cc: linux-...@vger.kernel.org
Signed-off-by: Yisheng Xie 
---
 drivers/mmc/host/sdhci-xenon-phy.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/mmc/host/sdhci-xenon-phy.c 
b/drivers/mmc/host/sdhci-xenon-phy.c
index ec87943..a35804b 100644
--- a/drivers/mmc/host/sdhci-xenon-phy.c
+++ b/drivers/mmc/host/sdhci-xenon-phy.c
@@ -814,15 +814,10 @@ static int xenon_add_phy(struct device_node *np, struct 
sdhci_host *host,
 {
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
-   int i, ret;
+   int ret;
 
-   for (i = 0; i < NR_PHY_TYPES; i++) {
-   if (!strcmp(phy_name, phy_types[i])) {
-   priv->phy_type = i;
-   break;
-   }
-   }
-   if (i == NR_PHY_TYPES) {
+   priv->phy_type = match_string(phy_types, NR_PHY_TYPES, phy_name);
+   if (priv->phy_type < 0) {
dev_err(mmc_dev(host->mmc),
"Unable to determine PHY name %s. Use default eMMC 5.1 
PHY\n",
phy_name);
-- 
1.7.12.4



[PATCH 11/33] bus: fsl-mc: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Stuart Yoder 
Cc: Laurentiu Tudor 
Signed-off-by: Yisheng Xie 
---
 drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c 
b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index fb1442b..63c4735 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -156,22 +156,6 @@ static int __must_check 
fsl_mc_resource_pool_remove_device(struct fsl_mc_device
[FSL_MC_POOL_IRQ] = "irq",
 };
 
-static int __must_check object_type_to_pool_type(const char *object_type,
-enum fsl_mc_pool_type
-   *pool_type)
-{
-   unsigned int i;
-
-   for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) {
-   if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) {
-   *pool_type = i;
-   return 0;
-   }
-   }
-
-   return -EINVAL;
-}
-
 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
  enum fsl_mc_pool_type pool_type,
  struct fsl_mc_resource **new_resource)
@@ -581,9 +565,11 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device 
*mc_dev)
return -EINVAL;
 
mc_bus = to_fsl_mc_bus(mc_bus_dev);
-   error = object_type_to_pool_type(mc_dev->obj_desc.type, _type);
-   if (error < 0)
-   return error;
+   pool_type = match_string(fsl_mc_pool_type_strings,
+ARRAY_SIZE(fsl_mc_pool_type_strings),
+mc_dev->obj_desc.type);
+   if (pool_type < 0)
+   return pool_type;
 
error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev);
if (error < 0)
-- 
1.7.12.4



[PATCH 17/33] pinctrl: armada-37xx: use match_string() helper

2018-05-21 Thread Yisheng Xie
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Jason Cooper <ja...@lakedaemon.net>
Cc: Andrew Lunn <and...@lunn.ch>
Cc: Gregory Clement <gregory.clem...@bootlin.com>
Cc: Sebastian Hesselbarth <sebastian.hesselba...@gmail.com>
Cc: Linus Walleij <linus.wall...@linaro.org>
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-g...@vger.kernel.org
Signed-off-by: Yisheng Xie <xieyishe...@huawei.com>
---
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c 
b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index 5b63248..e338327 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -214,18 +214,6 @@ static inline void armada_37xx_update_reg(unsigned int 
*reg,
}
 }
 
-static int armada_37xx_get_func_reg(struct armada_37xx_pin_group *grp,
-   const char *func)
-{
-   int f;
-
-   for (f = 0; (f < NB_FUNCS) && grp->funcs[f]; f++)
-   if (!strcmp(grp->funcs[f], func))
-   return f;
-
-   return -ENOTSUPP;
-}
-
 static struct armada_37xx_pin_group *armada_37xx_find_next_grp_by_pin(
struct armada_37xx_pinctrl *info, int pin, int *grp)
 {
@@ -344,10 +332,10 @@ static int armada_37xx_pmx_set_by_name(struct pinctrl_dev 
*pctldev,
dev_dbg(info->dev, "enable function %s group %s\n",
name, grp->name);
 
-   func = armada_37xx_get_func_reg(grp, name);
+   func = match_string(grp->funcs, NB_FUNCS, name);
 
if (func < 0)
-   return func;
+   return -ENOTSUPP;
 
val = grp->val[func];
 
-- 
1.7.12.4



  1   2   3   4   5   6   7   8   9   >