Message ID | 4ebda26c.346.18404df6852.Coremail.wangkailong@jari.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1602789wrr; Sun, 23 Oct 2022 05:55:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6H/brVMMjwNc4QnCgSjthhS7OqlBa8dGMr68UwuAlKeHZti86yD4XnASM8AlOs9Y/OEOE1 X-Received: by 2002:a17:907:9811:b0:79a:a1fe:8be6 with SMTP id ji17-20020a170907981100b0079aa1fe8be6mr10762522ejc.480.1666529755955; Sun, 23 Oct 2022 05:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666529755; cv=none; d=google.com; s=arc-20160816; b=VM/4T9r7GP+gQ9iw8XYpzQ4kl38GOxeGzdl1YjePxaBV4DPCmodg+8nGDUTuwKu9QJ OB+Or+3bYUBlCHDN4JSrrnT230n/DXjR0QG8/2QCt91ghPBlESKuMS920ctizqroQIEa ScF5CPYSyRwtbacLmJ2gXEiNG903MXK8q8nn5/UsDrGxBjg6gxhhATSvDF5yQNh5NYaX 0qEy9dJguFvlaVVSbj38e1/Gb/qegVgybk2D8kOymSzEPlmAgGCiObdTZ3AhnaoISKDD /TyBgMDZs9dfJ8NMg/rKwpN1f3nfi3UJeNhbr9rtvHLi8aEM6udTJKn/nIe8YlmVVDBT gGLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:mime-version :content-transfer-encoding:subject:cc:to:from:date; bh=T0nq/F2Ddnd7DW9rtSmMq2uXjCIntmkZgOX2cRxR6+U=; b=NQ/jyZkm4JfoAz6WU6aktoy/U4lbajebmLwblsOWveezBQ1sdhWbej7SQ+Nc6bHeev 8Vwy93DDtwGd8OgQyE+6Ud5Cm8QV1m9Ub+8AajFLIuvOS8WfB5wJNJGUfzCu4pWzCJ23 qBi/fPyyIgkqEausSBQUJV0sFnGpGlZ5BBcryLOhxz5x6EWMCFIScGWGOtpZMpMAQTZX u23E4cYlnmk6aABgvPqUvtNjju2pIbn9YDdH7Lbn11IYZKVyL3rRJcJbi6UofFvigQVz +OSi618JqpDqMWmvvw3LuP66B5oIrwkVHv+dlJll+YXWHoJ7c2u10VWJn50R8iHAjyQH RW0A== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb35-20020a1709071ca300b0078dce6e5cf8si23752393ejc.436.2022.10.23.05.55.32; Sun, 23 Oct 2022 05:55:55 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230268AbiJWMsL (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Sun, 23 Oct 2022 08:48:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229781AbiJWMsK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 23 Oct 2022 08:48:10 -0400 X-Greylist: delayed 118 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 23 Oct 2022 05:48:01 PDT Received: from jari.cn (unknown [218.92.28.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5FC6674E03 for <linux-kernel@vger.kernel.org>; Sun, 23 Oct 2022 05:48:01 -0700 (PDT) Received: by ajax-webmail-localhost.localdomain (Coremail) ; Sun, 23 Oct 2022 20:44:20 +0800 (GMT+08:00) X-Originating-IP: [182.148.15.254] Date: Sun, 23 Oct 2022 20:44:20 +0800 (GMT+08:00) X-CM-HeaderCharset: UTF-8 From: "KaiLong Wang" <wangkailong@jari.cn> To: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, farosas@linux.ibm.com, mirq-linux@rere.qmqm.pl, dmitry.osipenko@collabora.com, kda@linux-powerpc.org, naveen.n.rao@linux.vnet.ibm.com Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH] powerpc: replace ternary operator with min() X-Priority: 3 X-Mailer: Coremail Webmail Server Version XT6.0.1 build 20210329(c53f3fee) Copyright (c) 2002-2022 www.mailtech.cn mispb-4e503810-ca60-4ec8-a188-7102c18937cf-zhkzyfz.cn Content-Transfer-Encoding: base64 Content-Type: text/plain; charset=UTF-8 MIME-Version: 1.0 Message-ID: <4ebda26c.346.18404df6852.Coremail.wangkailong@jari.cn> X-Coremail-Locale: zh_CN X-CM-TRANSID: AQAAfwD3AG8lN1Vjk+RoAA--.1470W X-CM-SenderInfo: 5zdqwypdlo00nj6mt2flof0/1tbiAQAIB2FEYxtOmwAAsG X-Coremail-Antispam: 1Ur529EdanIXcx71UUUUU7IcSsGvfJ3iIAIbVAYjsxI4VWxJw CS07vEb4IE77IF4wCS07vE1I0E4x80FVAKz4kxMIAIbVAFxVCaYxvI4VCIwcAKzIAtYxBI daVFxhVjvjDU= X-Spam-Status: No, score=2.2 required=5.0 tests=BAYES_00,RCVD_IN_PBL,RDNS_NONE, T_SPF_HELO_PERMERROR,T_SPF_PERMERROR,XPRIO autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747483105157350055?= X-GMAIL-MSGID: =?utf-8?q?1747483105157350055?= |
Series |
powerpc: replace ternary operator with min()
|
|
Commit Message
KaiLong Wang
Oct. 23, 2022, 12:44 p.m. UTC
Fix the following coccicheck warning:
arch/powerpc/xmon/xmon.c:2987: WARNING opportunity for min()
arch/powerpc/xmon/xmon.c:2583: WARNING opportunity for min()
Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
---
arch/powerpc/xmon/xmon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Sun, 2022-10-23 at 20:44 +0800, KaiLong Wang wrote: > Fix the following coccicheck warning: > > arch/powerpc/xmon/xmon.c:2987: WARNING opportunity for min() > arch/powerpc/xmon/xmon.c:2583: WARNING opportunity for min() > > Signed-off-by: KaiLong Wang <wangkailong@jari.cn> Hello, This fails to compile on some platforms/compilers since n is a long and 16 is an int, expanding to: r = __builtin_choose_expr( ((!!(sizeof((typeof(n) *)1 == (typeof(16) *)1))) && ((sizeof(int) == sizeof(*(8 ? ((void *)((long)(n)*0l)) : (int *)8))) && (sizeof(int) == sizeof(*(8 ? ((void *)((long)(16) * 0l)) : (int *)8))))), ((n) < (16) ? (n) : (16)), ({ typeof(n) __UNIQUE_ID___x0 = (n); typeof(16) __UNIQUE_ID___y1 = (16); ((__UNIQUE_ID___x0) < (__UNIQUE_ID___y1) ? (__UNIQUE_ID___x0) : (__UNIQUE_ID___y1)); })); Here's the full build failure as found by snowpatch: https://github.com/ruscur/linux-ci/actions/runs/3308880562/jobs/5461579048#step:4:89 You should use min_t(long, n, 16) instead. - Russell > --- > arch/powerpc/xmon/xmon.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c > index f51c882bf902..a7751cd2cc9d 100644 > --- a/arch/powerpc/xmon/xmon.c > +++ b/arch/powerpc/xmon/xmon.c > @@ -2580,7 +2580,7 @@ static void xmon_rawdump (unsigned long adrs, > long ndump) > unsigned char temp[16]; > > for (n = ndump; n > 0;) { > - r = n < 16? n: 16; > + r = min(n, 16); > nr = mread(adrs, temp, r); > adrs += nr; > for (m = 0; m < r; ++m) { > @@ -2984,7 +2984,7 @@ prdump(unsigned long adrs, long ndump) > for (n = ndump; n > 0;) { > printf(REG, adrs); > putchar(' '); > - r = n < 16? n: 16; > + r = min(n, 16); > nr = mread(adrs, temp, r); > adrs += nr; > for (m = 0; m < r; ++m) {
Hi KaiLong, Thank you for the patch! Yet something to improve: [auto build test ERROR on powerpc/next] [also build test ERROR on linus/master v6.1-rc2 next-20221026] [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/KaiLong-Wang/powerpc-replace-ternary-operator-with-min/20221023-204906 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/4ebda26c.346.18404df6852.Coremail.wangkailong%40jari.cn patch subject: [PATCH] powerpc: replace ternary operator with min() config: powerpc-ppc64e_defconfig (attached as .config) compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install powerpc cross compiling tool for clang build # apt-get install binutils-powerpc-linux-gnu # https://github.com/intel-lab-lkp/linux/commit/51fa624eb9fa01ea67de462263913ab61a68cbc5 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review KaiLong-Wang/powerpc-replace-ternary-operator-with-min/20221023-204906 git checkout 51fa624eb9fa01ea67de462263913ab61a68cbc5 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): >> arch/powerpc/xmon/xmon.c:2583:7: error: comparison of distinct pointer types ('typeof (n) *' (aka 'long *') and 'typeof (16) *' (aka 'int *')) [-Werror,-Wcompare-distinct-pointer-types] r = min(n, 16); ^~~~~~~~~~ include/linux/minmax.h:45:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(x, y, <) ^~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp' __builtin_choose_expr(__safe_cmp(x, y), \ ^~~~~~~~~~~~~~~~ include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp' (__typecheck(x, y) && __no_side_effects(x, y)) ^~~~~~~~~~~~~~~~~ include/linux/minmax.h:20:28: note: expanded from macro '__typecheck' (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~ arch/powerpc/xmon/xmon.c:2987:7: error: comparison of distinct pointer types ('typeof (n) *' (aka 'long *') and 'typeof (16) *' (aka 'int *')) [-Werror,-Wcompare-distinct-pointer-types] r = min(n, 16); ^~~~~~~~~~ include/linux/minmax.h:45:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(x, y, <) ^~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:36:24: note: expanded from macro '__careful_cmp' __builtin_choose_expr(__safe_cmp(x, y), \ ^~~~~~~~~~~~~~~~ include/linux/minmax.h:26:4: note: expanded from macro '__safe_cmp' (__typecheck(x, y) && __no_side_effects(x, y)) ^~~~~~~~~~~~~~~~~ include/linux/minmax.h:20:28: note: expanded from macro '__typecheck' (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~ 2 errors generated. vim +2583 arch/powerpc/xmon/xmon.c 2576 2577 static void xmon_rawdump (unsigned long adrs, long ndump) 2578 { 2579 long n, m, r, nr; 2580 unsigned char temp[16]; 2581 2582 for (n = ndump; n > 0;) { > 2583 r = min(n, 16); 2584 nr = mread(adrs, temp, r); 2585 adrs += nr; 2586 for (m = 0; m < r; ++m) { 2587 if (m < nr) 2588 printf("%.2x", temp[m]); 2589 else 2590 printf("%s", fault_chars[fault_type]); 2591 } 2592 n -= r; 2593 if (nr < r) 2594 break; 2595 } 2596 printf("\n"); 2597 } 2598
Le 24/10/2022 à 06:33, Russell Currey a écrit : > On Sun, 2022-10-23 at 20:44 +0800, KaiLong Wang wrote: >> Fix the following coccicheck warning: >> >> arch/powerpc/xmon/xmon.c:2987: WARNING opportunity for min() >> arch/powerpc/xmon/xmon.c:2583: WARNING opportunity for min() >> >> Signed-off-by: KaiLong Wang <wangkailong@jari.cn> > > Hello, > > This fails to compile on some platforms/compilers since n is a long and > 16 is an int, expanding to: > > r = __builtin_choose_expr( > ((!!(sizeof((typeof(n) *)1 == (typeof(16) *)1))) && > ((sizeof(int) == > sizeof(*(8 ? ((void *)((long)(n)*0l)) : (int *)8))) && > (sizeof(int) == > sizeof(*(8 ? ((void *)((long)(16) * 0l)) : > (int *)8))))), > ((n) < (16) ? (n) : (16)), ({ > typeof(n) __UNIQUE_ID___x0 = (n); > typeof(16) __UNIQUE_ID___y1 = (16); > ((__UNIQUE_ID___x0) < (__UNIQUE_ID___y1) ? > (__UNIQUE_ID___x0) : > (__UNIQUE_ID___y1)); > })); > > Here's the full build failure as found by snowpatch: > https://github.com/ruscur/linux-ci/actions/runs/3308880562/jobs/5461579048#step:4:89 > > You should use min_t(long, n, 16) instead. Wouldn't it work with 16L instead of 16 : min(n, 16L) Christophe > > - Russell > >> --- >> arch/powerpc/xmon/xmon.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c >> index f51c882bf902..a7751cd2cc9d 100644 >> --- a/arch/powerpc/xmon/xmon.c >> +++ b/arch/powerpc/xmon/xmon.c >> @@ -2580,7 +2580,7 @@ static void xmon_rawdump (unsigned long adrs, >> long ndump) >> unsigned char temp[16]; >> >> for (n = ndump; n > 0;) { >> - r = n < 16? n: 16; >> + r = min(n, 16); >> nr = mread(adrs, temp, r); >> adrs += nr; >> for (m = 0; m < r; ++m) { >> @@ -2984,7 +2984,7 @@ prdump(unsigned long adrs, long ndump) >> for (n = ndump; n > 0;) { >> printf(REG, adrs); >> putchar(' '); >> - r = n < 16? n: 16; >> + r = min(n, 16); >> nr = mread(adrs, temp, r); >> adrs += nr; >> for (m = 0; m < r; ++m) { >
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index f51c882bf902..a7751cd2cc9d 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -2580,7 +2580,7 @@ static void xmon_rawdump (unsigned long adrs, long ndump) unsigned char temp[16]; for (n = ndump; n > 0;) { - r = n < 16? n: 16; + r = min(n, 16); nr = mread(adrs, temp, r); adrs += nr; for (m = 0; m < r; ++m) { @@ -2984,7 +2984,7 @@ prdump(unsigned long adrs, long ndump) for (n = ndump; n > 0;) { printf(REG, adrs); putchar(' '); - r = n < 16? n: 16; + r = min(n, 16); nr = mread(adrs, temp, r); adrs += nr; for (m = 0; m < r; ++m) {