Message ID | 20231018064817.86721-1-jiapeng.chong@linux.alibaba.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4605134vqb; Tue, 17 Oct 2023 23:48:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFI+s/oravAJUPMjaR2mCLQqs83whyjzWU/y0E5Z/Kr+eHidqOzirmvLrOJSwcv3rRmqF+u X-Received: by 2002:a54:448e:0:b0:3a9:f25d:d917 with SMTP id v14-20020a54448e000000b003a9f25dd917mr4804792oiv.4.1697611714980; Tue, 17 Oct 2023 23:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697611714; cv=none; d=google.com; s=arc-20160816; b=M4Ju5uZ/frCkNIXo+x5WDX7OccYj/46LbTGB+pqiWksD5w0PAO/RQzpdK/FETY4z8v KqLMEJirZe53eSTf+dLngNQV+fhjiCEHaX9XUxjK/YICh8ewtAWqJSR1LM3ARgL64FPn oLK26Z5dppnr20jRKEVOTsxU3UMhc2XQYIVXSxE2/XEiPAl4WUkxlDgUGgsOMv5hteKe dg/ukxqKKlpDa03WcoOTcqLnph2hqxR/mVOdTJLuaJmdLXoTizhPM4xfGyPwVtDgC7iT Kai7g3SQoWdL3X2VSugoGDuy3E91w9d7dLIv0e33zikKsQBPPfTybwiBhgLSF8NVlBK+ kKBQ== 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; bh=EEgTuKkZbau4hIB/vMYKc7Suhsh9bjclwDqF5zb14pM=; fh=7pJOd2elMeWZIKI2NfY0I/yxzdo+uXwUt04e/IE2nM8=; b=NreRWEYcun/4dQF+D4T4asfHZfh0UX/OPnK5I3HhoqZYcG8FZn7Zn0Xgx2vOexYuRN IK6MP9fasHixqOIx9fyGd/CYn+dgOMVB4Kh+aZM2Vf8RpGThoAZP0v9XnUVDaTsyADc/ xqZMphYjmenyLa0Yck5y1KAaxtzGw7zLqYYogUSIvulNH5aeGeHcx/f/pXjD0E1GvKUH viHX07aV/7ujdQV9lBVYB5QlOt84rY9pU0UKTX+K+PmstVjxqWDBusLLmdI6FSmliHUC C+lIENEdX7FT5d1gSuprvDnYRwfaU6l9NH9vVYxyK7JQlnILe1CeKlxqnH4hcMJU9w0f FboQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id w9-20020a654109000000b005acd3068202si1417840pgp.552.2023.10.17.23.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 23:48:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5614580D6E4F; Tue, 17 Oct 2023 23:48:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjJRGsa (ORCPT <rfc822;zwp10758@gmail.com> + 23 others); Wed, 18 Oct 2023 02:48:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjJRGs3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 18 Oct 2023 02:48:29 -0400 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9707B0 for <linux-kernel@vger.kernel.org>; Tue, 17 Oct 2023 23:48:26 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=jiapeng.chong@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VuPuRWb_1697611697; Received: from localhost(mailfrom:jiapeng.chong@linux.alibaba.com fp:SMTPD_---0VuPuRWb_1697611697) by smtp.aliyun-inc.com; Wed, 18 Oct 2023 14:48:23 +0800 From: Jiapeng Chong <jiapeng.chong@linux.alibaba.com> To: pmladek@suse.com Cc: rostedt@goodmis.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, senozhatsky@chromium.org, linux-kernel@vger.kernel.org, Jiapeng Chong <jiapeng.chong@linux.alibaba.com>, Abaci Robot <abaci@linux.alibaba.com> Subject: [PATCH] lib/vsprintf: Remove redundant code Date: Wed, 18 Oct 2023 14:48:17 +0800 Message-Id: <20231018064817.86721-1-jiapeng.chong@linux.alibaba.com> X-Mailer: git-send-email 2.20.1.7.g153144c MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 17 Oct 2023 23:48:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780074901353465028 X-GMAIL-MSGID: 1780074901353465028 |
Series |
lib/vsprintf: Remove redundant code
|
|
Commit Message
Jiapeng Chong
Oct. 18, 2023, 6:48 a.m. UTC
When variable needcolon is assigned a value of false, it must be
assigned a value of true later on, which is redundant code.
lib/vsprintf.c:1411:4: warning: Value stored to 'needcolon' is never read.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=6909
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
lib/vsprintf.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
Comments
On Wed, Oct 18, 2023 at 02:48:17PM +0800, Jiapeng Chong wrote: > When variable needcolon is assigned a value of false, it must be > assigned a value of true later on, which is redundant code. > > lib/vsprintf.c:1411:4: warning: Value stored to 'needcolon' is never read. ... > @@ -1406,10 +1406,9 @@ char *ip6_compressed_string(char *p, const char *addr) > i += longest - 1; > continue; > } > - if (needcolon) { > + if (needcolon) > *p++ = ':'; > - needcolon = false; > - } > + > /* hex u16 without leading 0s */ > word = ntohs(in6.s6_addr16[i]); > hi = word >> 8; Logically you may remove then the assignment to true as well. But I would double check if it's not a continue missing somewhere or so.
On 18/10/2023 08.48, Jiapeng Chong wrote: > When variable needcolon is assigned a value of false, it must be > assigned a value of true later on, which is redundant code. NAK on any patch modifying these things without first filling the blank space in ip6() in lib/test_printf.c with tests for all the various ip6 printing modes. Adding test cases there is much more useful than code-golfing, and would help verify that these changes are actually ok. Or may reveal that the current code is buggy. Rasmus
On Thu, Oct 19, 2023 at 01:51:45PM +0200, Rasmus Villemoes wrote: > On 18/10/2023 08.48, Jiapeng Chong wrote: ... > Or may reveal that the current code is buggy. ...and hopefully didn't become a part of any ABIs...
On Wed 2023-10-18 14:48:17, Jiapeng Chong wrote: > When variable needcolon is assigned a value of false, it must be > assigned a value of true later on, which is redundant code. > > lib/vsprintf.c:1411:4: warning: Value stored to 'needcolon' is never read. > > Reported-by: Abaci Robot <abaci@linux.alibaba.com> > Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=6909 > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com> > --- > lib/vsprintf.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index afb88b24fa74..9a9086885da8 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -1406,10 +1406,9 @@ char *ip6_compressed_string(char *p, const char *addr) > i += longest - 1; > continue; > } > - if (needcolon) { > + if (needcolon) > *p++ = ':'; > - needcolon = false; > - } > + > /* hex u16 without leading 0s */ > word = ntohs(in6.s6_addr16[i]); > hi = word >> 8; I am against this change. The assignment should be there from the logical POV. IMHO, it helps people to verify that the code works as expected. The removal might even cause regression when the logic gets modified in the future. Anyway, this is a slow path. The code readability is more important then the speed. Let compiler do these micro optimizations. Best Regards, Petr
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index afb88b24fa74..9a9086885da8 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1406,10 +1406,9 @@ char *ip6_compressed_string(char *p, const char *addr) i += longest - 1; continue; } - if (needcolon) { + if (needcolon) *p++ = ':'; - needcolon = false; - } + /* hex u16 without leading 0s */ word = ntohs(in6.s6_addr16[i]); hi = word >> 8;