Message ID | 20230628153342.53406-1-andriy.shevchenko@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9018110vqr; Wed, 28 Jun 2023 08:37:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76c1nYvM9FqEiBqsWMvJ+y/vSVwVXmfPVziFz9kSJCNiFFwQAPu6M+J3Q2zEsEzAD9AM5C X-Received: by 2002:a2e:990a:0:b0:2b5:8bb9:4dd6 with SMTP id v10-20020a2e990a000000b002b58bb94dd6mr14503165lji.12.1687966673273; Wed, 28 Jun 2023 08:37:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687966673; cv=none; d=google.com; s=arc-20160816; b=i0U0TvMHqlr0hqH0QuHr/C9KnKA6Pstutk5aMzUx/hlCfTQabZ8LLb2zpE77wcE/n5 p2Ox5D/QxfCjjzbiulMNiuvGzaq1+HP5LIkTRmsyupG2KOleTNcoh04MGf1hgaAjz5om mBUkE0qJDfbWVcC3MeJULSHYXJ89vkeAKtLgYrjWKHrpRTFkXgY81sxNWEbD6ciwaYTU 1ECYc/4YviOf9csMz30fL/4VJksPJXGTkNMzCn00bmmbZr19ww7dk6ZwEmcPI4Qhmi/f Mq05YLrrKe1EvfjZXkv0IHghbobzIG9NXZn+WWihuEB25HAlcJ3IW0SsDw3PCN6WQrrW vhRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QUot3id03Fi4Q0nI8wc0vO323eixpfAxso0J0rUzMvU=; fh=YEBSwHLBxseWd1htZdUMtd2T+IT5f789+YFsDanJEZY=; b=z+L1tk18aCGdbJ/jBfOFngTBoiZmZYeZRE3jqmKhe5Hmo2GofQz9CM0G9jsMG6WteQ mcQArl20bt5bU64IA2epl2dS1/yozH0EwsFaJeuBhTwBgrODrahlo/hTHlOJcNo1B4GZ 9J+bWOVtqhCpXnsTbkby3tZoSImww3sfJv/WLUftxmytp0CIvMcb39YTtuIr2MYZb5NL +lYyj9ZBpNBR9BRmA1/G3ArpmCkenUNqg/ZgsmBQypGKo3Fap/OTk50B+oJh1lRiCyxn LEWM3I3P+MopJYlwni4cThmNUw0pNZodFeGXSdSF6NRaWvsTiG9vg/2Q+XnRRVp0IMUR qaHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NSAl2M3Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm6-20020a170906c04600b00982a36463c9si5772348ejb.518.2023.06.28.08.37.28; Wed, 28 Jun 2023 08:37:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NSAl2M3Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232662AbjF1Pfa (ORCPT <rfc822;adanhawthorn@gmail.com> + 99 others); Wed, 28 Jun 2023 11:35:30 -0400 Received: from mga09.intel.com ([134.134.136.24]:20036 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232553AbjF1PeV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 28 Jun 2023 11:34:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687966461; x=1719502461; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=UM29w6YmyINBXCk6A+fAcfZ7rP6qST6yVT5akSdbQhM=; b=NSAl2M3Qb7rt9maR/OndmlJiJtvLSUjGJRAKOR45dstxFoaY0psrg0p8 6y1td1N3yEAjfrvrSh/WNQz6bU2p/3keXXnPBrj+NnVHkx5yBTsYaD/bB CRfg3+4KIrOWWIs+LAhmuU8qzIQ/m6+qPEH0cl2Iqj32LXnh7g98t9oc+ We1mga/xAsbx6NyNR9upN2QuNt78EtfO5tHI6kKGJtsrXWhl2llVPNGQJ wY8KURaXyV8A2mpu+gct9Fy60ueF6uXZZ6GRPpREn5Cl+eTXL9eJ9f3Bc bkDwjukQq+IJtEpyTZu2FMeGJJNPFbni9OtHU5X+bfFusI6zvpXLgGwGI w==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="364427621" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="364427621" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 08:33:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="782344837" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="782344837" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 28 Jun 2023 08:33:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4BDDDE1; Wed, 28 Jun 2023 18:33:48 +0300 (EEST) From: Andy Shevchenko <andriy.shevchenko@linux.intel.com> To: Andrew Morton <akpm@linux-foundation.org>, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>, Alexander Potapenko <glider@google.com>, Andrey Konovalov <andreyknvl@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, Andy Shevchenko <andriy.shevchenko@linux.intel.com> Subject: [PATCH v1 1/1] kasan: Replace strreplace() with strchrnul() Date: Wed, 28 Jun 2023 18:33:42 +0300 Message-Id: <20230628153342.53406-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769961342236014879?= X-GMAIL-MSGID: =?utf-8?q?1769961342236014879?= |
Series |
[v1,1/1] kasan: Replace strreplace() with strchrnul()
|
|
Commit Message
Andy Shevchenko
June 28, 2023, 3:33 p.m. UTC
We don't need to traverse over the entire string and replace
occurrences of a character with '\0'. The first match will
suffice. Hence, replace strreplace() with strchrnul().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
mm/kasan/report_generic.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Wed, Jun 28, 2023 at 5:34 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > We don't need to traverse over the entire string and replace > occurrences of a character with '\0'. The first match will > suffice. Hence, replace strreplace() with strchrnul(). > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > --- > mm/kasan/report_generic.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c > index 51a1e8a8877f..63a34eac4a8c 100644 > --- a/mm/kasan/report_generic.c > +++ b/mm/kasan/report_generic.c > @@ -264,6 +264,7 @@ static void print_decoded_frame_descr(const char *frame_descr) > while (num_objects--) { > unsigned long offset; > unsigned long size; > + char *p; > > /* access offset */ > if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), > @@ -282,7 +283,7 @@ static void print_decoded_frame_descr(const char *frame_descr) > return; > > /* Strip line number; without filename it's not very helpful. */ > - strreplace(token, ':', '\0'); > + p[strchrnul(token, ':') - token] = '\0'; Why not just *(strchrnul(token, ':')) = '\0'; ?
On Wed, Jun 28, 2023 at 05:39:26PM +0200, Alexander Potapenko wrote: > On Wed, Jun 28, 2023 at 5:34 PM Andy Shevchenko > <andriy.shevchenko@linux.intel.com> wrote: ... > > /* Strip line number; without filename it's not very helpful. */ > > - strreplace(token, ':', '\0'); > > + p[strchrnul(token, ':') - token] = '\0'; > > Why not just > *(strchrnul(token, ':')) = '\0'; > ? I don't like Pythonish style in the C. But if you insist, I can update it.
From: Andy Shevchenko > Sent: 28 June 2023 16:34 > > We don't need to traverse over the entire string and replace > occurrences of a character with '\0'. The first match will > suffice. Hence, replace strreplace() with strchrnul(). > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > --- > mm/kasan/report_generic.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c > index 51a1e8a8877f..63a34eac4a8c 100644 > --- a/mm/kasan/report_generic.c > +++ b/mm/kasan/report_generic.c > @@ -264,6 +264,7 @@ static void print_decoded_frame_descr(const char *frame_descr) > while (num_objects--) { > unsigned long offset; > unsigned long size; > + char *p; > > /* access offset */ > if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), > @@ -282,7 +283,7 @@ static void print_decoded_frame_descr(const char *frame_descr) > return; > > /* Strip line number; without filename it's not very helpful. */ > - strreplace(token, ':', '\0'); > + p[strchrnul(token, ':') - token] = '\0'; Isn't 'p' undefined here? David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Thu, Jun 29, 2023 at 02:32:13PM +0000, David Laight wrote: > From: Andy Shevchenko > > Sent: 28 June 2023 16:34 ... > > /* Strip line number; without filename it's not very helpful. */ > > - strreplace(token, ':', '\0'); > > + p[strchrnul(token, ':') - token] = '\0'; > > Isn't 'p' undefined here? Yep, should be token. Not sure what I was thinking about...
On Wed, Jun 28, 2023 at 06:33:42PM +0300, Andy Shevchenko wrote: > We don't need to traverse over the entire string and replace > occurrences of a character with '\0'. The first match will > suffice. Hence, replace strreplace() with strchrnul(). Not that it's a hot path, the bloat-o-meter shows +6 bytes on x86_64, the change seems has no added value, self-rejected.
Hi Andy, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master v6.5-rc2 next-20230718] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/kasan-Replace-strreplace-with-strchrnul/20230628-233727 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230628153342.53406-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v1 1/1] kasan: Replace strreplace() with strchrnul() config: x86_64-randconfig-x001-20230718 (https://download.01.org/0day-ci/archive/20230719/202307191350.tJh2PZdE-lkp@intel.com/config) compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) reproduce: (https://download.01.org/0day-ci/archive/20230719/202307191350.tJh2PZdE-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202307191350.tJh2PZdE-lkp@intel.com/ All warnings (new ones prefixed by >>): >> mm/kasan/report_generic.c:286:3: warning: variable 'p' is uninitialized when used here [-Wuninitialized] p[strchrnul(token, ':') - token] = '\0'; ^ mm/kasan/report_generic.c:267:10: note: initialize the variable 'p' to silence this warning char *p; ^ = NULL 1 warning generated. vim +/p +286 mm/kasan/report_generic.c 242 243 static void print_decoded_frame_descr(const char *frame_descr) 244 { 245 /* 246 * We need to parse the following string: 247 * "n alloc_1 alloc_2 ... alloc_n" 248 * where alloc_i looks like 249 * "offset size len name" 250 * or "offset size len name:line". 251 */ 252 253 char token[64]; 254 unsigned long num_objects; 255 256 if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), 257 &num_objects)) 258 return; 259 260 pr_err("\n"); 261 pr_err("This frame has %lu %s:\n", num_objects, 262 num_objects == 1 ? "object" : "objects"); 263 264 while (num_objects--) { 265 unsigned long offset; 266 unsigned long size; 267 char *p; 268 269 /* access offset */ 270 if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), 271 &offset)) 272 return; 273 /* access size */ 274 if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), 275 &size)) 276 return; 277 /* name length (unused) */ 278 if (!tokenize_frame_descr(&frame_descr, NULL, 0, NULL)) 279 return; 280 /* object name */ 281 if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), 282 NULL)) 283 return; 284 285 /* Strip line number; without filename it's not very helpful. */ > 286 p[strchrnul(token, ':') - token] = '\0'; 287 288 /* Finally, print object information. */ 289 pr_err(" [%lu, %lu) '%s'", offset, offset + size, token); 290 } 291 } 292
diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 51a1e8a8877f..63a34eac4a8c 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -264,6 +264,7 @@ static void print_decoded_frame_descr(const char *frame_descr) while (num_objects--) { unsigned long offset; unsigned long size; + char *p; /* access offset */ if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), @@ -282,7 +283,7 @@ static void print_decoded_frame_descr(const char *frame_descr) return; /* Strip line number; without filename it's not very helpful. */ - strreplace(token, ':', '\0'); + p[strchrnul(token, ':') - token] = '\0'; /* Finally, print object information. */ pr_err(" [%lu, %lu) '%s'", offset, offset + size, token);