linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ardelean, Alexandru" <alexandru.Ardelean@analog.com>
To: "andriy.shevchenko@linux.intel.com"  <andriy.shevchenko@linux.intel.com>
Cc: "keescook@chromium.org" <keescook@chromium.org>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"tobin@kernel.org" <tobin@kernel.org>
Subject: Re: [PATCH] lib/string: update match_string() doc-strings with correct behavior
Date: Thu, 13 Feb 2020 07:09:49 +0000	[thread overview]
Message-ID: <27677d8f08e1d9c1327b9771a9b93c99661ed2d0.camel@analog.com> (raw)
In-Reply-To: <20200212164627.GU10400@smile.fi.intel.com>

On Wed, 2020-02-12 at 18:46 +0200, Andy Shevchenko wrote:
> [External]
> 
> On Wed, Feb 12, 2020 at 04:47:23PM +0200, Alexandru Ardelean wrote:
> > There were a few attempts at changing behavior of the match_string()
> > helpers (i.e. 'match_string()' & 'sysfs_match_string()'), to change &
> > extend the behavior according to the doc-string.
> > 
> > But the simplest approach is to just fix the doc-strings. The current
> > behavior is fine as-is, and some bugs were introduced trying to fix it.
> > 
> > As for extending the behavior, new helpers can always be introduced if
> > needed.
> > 
> > The match_string() helpers behave more like 'strncmp()' in the sense that
> > they go up to n elements or until the first NULL element in the array of
> > strings.
> > 
> > This change updates the doc-strings with this info.
> > 
> > Some references to the previous attempts (in no particular order):
> >   
> > https://lore.kernel.org/lkml/20190508111913.7276-1-alexandru.ardelean@analog.com/
> >   
> > https://lore.kernel.org/lkml/20190625130104.29904-1-alexandru.ardelean@analog.com/
> >   
> > https://lore.kernel.org/lkml/20190422083257.21805-1-alexandru.ardelean@analog.com/
> 
> ...
> 
> >  /**
> >   * match_string - matches given string in an array
> >   * @array:	array of strings
> > - * @n:		number of strings in the array or -1 for NULL terminated
> > arrays
> > + * @n:		number of strings in the array to compare
> 
> But this change won't be helpful, it actually hides the part of behaviour that
> is being used.
> 
> >   * @string:	string to match with
> >   *
> > + * This routine will look for a string in an array of strings up to the
> > + * n-th element in the array or until the first NULL element.
> > + *
> 
> Perhaps this needs to be rephrased. Because now it has completely hidden the
> -1 case.

Hmm, it does make sense to specify the -1 behavior purely for historical
purposes.
Otheriwse, I don't feel it's that important to mention it, since you could
technically specify UINT_MAX [or similar] and get the same behavior.

> 
> >   * Return:
> >   * index of a @string in the @array if matches, or %-EINVAL otherwise.
> >   */
> 
> Ditto for the second part.
> 

  reply	other threads:[~2020-02-13  7:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12 14:47 [PATCH] lib/string: update match_string() doc-strings with correct behavior Alexandru Ardelean
2020-02-12 16:46 ` Andy Shevchenko
2020-02-13  7:09   ` Ardelean, Alexandru [this message]
2020-02-13  7:27 ` [PATCH v2] " Alexandru Ardelean
2020-02-13  9:36   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=27677d8f08e1d9c1327b9771a9b93c99661ed2d0.camel@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tobin@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).