[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6426e8cf8d3bb2fff1403038ef627548f07cef32.camel@russell.cc>
Date: Mon, 24 Oct 2022 15:33:15 +1100
From: Russell Currey <ruscur@...sell.cc>
To: KaiLong Wang <wangkailong@...i.cn>, mpe@...erman.id.au,
npiggin@...il.com, christophe.leroy@...roup.eu,
farosas@...ux.ibm.com, mirq-linux@...e.qmqm.pl,
dmitry.osipenko@...labora.com, kda@...ux-powerpc.org,
naveen.n.rao@...ux.vnet.ibm.com
Cc: linuxppc-dev@...ts.ozlabs.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] powerpc: replace ternary operator with min()
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@...i.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) {
Powered by blists - more mailing lists