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: <88282a0514984e2b943628f1476c3bbd@AcuMS.aculab.com>
Date:   Mon, 9 Nov 2020 10:20:42 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Andy Shevchenko' <andy.shevchenko@...il.com>,
        Jiri Slaby <jirislaby@...nel.org>
CC:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "Greg Kroah-Hartman" <gregkh@...uxfoundation.org>
Subject: RE: [PATCH v1 1/3] vt: keyboard, use GENMAASK()/BIT() macros instead
 of open coded variants

From: Andy Shevchenko 
> Sent: 09 November 2020 10:10
> 
> On Mon, Nov 9, 2020 at 11:57 AM Jiri Slaby <jirislaby@...nel.org> wrote:
> > On 06. 11. 20, 17:06, Andy Shevchenko wrote:
> > > On Fri, Nov 6, 2020 at 5:35 PM David Laight <David.Laight@...lab.com> wrote:
> > >> From: Andy Shevchenko
> > >>> Sent: 06 November 2020 14:36
> > >>>
> > >>> There are few places when GENMASK() or BIT() macro is suitable and makes code
> > >>> easier to understand.
> 
> Thanks for the review, my answers below.
> 
> > >> ...
> > >>> -     if ((d & ~0xff) == BRL_UC_ROW) {
> > >>> -             if ((ch & ~0xff) == BRL_UC_ROW)
> > >>> +     if ((d & ~GENMASK(7, 0)) == BRL_UC_ROW) {
> > >>> +             if ((ch & ~GENMASK(7, 0)) == BRL_UC_ROW)
> > >>>                        return d | ch;
> > >>
> > >> Do you really think that makes it more readable?
> > >
> > > Yes. Because this tells explicitly how many bits are used for metadata
> > > vs. data.
> >
> > No, because ~0xff is clearly what it is. GENMASK(7, 0) is:
> > 1) longer to read & parse by brain with result: "GENMASK undefined"
> > 2) terrible in this particular use case
> 
> Maybe #define with a proper name can bring some shed of light here?

Possibly.

> > Another instance of an even worse switch:
> > -               if (arg & ~0x77)
> > +               if (arg & ~(GENMASK(6, 4) | GENMASK(2, 0)))
> 
> It exactly shows what bits we are accepting and what are not. 0x77 you
> need to translate to the bitmap and then figure out the bit numbers.
> This is error prone as shown in some cases.

We all know what 0xff and 0x77 mean.
It is ingrained from years of writing software.

Now it may be that the 0x77 is related to masking off
some other bit values.
In that case you could have a named constant based on the
names of the other bit values.
But if you are putting in simple constants there is nothing
wrong with hex.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ