From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Tejun Heo <tj@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
David Airlie <airlied@linux.ie>,
Andrew Morton <akpm@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [PATCH v1 1/8] lib/string: introduce match_string() helper
Date: Mon, 11 Jan 2016 17:00:00 +0200 [thread overview]
Message-ID: <1452524400.26146.32.camel@linux.intel.com> (raw)
In-Reply-To: <CAHp75Vf_dESyzvi5EN5KP8OCKtqKoD8YK7w5s0yHpBgt=-q7Uw@mail.gmail.com>
On Sat, 2016-01-09 at 13:57 +0200, Andy Shevchenko wrote:
> On Sat, Jan 9, 2016 at 3:12 AM, Sergey Senozhatsky
> <sergey.senozhatsky@gmail.com> wrote:
> > Andy Shevchenko wrote:
> > [..]
> > > >
> > > > strncmp() case seems to be quite common.
> > >
> > > Like I answered to Rasmus, please, provide real examples.
> >
> > [..]
> > > > int nmatch_string(array, array_size, string, string_len)
> > > > {
> > > > do {
> > > > strncmp();
> > > > } while ();
> > > > }
> > > >
> > > > int match_string(array, array_size, string)
> > > > {
> > > > return nmatch_string(array, array_size, string,
> > > > strlen(string));
> > > > }
> > >
> > > See above.
> >
> > after some quick and inaccurate grepping, well, probably you're
> > right - not worth it.
>
> Good grep anyway, it clearly shows that there is hard to generalize
> which limit to use: a) length of a first argument / item from a list,
> b) length of a second argument or a constant.
>
> > arch/mips/bcm63xx/boards/board_bcm963xx.c void __init
> > board_prom_init(void)
> > net/irda/irnet/irnet_irda.c irnet_dname_to_daddr()
> > arch/powerpc/sysdev/ppc4xx_cpm.c static ssize_t cpm_idle_store()
> > arch/x86/ras/mce_amd_inj.c static int __set_inj
> > drivers/hwtracing/intel_th/msu.c mode_store
> > drivers/pci/pcie/aer/ecrc.c void pcie_ecrc_get_policy
> > drivers/pci/pcie/aspm.c pcie_aspm_set_policy
> > drivers/scsi/aic7xxx/aic7xxx_osm.c aic7xxx_setup
> > drivers/scsi/aic7xxx/aic79xx_osm.c aic79xx_setup
> > drivers/scsi/scsi_transport_fc.c static int get_fc_##title##_match
> > drivers/staging/android/ion/hisilicon/hi6220_ion.c get_type_by_name
> > drivers/staging/lustre/lustre/lmv/lproc_lmv.c placement_name2policy
> > drivers/xen/sys-hypervisor.c pmu_mode_store
Thought more about those cases.
If you would like you may introduce something like
int nmatch_string(array, array_size, string, int len)
{
if (len < 0)
return match_string();
for (…) {
size_t itemlen = (len > 0) ? len : strlen(array[index]);
…
if (!strncmp(array[index], string, itemlen))
return index;
}
return -EINVAL;
}
And convert existing users where it makes sense.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
next prev parent reply other threads:[~2016-01-11 14:59 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-07 12:06 [PATCH v1 1/8] lib/string: introduce match_string() helper Andy Shevchenko
2016-01-07 12:06 ` [PATCH v1 2/8] device property: convert to use " Andy Shevchenko
2016-01-08 13:01 ` Mika Westerberg
2016-01-07 12:06 ` [PATCH v1 3/8] pinctrl: " Andy Shevchenko
2016-01-07 15:19 ` Linus Walleij
2016-01-07 12:06 ` [PATCH v1 4/8] drm/edid: " Andy Shevchenko
2016-01-07 12:06 ` [PATCH v1 5/8] power: charger_manager: " Andy Shevchenko
2016-01-07 12:06 ` [PATCH v1 6/8] power: ab8500: " Andy Shevchenko
2016-01-07 15:19 ` Linus Walleij
2016-01-07 12:06 ` [PATCH v1 7/8] ata: hpt366: " Andy Shevchenko
2016-01-07 15:44 ` Tejun Heo
2016-01-07 12:06 ` [PATCH v1 8/8] ide: " Andy Shevchenko
2016-01-07 13:07 ` [PATCH v1 1/8] lib/string: introduce " Heikki Krogerus
2016-01-07 13:12 ` Andy Shevchenko
2016-01-07 13:24 ` Heikki Krogerus
2016-01-07 22:05 ` Rasmus Villemoes
2016-01-08 8:40 ` Andy Shevchenko
2016-01-08 0:13 ` Sergey Senozhatsky
2016-01-08 8:43 ` Andy Shevchenko
2016-01-09 1:12 ` Sergey Senozhatsky
2016-01-09 11:57 ` Andy Shevchenko
2016-01-11 15:00 ` Andy Shevchenko [this message]
2016-01-11 22:10 ` Rasmus Villemoes
2016-01-11 22:24 ` Andy Shevchenko
2016-01-12 8:26 ` Sergey Senozhatsky
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=1452524400.26146.32.camel@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=airlied@linux.ie \
--cc=akpm@linux-foundation.org \
--cc=andy.shevchenko@gmail.com \
--cc=davem@davemloft.net \
--cc=dbaryshkov@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=tj@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).