From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757753AbcBBTuI (ORCPT ); Tue, 2 Feb 2016 14:50:08 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:33967 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757740AbcBBTuG (ORCPT ); Tue, 2 Feb 2016 14:50:06 -0500 From: Rasmus Villemoes To: Andrew Morton Cc: Andy Shevchenko , Tejun Heo , Linus Walleij , Dmitry Eremin-Solenikov , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, "David S . Miller" , David Airlie Subject: Re: [PATCH v4 1/9] lib/string: introduce match_string() helper Organization: D03 References: <1453986865-133572-1-git-send-email-andriy.shevchenko@linux.intel.com> <1453986865-133572-2-git-send-email-andriy.shevchenko@linux.intel.com> <20160201220538.481cb8ee.akpm@linux-foundation.org> X-Hashcash: 1:20:160202:andriy.shevchenko@linux.intel.com::9Y23RgAe4Z6bvT0L:00000000000000000000000000000d9t X-Hashcash: 1:20:160202:linux-kernel@vger.kernel.org::R/ZkyN/12jOIWFuh:0000000000000000000000000000000000zeN X-Hashcash: 1:20:160202:linus.walleij@linaro.org::780iHxnVfyzCbFjs:00000000000000000000000000000000000002QQN X-Hashcash: 1:20:160202:linux-pm@vger.kernel.org::+1HNYGnbB9DIsir5:00000000000000000000000000000000000002fHE X-Hashcash: 1:20:160202:tj@kernel.org::2FS4VyoO26sMIL8u:000035Hh X-Hashcash: 1:20:160202:dbaryshkov@gmail.com::QFF04W+72pxrfyVo:000000000000000000000000000000000000000004T9O X-Hashcash: 1:20:160202:davem@davemloft.net::q4E8Y6NtwwKRjsuS:0000000000000000000000000000000000000000005Z5D X-Hashcash: 1:20:160202:airlied@linux.ie::hER0X+6wz8MFCBRY:08IBp X-Hashcash: 1:20:160202:akpm@linux-foundation.org::2J+cHLdoAEhPsE6u:000000000000000000000000000000000000Bcm+ Date: Tue, 02 Feb 2016 20:50:02 +0100 In-Reply-To: <20160201220538.481cb8ee.akpm@linux-foundation.org> (Andrew Morton's message of "Mon, 1 Feb 2016 22:05:38 -0800") Message-ID: <87a8nizyc5.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 02 2016, Andrew Morton wrote: > On Thu, 28 Jan 2016 15:14:17 +0200 Andy Shevchenko 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. n has unsigned type to make it easy to pass 'infinity'; *that's* where we rely on integer promotion. One could make index be unsigned int (or size_t), but it won't matter, because it will never have a value where the type promotion (nor the implicit cast back to int if/when it's used as a return value) changes its value. Rasmus