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 21/21] sparc64: use match_string() helper

2018-06-04 Thread Andy Shevchenko
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 !=
 ...

-- 
With Best Regards,
Andy Shevchenko


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

2018-06-04 Thread Andy Shevchenko
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 !=
 ...

-- 
With Best Regards,
Andy Shevchenko


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 21/21] sparc64: use match_string() helper

2018-06-01 Thread Andy Shevchenko
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.

> -   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
>



-- 
With Best Regards,
Andy Shevchenko


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

2018-06-01 Thread Andy Shevchenko
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.

> -   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
>



-- 
With Best Regards,
Andy Shevchenko


[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