From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750994AbcGEW40 (ORCPT ); Tue, 5 Jul 2016 18:56:26 -0400 Received: from smtprelay0237.hostedemail.com ([216.40.44.237]:44570 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751095AbcGEW4W (ORCPT ); Tue, 5 Jul 2016 18:56:22 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6119:6742:7875:7903:10004:10400:10848:11232:11658:11783:11914:12517:12519:12663:12740:13161:13229:13439:13894:14181:14659:14721:21080:21324:21433:21434:30012:30054:30064:30070:30079:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: word01_3711662eb6119 X-Filterd-Recvd-Size: 4038 Message-ID: <1467759377.8360.12.camel@perches.com> Subject: Re: [PATCH v2 0/7] lib: string: add functions to case-convert strings From: Joe Perches To: Markus Mayer Cc: Andrew Morton , Al Viro , Rasmus Villemoes , Chris Metcalf , Kees Cook , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-acpi@vger.kernel.org, speakup@linux-speakup.org, devel@driverdev.osuosl.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-pm@vger.kernel.org, Linux Kernel Date: Tue, 05 Jul 2016 15:56:17 -0700 In-Reply-To: References: <1467751631-22878-1-git-send-email-mmayer@broadcom.com> <1467756874.16342.11.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2016-07-05 at 15:36 -0700, Markus Mayer wrote: > On 5 July 2016 at 15:14, Joe Perches wrote: > > On Tue, 2016-07-05 at 13:47 -0700, Markus Mayer wrote: > > > This series introduces a family of generic string case conversion > > > functions. This kind of functionality is needed in several places in > > > the kernel. Right now, everybody seems to be implementing their own > > > copy of this functionality. > > > > > > Based on the discussion of the previous version of this series[1] and > > > the use cases found in the kernel, it does look like having several > > > flavours of case conversion functions is beneficial. The use cases fall > > > into three categories: > > >     - copying a string and converting the case while specifying a > > >       maximum length to mimic strncpy() > > >     - copying a string and converting the case without specifying a > > >       length to mimic strcpy() > > >     - converting the case of a string in-place (i.e. modifying the > > >       string that was passed in) > > > > > > Consequently, I am proposing these new functions: > > >     char *strncpytoupper(char *dst, const char *src, size_t len); > > >     char *strncpytolower(char *dst, const char *src, size_t len); > > >     char *strcpytoupper(char *dst, const char *src); > > >     char *strcpytolower(char *dst, const char *src); > > >     char *strtoupper(char *s); > > >     char *strtolower(char *s); > > I think there isn't much value in anything other > > than strto. > > > > Using str[n]cpy followed by strto is > > pretty obvious and rarely used anyway. > First time around, folks were proposing the "copy" variants when I > submitted just strtolower() by itself[1]. They just asked for source > and destination parameters to strtolower(), but looking at the use > cases that wouldn't have worked so well. Hence it evolved into these 6 > functions. > > Here's a breakdown of how the functions are being used (patches 2-7), > see also [2]: > > Patch 2: strncpytolower() > Patch 3: strtolower() > Patch 4: strncpytolower() and strtolower() > Patch 5: strtolower() > Patch 6: strcpytoupper() > Patch 7: strcpytoupper() > > So it does look like the copy + change case variant is more frequently > used than just strto. Are these functions useful?   Not to me, not so much. None of the functions would have the strcpy performance of the arch / asm versions of strcpy and the savings in overall code isn't significant (or measured?). Of course none of the uses are runtime performance important. This patch also adds always compiled functions that aren't used in many .configs.