All of lore.kernel.org
 help / color / mirror / Atom feed
From: 'Andy Shevchenko' <andy.shevchenko@gmail.com>
To: David Laight <David.Laight@aculab.com>
Cc: Jiri Slaby <jirislaby@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v1 1/3] vt: keyboard, use GENMAASK()/BIT() macros instead of open coded variants
Date: Mon, 9 Nov 2020 12:44:43 +0200	[thread overview]
Message-ID: <20201109104443.GW4077@smile.fi.intel.com> (raw)
In-Reply-To: <88282a0514984e2b943628f1476c3bbd@AcuMS.aculab.com>

On Mon, Nov 09, 2020 at 10:20:42AM +0000, David Laight wrote:
> > On Mon, Nov 9, 2020 at 11:57 AM Jiri Slaby <jirislaby@kernel.org> wrote:
> > > On 06. 11. 20, 17:06, Andy Shevchenko wrote:

...

> > > 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.

Oh, do you expect one with curiosity and absence of C/Linux kernel experience
may not try to understand the code easily? We have real examples of such
curious people, and honestly I admire them much more than people who knows what
0x77 or 0xff means in every case by heart (yes, at some point of time I used to
program Z80 directly from my mind in assembly, but does it really a must for
a curious reader / contributor?).

> 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.

It makes code harder to understand. Besides that GENMASK() and BIT() avoids UB
which is often happen when programmers doesn't think about (yes, we may discuss
about poorness of C standard etc, but this what we have now).

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2020-11-09 10:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-06 14:35 [PATCH v1 1/3] vt: keyboard, use GENMAASK()/BIT() macros instead of open coded variants Andy Shevchenko
2020-11-06 14:35 ` [PATCH v1 2/3] vt: keyboard, replace numbers with \r, \n where appropriate Andy Shevchenko
2020-11-09  9:58   ` Jiri Slaby
2020-11-06 14:35 ` [PATCH v1 3/3] vt: keyboard, make use of assign_bit() API Andy Shevchenko
2020-11-09  9:58   ` Jiri Slaby
2020-11-06 15:33 ` [PATCH v1 1/3] vt: keyboard, use GENMAASK()/BIT() macros instead of open coded variants David Laight
2020-11-06 16:06   ` Andy Shevchenko
2020-11-09  9:57     ` Jiri Slaby
2020-11-09 10:10       ` Andy Shevchenko
2020-11-09 10:20         ` David Laight
2020-11-09 10:44           ` 'Andy Shevchenko' [this message]
2020-11-09 10:27         ` Andy Shevchenko
2020-11-09 10:41           ` Jiri Slaby
2020-11-09 10:54             ` Andy Shevchenko

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=20201109104443.GW4077@smile.fi.intel.com \
    --to=andy.shevchenko@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.