Re: [PATCH v7 1/2] lib/string.c: add __sysfs_match_string_with_gaps() helper

From: Andy Shevchenko
Date: Thu Jan 07 2021 - 05:09:50 EST


On Thu, Jan 7, 2021 at 10:41 AM Alexandru Ardelean
<alexandru.ardelean@xxxxxxxxxx> wrote:
>
> The original docstring of the __sysfs_match_string() and match_string()
> helper, implied that -1 could be used to search through NULL terminated
> arrays, and positive 'n' could be used to go through arrays that may have
> NULL elements in the middle of the array.
>
> This isn't true. Regardless of the value of 'n', the first NULL element in
> the array will stop the search, even if the element may be after a NULL
> element.
>
> To allow for a behavior where we can use the __sysfs_match_string() to
> search over arrays with NULL elements in the middle, the
> __sysfs_match_string_with_gaps() helper is added.
> If n > 0, the search will continue until the element is found or n is
> reached.

...

> If n < 0, the search will continue until the element is found or a NULL
> character is found.

And this is what I think is not needed.

...

> FWIW (from my side): I am not fully sure yet that implementing a
> new helper is the best idea. It's also not a bad idea.
> It's one of those "this could be useful for others as well later", but
> right now we would have only one user (IIO) for this.

Taking into account the failure of bitmap_set_clump() promotion, I
suggest to reduce scope to IIO for now.

> I'm also fine with just implementing it in IIO first, and the someone
> else can move it to lib/string.c if needed.

Yes, please do.

...

> + * If n < 0, then the search will continue until the element is found or
> + * until the first NULL element.

...

> + if (n < 0)
> + break;

And drop these.

--
With Best Regards,
Andy Shevchenko