mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Russell Currey <ruscur@russell.cc>
To: KaiLong Wang <wangkailong@jari.cn>,
	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: Re: [PATCH] powerpc: replace ternary operator with min()
Date: Mon, 24 Oct 2022 15:33:15 +1100	[thread overview]
Message-ID: <6426e8cf8d3bb2fff1403038ef627548f07cef32.camel@russell.cc> (raw)
In-Reply-To: <4ebda26c.346.18404df6852.Coremail.wangkailong@jari.cn>

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


  reply	other threads:[~2022-10-24  4:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-23 12:44 KaiLong Wang
2022-10-24  4:33 ` Russell Currey [this message]
2022-11-02  9:23   ` Christophe Leroy
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=6426e8cf8d3bb2fff1403038ef627548f07cef32.camel@russell.cc \
    --to=ruscur@russell.cc \
    --cc=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=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

all inboxes | Powered by JetHome®