linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] iio: core: Use __sysfs_match_string() helper
@ 2017-06-09 12:08 Andy Shevchenko
  2017-06-11 10:52 ` Jonathan Cameron
  2017-06-11 11:00 ` Jonathan Cameron
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2017-06-09 12:08 UTC (permalink / raw)
  To: linux-iio; +Cc: Andy Shevchenko, Jonathan Cameron, Lars-Peter Clausen

Use __sysfs_match_string() helper instead of open coded variant.

Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/industrialio-core.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 4a1de59d153a..15c86a8cd704 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -478,21 +478,16 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
 	size_t len)
 {
 	const struct iio_enum *e = (const struct iio_enum *)priv;
-	unsigned int i;
 	int ret;
 
 	if (!e->set)
 		return -EINVAL;
 
-	for (i = 0; i < e->num_items; i++) {
-		if (sysfs_streq(buf, e->items[i]))
-			break;
-	}
-
-	if (i == e->num_items)
-		return -EINVAL;
+	ret = __sysfs_match_string(e->items, e->num_items, buf);
+	if (ret < 0)
+		return ret;
 
-	ret = e->set(indio_dev, chan, i);
+	ret = e->set(indio_dev, chan, ret);
 	return ret ? ret : len;
 }
 EXPORT_SYMBOL_GPL(iio_enum_write);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] iio: core: Use __sysfs_match_string() helper
  2017-06-09 12:08 [PATCH v1] iio: core: Use __sysfs_match_string() helper Andy Shevchenko
@ 2017-06-11 10:52 ` Jonathan Cameron
  2017-06-11 11:00 ` Jonathan Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2017-06-11 10:52 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-iio, Lars-Peter Clausen

On Fri,  9 Jun 2017 15:08:16 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Use __sysfs_match_string() helper instead of open coded variant.
> 
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

A nice little tidy up.  I'd missed that function being added.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with.

Jonathan
> ---
>  drivers/iio/industrialio-core.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 4a1de59d153a..15c86a8cd704 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -478,21 +478,16 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
>  	size_t len)
>  {
>  	const struct iio_enum *e = (const struct iio_enum *)priv;
> -	unsigned int i;
>  	int ret;
>  
>  	if (!e->set)
>  		return -EINVAL;
>  
> -	for (i = 0; i < e->num_items; i++) {
> -		if (sysfs_streq(buf, e->items[i]))
> -			break;
> -	}
> -
> -	if (i == e->num_items)
> -		return -EINVAL;
> +	ret = __sysfs_match_string(e->items, e->num_items, buf);
> +	if (ret < 0)
> +		return ret;
>  
> -	ret = e->set(indio_dev, chan, i);
> +	ret = e->set(indio_dev, chan, ret);
>  	return ret ? ret : len;
>  }
>  EXPORT_SYMBOL_GPL(iio_enum_write);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] iio: core: Use __sysfs_match_string() helper
  2017-06-09 12:08 [PATCH v1] iio: core: Use __sysfs_match_string() helper Andy Shevchenko
  2017-06-11 10:52 ` Jonathan Cameron
@ 2017-06-11 11:00 ` Jonathan Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2017-06-11 11:00 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-iio, Lars-Peter Clausen

On Fri,  9 Jun 2017 15:08:16 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Use __sysfs_match_string() helper instead of open coded variant.
> 
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Hmm. I'm sure I replied to this but it seems to have gone astray.
Anyhow, applied to the togreg branch of iio.git and pushed out as
testing for the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/industrialio-core.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 4a1de59d153a..15c86a8cd704 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -478,21 +478,16 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
>  	size_t len)
>  {
>  	const struct iio_enum *e = (const struct iio_enum *)priv;
> -	unsigned int i;
>  	int ret;
>  
>  	if (!e->set)
>  		return -EINVAL;
>  
> -	for (i = 0; i < e->num_items; i++) {
> -		if (sysfs_streq(buf, e->items[i]))
> -			break;
> -	}
> -
> -	if (i == e->num_items)
> -		return -EINVAL;
> +	ret = __sysfs_match_string(e->items, e->num_items, buf);
> +	if (ret < 0)
> +		return ret;
>  
> -	ret = e->set(indio_dev, chan, i);
> +	ret = e->set(indio_dev, chan, ret);
>  	return ret ? ret : len;
>  }
>  EXPORT_SYMBOL_GPL(iio_enum_write);


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-13 18:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-09 12:08 [PATCH v1] iio: core: Use __sysfs_match_string() helper Andy Shevchenko
2017-06-11 10:52 ` Jonathan Cameron
2017-06-11 11:00 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).