Skip to contentSkip to conversation

iio: core: Use __sysfs_match_string() helper

PATCH In review Andy Shevchenko 2 participants 3 messages Jun 9, 2017 – Jun 13, 2017 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: core: Use __sysfs_match_string() helper

Use __sysfs_match_string() helper instead of open coded variant.

Cc Jonathan Cameron <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
---
 drivers/iio/industrialio-core.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/iio/industrialio-core.c +4 -9
index 4a1de59d153a..15c86a8cd704 100644
@@ -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);
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 5 lines · On Fri, 9 Jun 2017 15:08:16 +0300 Andy Shevchenko…

Use __sysfs_match_string() helper instead of open coded variant.

Cc Jonathan Cameron <[email protected]>
Cc Lars-Peter Clausen <[email protected]>

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

Quoted 34 lines
---
 drivers/iio/industrialio-core.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/iio/industrialio-core.c +4 -9
index 4a1de59d153a..15c86a8cd704 100644
@@ -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);
maintainer
#2 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · On Fri, 9 Jun 2017 15:08:16 +0300 Andy Shevchenko…

Use __sysfs_match_string() helper instead of open coded variant.

Cc Jonathan Cameron <[email protected]>
Cc Lars-Peter Clausen <[email protected]>

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

Quoted 34 lines
---
 drivers/iio/industrialio-core.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/iio/industrialio-core.c +4 -9
index 4a1de59d153a..15c86a8cd704 100644
@@ -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);