[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 02 Feb 2016 10:00:21 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Tejun Heo <tj@...nel.org>,
Linus Walleij <linus.walleij@...aro.org>,
Dmitry Eremin-Solenikov <dbaryshkov@...il.com>,
linux-kernel@...r.kernel.org, linux-pm@...r.kernel.org,
"David S . Miller" <davem@...emloft.net>,
David Airlie <airlied@...ux.ie>,
Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: Re: [PATCH v4 1/9] lib/string: introduce match_string() helper
On Mon, 2016-02-01 at 22:05 -0800, Andrew Morton wrote:
> On Thu, 28 Jan 2016 15:14:17 +0200 Andy Shevchenko <andriy.shevchenko
> @linux.intel.com> wrote:
> > + * @array: array of strings
> > + * @n: number of strings in the array or -1 for
> > NULL terminated arrays
> > + * @string: string to match with
> > + *
> > + * Return:
> > + * index of a @string in the @array if matches, or %-ENODATA
> > otherwise.
> > + */
> > +int match_string(const char * const *array, size_t n, const char
> > *string)
> > +{
> > + int index;
> > + const char *item;
> > +
> > + for (index = 0; index < n; index++) {
>
> So we're taking an int and comparing that with (size_t)-1, relying
> upon
> the compiler promoting the int to an unsigned type because size_t is
> unsigned. It works, but it isn't pretty - there wasn't really much
> point in making size have type size_t.
It was Rasmus' idea [1], before that I used int and tristate branch. I
agreed that one of that branches wasn't a good idea, but the rest was
exactly about differentiating size to compare and infinite (till
terminator) loop.
[1] http://www.spinics.net/lists/kernel/msg2156925.html
>
>
> > + item = array[index];
> > + if (!item)
> > + break;
> > + if (!strcmp(item, string))
> > + return index;
> > + }
> > +
> > + return -ENODATA;
> > +}
> > +EXPORT_SYMBOL(match_string);
>
--
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Intel Finland Oy
Powered by blists - more mailing lists