linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Russell Currey <ruscur@russell.cc>,
	KaiLong Wang <wangkailong@jari.cn>,
	"mpe@ellerman.id.au" <mpe@ellerman.id.au>,
	"npiggin@gmail.com" <npiggin@gmail.com>,
	"farosas@linux.ibm.com" <farosas@linux.ibm.com>,
	"mirq-linux@rere.qmqm.pl" <mirq-linux@rere.qmqm.pl>,
	"dmitry.osipenko@collabora.com" <dmitry.osipenko@collabora.com>,
	"kda@linux-powerpc.org" <kda@linux-powerpc.org>,
	"naveen.n.rao@linux.vnet.ibm.com"
	<naveen.n.rao@linux.vnet.ibm.com>
Cc: "linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] powerpc: replace ternary operator with min()
Date: Wed, 2 Nov 2022 09:23:15 +0000	[thread overview]
Message-ID: <b9b0aebb-a27e-826f-a3d1-954fa3421747@csgroup.eu> (raw)
In-Reply-To: <6426e8cf8d3bb2fff1403038ef627548f07cef32.camel@russell.cc>



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) {
> 

  reply	other threads:[~2022-11-02  9:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-23 12:44 [PATCH] powerpc: replace ternary operator with min() KaiLong Wang
2022-10-24  4:33 ` Russell Currey
2022-11-02  9:23   ` Christophe Leroy [this message]
2022-10-26 12:07 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b9b0aebb-a27e-826f-a3d1-954fa3421747@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=dmitry.osipenko@collabora.com \
    --cc=farosas@linux.ibm.com \
    --cc=kda@linux-powerpc.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=mpe@ellerman.id.au \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=ruscur@russell.cc \
    --cc=wangkailong@jari.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).