From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753100AbbFHQDn (ORCPT ); Mon, 8 Jun 2015 12:03:43 -0400 Received: from smtprelay0020.hostedemail.com ([216.40.44.20]:58561 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751746AbbFHQDe (ORCPT ); Mon, 8 Jun 2015 12:03:34 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:1801:2197:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3355:3653:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:4605:5007:6117:6119:6261:7875:7903:8660:9040:9121:10004:10400:10848:10967:11026:11232:11473:11658:11914:12296:12517:12519:12555:12663:12740:13148:13184:13229:13230:21080,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 X-HE-Tag: cake91_3bf2d534b7c4a X-Filterd-Recvd-Size: 4077 Date: Mon, 8 Jun 2015 12:03:30 -0400 From: Steven Rostedt To: Rasmus Villemoes Cc: Andrew Morton , Ingo Molnar , linux-kernel@vger.kernel.org, Jens Axboe Subject: Re: [RFC/PATCH 3/8] blktrace: use strreplace in do_blk_trace_setup Message-ID: <20150608120330.4ecb73b7@gandalf.local.home> In-Reply-To: <1433410636-26812-4-git-send-email-linux@rasmusvillemoes.dk> References: <1433410636-26812-1-git-send-email-linux@rasmusvillemoes.dk> <1433410636-26812-4-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org blktrace is maintained by Jens Axboe (added to the Cc), although I also maintain it for cleanups such as this. That's the reason it doesn't have a "trace_" in its name like the other files do (a bit of trivia for you ;-) kernel/trace/blktrace.c should probably be included in the MAINTAINERS file under BLOCK LAYER. On Thu, 4 Jun 2015 11:37:10 +0200 Rasmus Villemoes wrote: > Part of the disassembly of do_blk_trace_setup: > > 231b: e8 00 00 00 00 callq 2320 > 231c: R_X86_64_PC32 strlen+0xfffffffffffffffc > 2320: eb 0a jmp 232c > 2322: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) > 2328: 48 83 c3 01 add $0x1,%rbx > 232c: 48 39 d8 cmp %rbx,%rax > 232f: 76 47 jbe 2378 > 2331: 41 80 3c 1c 2f cmpb $0x2f,(%r12,%rbx,1) > 2336: 75 f0 jne 2328 > 2338: 41 c6 04 1c 5f movb $0x5f,(%r12,%rbx,1) > 233d: 4c 89 e7 mov %r12,%rdi > 2340: e8 00 00 00 00 callq 2345 > 2341: R_X86_64_PC32 strlen+0xfffffffffffffffc > 2345: eb e1 jmp 2328 > > Yep, that's right: gcc isn't smart enough to realize that replacing > '/' by '_' cannot change the strlen(), so we call it again and again > (at least when a '/' is found). Even if gcc were that smart, this > construction would still loop over the string twice, once for the > initial strlen() call and then the open-coded loop. > > Let's simply use strreplace() instead. > > Signed-off-by: Rasmus Villemoes > --- > kernel/trace/blktrace.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c > index 483cecfa5c17..4eeae4674b5a 100644 > --- a/kernel/trace/blktrace.c > +++ b/kernel/trace/blktrace.c > @@ -439,7 +439,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, > { > struct blk_trace *old_bt, *bt = NULL; > struct dentry *dir = NULL; > - int ret, i; > + int ret; > > if (!buts->buf_size || !buts->buf_nr) > return -EINVAL; > @@ -451,9 +451,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, > * some device names have larger paths - convert the slashes > * to underscores for this to work as expected > */ > - for (i = 0; i < strlen(buts->name); i++) Wow! I'm surprised this wasn't: for (i = 0; buts->name[i]; i++) > - if (buts->name[i] == '/') > - buts->name[i] = '_'; > + strreplace(buts->name, '/', '_'); > > bt = kzalloc(sizeof(*bt), GFP_KERNEL); > if (!bt) Acked-by: Steven Rostedt -- Steve