2018-05-16 09:26:29

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH] intel_th: pti: Convert to use sysfs_match_string() helper

The helper returns index of the matching string in an array,
use it to simpler the code.

Signed-off-by: Yisheng Xie <[email protected]>
---
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



2018-05-21 22:16:38

by Andy Shevchenko

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

On Wed, May 16, 2018 at 12:15 PM, Yisheng Xie <[email protected]> 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.

>
> Signed-off-by: Yisheng Xie <[email protected]>
> ---
> 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
>



--
With Best Regards,
Andy Shevchenko

2018-05-22 00:50:23

by Yisheng Xie

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

Hi Andy,

On 2018/5/22 6:16, Andy Shevchenko wrote:
> On Wed, May 16, 2018 at 12:15 PM, Yisheng Xie <[email protected]> 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 <[email protected]>
>> ---
>> 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
>>
>
>
>