lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <783456A8-67F9-47DD-AB15-914622A921CD@zytor.com>
Date: Fri, 07 Mar 2025 11:33:40 -0800
From: "H. Peter Anvin" <hpa@...or.com>
To: Yury Norov <yury.norov@...il.com>
CC: Ingo Molnar <mingo@...nel.org>, Jiri Slaby <jirislaby@...nel.org>,
        Kuan-Wei Chiu <visitorckw@...il.com>, 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,
        akpm@...ux-foundation.org, 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,
        Yu-Chun Lin <eleanor15x@...il.com>
Subject: Re: [PATCH v3 01/16] bitops: Change parity8() return type to bool

On March 7, 2025 11:30:08 AM PST, Yury Norov <yury.norov@...il.com> wrote:
>On Fri, Mar 07, 2025 at 04:14:34AM -0800, H. Peter Anvin wrote:
>> On March 7, 2025 4:13:26 AM PST, Ingo Molnar <mingo@...nel.org> wrote:
>> >
>> >* Jiri Slaby <jirislaby@...nel.org> wrote:
>> >
>> >> On 07. 03. 25, 12:38, Ingo Molnar wrote:
>> >> > 
>> >> > * Jiri Slaby <jirislaby@...nel.org> wrote:
>> >> > 
>> >> > > On 06. 03. 25, 17:25, Kuan-Wei Chiu wrote:
>> >> > > > Change return type to bool for better clarity. Update the kernel doc
>> >> > > > comment accordingly, including fixing "@value" to "@val" and adjusting
>> >> > > > examples. Also mark the function with __attribute_const__ to allow
>> >> > > > potential compiler optimizations.
>> >> > > > 
>> >> > > > 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>
>> >> > > > ---
>> >> > > >    include/linux/bitops.h | 10 +++++-----
>> >> > > >    1 file changed, 5 insertions(+), 5 deletions(-)
>> >> > > > 
>> >> > > > diff --git a/include/linux/bitops.h b/include/linux/bitops.h
>> >> > > > index c1cb53cf2f0f..44e5765b8bec 100644
>> >> > > > --- a/include/linux/bitops.h
>> >> > > > +++ b/include/linux/bitops.h
>> >> > > > @@ -231,26 +231,26 @@ static inline int get_count_order_long(unsigned long l)
>> >> > > >    /**
>> >> > > >     * parity8 - get the parity of an u8 value
>> >> > > > - * @value: the value to be examined
>> >> > > > + * @val: the value to be examined
>> >> > > >     *
>> >> > > >     * Determine the parity of the u8 argument.
>> >> > > >     *
>> >> > > >     * Returns:
>> >> > > > - * 0 for even parity, 1 for odd parity
>> >> > > > + * false for even parity, true for odd parity
>> >> > > 
>> >> > > This occurs somehow inverted to me. When something is in parity means that
>> >> > > it has equal number of 1s and 0s. I.e. return true for even distribution.
>> >> > > Dunno what others think? Or perhaps this should be dubbed odd_parity() when
>> >> > > bool is returned? Then you'd return true for odd.
>> >> > 
>> >> > OTOH:
>> >> > 
>> >> >   - '0' is an even number and is returned for even parity,
>> >> >   - '1' is an odd  number and is returned for odd  parity.
>> >> 
>> >> Yes, that used to make sense for me. For bool/true/false, it no longer does.
>> >> But as I wrote, it might be only me...
>> >
>> >No strong opinion on this from me either, I'd guess existing practice 
>> >with other parity functions should probably control. (If a coherent 
>> >praxis exists.).
>> >
>> >Thanks,
>> >
>> >	Ingo
>> 
>> Instead of "bool" think of it as "bit" and it makes more sense
>
>So, to help people thinking that way we can introduce a corresponding
>type:
>        typedef unsigned _BitInt(1) u1;
>
>It already works for clang, and GCC is going to adopt it with std=c23.
>We can make u1 an alias to bool for GCC for a while. If you guys like
>it, I can send a patch.
>
>For clang it prints quite a nice overflow warning:
>
>tst.c:59:9: warning: implicit conversion from 'int' to 'u1' (aka 'unsigned _BitInt(1)') changes value from 2 to 0 [-Wconstant-conversion]
>   59 |         u1 r = 2;
>      |            ~   ^
>
>Thanks,
>Yury

No, for a whole bunch of reasons.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ