Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1323860
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v4 1/9] lib/string: introduce match_string() helper |
| Date | 2016-02-02 09:00 +0100 |
| Message-ID | <qXE2u-7EE-7@gated-at.bofh.it> (permalink) |
| References | <qVUEp-3UD-5@gated-at.bofh.it> <qVUEr-3UD-51@gated-at.bofh.it> <qXCk1-6AZ-9@gated-at.bofh.it> |
| Organization | Intel Finland Oy |
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@linux.intel.com>
Intel Finland Oy
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v4 0/9] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-28 14:20 +0100
[PATCH v4 4/9] drm/edid: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-28 14:20 +0100
[PATCH v4 3/9] pinctrl: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-28 14:20 +0100
Re: [PATCH v4 3/9] pinctrl: convert to use match_string() helper Andrew Morton <akpm@linux-foundation.org> - 2016-02-02 07:10 +0100
Re: [PATCH v4 3/9] pinctrl: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-02-02 09:20 +0100
[PATCH v4 8/9] ide: hpt366: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-28 14:20 +0100
[PATCH v4 5/9] power: charger_manager: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-28 14:20 +0100
[PATCH v4 6/9] power: ab8500: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-28 14:20 +0100
[PATCH v4 1/9] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-28 14:20 +0100
Re: [PATCH v4 1/9] lib/string: introduce match_string() helper Andrew Morton <akpm@linux-foundation.org> - 2016-02-02 07:10 +0100
Re: [PATCH v4 1/9] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-02-02 09:00 +0100
Re: [PATCH v4 1/9] lib/string: introduce match_string() helper Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-02-02 21:00 +0100
[PATCH v4 7/9] ata: hpt366: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-28 14:20 +0100
csiph-web