linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3][V3] lib: fix __sysfs_match_string() helper when n != -1
@ 2019-05-08 11:19 Alexandru Ardelean
  2019-05-08 11:19 ` [PATCH 2/3][V3] scsi: sd: remove sysfs_match_string() dense array comment Alexandru Ardelean
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Alexandru Ardelean @ 2019-05-08 11:19 UTC (permalink / raw)
  To: linux-kernel, linux-iio, linux-scsi
  Cc: gregkh, andriy.shevchenko, jic23, lars, Alexandru Ardelean

The documentation the `__sysfs_match_string()` helper mentions that `n`
(the size of the given array) should be:
 * @n: number of strings in the array or -1 for NULL terminated arrays

The behavior of the function is different, in the sense that it exits on
the first NULL element in the array.

This patch changes the behavior, to exit the loop when a NULL element is
found, and the size of the array is provided as -1.

All current users of __sysfs_match_string() & sysfs_match_string() provide
contiguous arrays of strings, so this behavior change doesn't influence
anything (at this point in time).

This behavior change allows for an array of strings to have NULL elements
within the array, which will be ignored. This is particularly useful when
creating mapping of strings and integers (as bitfields or other HW
description).

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---

Changelog v2 -> v3:
* fix __sysfs_match_string() vs adding a new
  __sysfs_match_string_with_gaps() helper

 lib/string.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/string.c b/lib/string.c
index 3ab861c1a857..5bea3f98478a 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -674,8 +674,11 @@ int __sysfs_match_string(const char * const *array, size_t n, const char *str)
 
 	for (index = 0; index < n; index++) {
 		item = array[index];
-		if (!item)
+		if (!item) {
+			if (n != (size_t)-1)
+				continue;
 			break;
+		}
 		if (sysfs_streq(item, str))
 			return index;
 	}
-- 
2.17.1


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

end of thread, other threads:[~2019-07-14 10:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 11:19 [PATCH 1/3][V3] lib: fix __sysfs_match_string() helper when n != -1 Alexandru Ardelean
2019-05-08 11:19 ` [PATCH 2/3][V3] scsi: sd: remove sysfs_match_string() dense array comment Alexandru Ardelean
2019-05-08 11:19 ` [PATCH 3/3][V3] iio: Handle enumerated properties with gaps Alexandru Ardelean
2019-05-08 13:17   ` Andy Shevchenko
2019-05-09  7:31     ` Ardelean, Alexandru
2019-07-05 13:35       ` Ardelean, Alexandru
2019-05-28  7:18 ` [PATCH 1/3][V3] lib: fix __sysfs_match_string() helper when n != -1 Ardelean, Alexandru
2019-07-14 10:12 ` 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).