[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z/bC6cygo0hem5IO@visitorckw-System-Product-Name>
Date: Thu, 10 Apr 2025 02:56:41 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: Yury Norov <yury.norov@...il.com>
Cc: tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, jk@...abs.org,
joel@....id.au, eajames@...ux.ibm.com, andrzej.hajda@...el.com,
neil.armstrong@...aro.org, rfoss@...nel.org,
maarten.lankhorst@...ux.intel.com, mripard@...nel.org,
tzimmermann@...e.de, airlied@...il.com, simona@...ll.ch,
dmitry.torokhov@...il.com, mchehab@...nel.org,
awalls@...metrocast.net, hverkuil@...all.nl,
miquel.raynal@...tlin.com, richard@....at, vigneshr@...com,
louis.peens@...igine.com, andrew+netdev@...n.ch,
davem@...emloft.net, edumazet@...gle.com, pabeni@...hat.com,
parthiban.veerasooran@...rochip.com, arend.vanspriel@...adcom.com,
johannes@...solutions.net, gregkh@...uxfoundation.org,
jirislaby@...nel.org, akpm@...ux-foundation.org, jdelvare@...e.com,
linux@...ck-us.net, alexandre.belloni@...tlin.com, pgaj@...ence.com,
hpa@...or.com, alistair@...ple.id.au, linux@...musvillemoes.dk,
Laurent.pinchart@...asonboard.com, jonas@...boo.se,
jernej.skrabec@...il.com, kuba@...nel.org,
linux-kernel@...r.kernel.org, linux-fsi@...ts.ozlabs.org,
dri-devel@...ts.freedesktop.org, linux-input@...r.kernel.org,
linux-media@...r.kernel.org, linux-mtd@...ts.infradead.org,
oss-drivers@...igine.com, netdev@...r.kernel.org,
linux-wireless@...r.kernel.org, brcm80211@...ts.linux.dev,
brcm80211-dev-list.pdl@...adcom.com, linux-serial@...r.kernel.org,
bpf@...r.kernel.org, jserv@...s.ncku.edu.tw, Frank.Li@....com,
linux-hwmon@...r.kernel.org, linux-i3c@...ts.infradead.org,
david.laight.linux@...il.com, andrew.cooper3@...rix.com,
Yu-Chun Lin <eleanor15x@...il.com>
Subject: Re: [PATCH v4 02/13] media: media/test_drivers: Replace open-coded
parity calculation with parity_odd()
On Wed, Apr 09, 2025 at 02:41:03PM -0400, Yury Norov wrote:
> On Thu, Apr 10, 2025 at 02:23:09AM +0800, Kuan-Wei Chiu wrote:
> > On Wed, Apr 09, 2025 at 01:03:42PM -0400, Yury Norov wrote:
> > > On Wed, Apr 09, 2025 at 11:43:45PM +0800, Kuan-Wei Chiu wrote:
> > > > Refactor parity calculations to use the standard parity_odd() helper.
> > > > This change eliminates redundant implementations.
> > > >
> > > > Co-developed-by: Yu-Chun Lin <eleanor15x@...il.com>
> > > > Signed-off-by: Yu-Chun Lin <eleanor15x@...il.com>
> > > > Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
> > > > ---
> > > > drivers/media/test-drivers/vivid/vivid-vbi-gen.c | 8 ++------
> > > > 1 file changed, 2 insertions(+), 6 deletions(-)
> > > >
> > > > diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-gen.c b/drivers/media/test-drivers/vivid/vivid-vbi-gen.c
> > > > index 70a4024d461e..5e1b7b1742e4 100644
> > > > --- a/drivers/media/test-drivers/vivid/vivid-vbi-gen.c
> > > > +++ b/drivers/media/test-drivers/vivid/vivid-vbi-gen.c
> > > > @@ -5,6 +5,7 @@
> > > > * Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
> > > > */
> > > >
> > > > +#include <linux/bitops.h>
> > > > #include <linux/errno.h>
> > > > #include <linux/kernel.h>
> > > > #include <linux/ktime.h>
> > > > @@ -165,12 +166,7 @@ static const u8 vivid_cc_sequence2[30] = {
> > > >
> > > > static u8 calc_parity(u8 val)
> > > > {
> > > > - unsigned i;
> > > > - unsigned tot = 0;
> > > > -
> > > > - for (i = 0; i < 7; i++)
> > > > - tot += (val & (1 << i)) ? 1 : 0;
> > > > - return val | ((tot & 1) ? 0 : 0x80);
> > > > + return val | (parity_odd(val) ? 0 : 0x80);
> > >
> > > So, if val == 0 than parity_odd(val) is also 0, and this can be
> > > simplified just to:
> > > return parity(val) ? 0 : 0x80;
> > > Or I miss something?
> > >
> > If val == 0x01, the return value of calc_parity() will remain 0x01.
> > If changed to return parity_odd(val) ? 0 : 0x80;, the return value will
> > be changed to 0x00.
>
> Sorry, I meant
> return val ? 0 : 0x80;
>
> This 'val | (parity_odd(val)' is only false when val == 0, right?
> When val != 0, compiler will return true immediately, not even calling
> parity().
>
I'm still confused.
Maybe you're interpreting the code as:
(val | parity(val)) ? 0 : 0x80
But what we're trying to do is:
val | (parity(val) ? 0 : 0x80)
So, for example, if val == 0x06, the return value will be 0x86.
Only returning 0 or 0x80 seems wrong to me.
Or did I misunderstand something?
Regards,
Kuan-Wei
> I think we need a comment from authors.
Powered by blists - more mailing lists