From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Life is hard, and then you die" <ronald@innovation.ch>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Henrik Rydberg <rydberg@bitmath.org>,
Andrzej Hajda <a.hajda@samsung.com>,
Inki Dae <inki.dae@samsung.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Lukas Wunner <lukas@wunner.de>,
Federico Lorenzi <federico@travelground.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
linux-input@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/2] Input: add Apple SPI keyboard and trackpad driver.
Date: Tue, 16 Apr 2019 15:52:34 +0300 [thread overview]
Message-ID: <20190416125234.GD9224@smile.fi.intel.com> (raw)
In-Reply-To: <20190415230955.GA13033@innovation.ch>
On Mon, Apr 15, 2019 at 04:09:55PM -0700, Life is hard, and then you die wrote:
> On Mon, Apr 15, 2019 at 12:03:46PM +0300, Andy Shevchenko wrote:
> > On Mon, Apr 15, 2019 at 01:13:00AM -0700, Ronald Tschalär wrote:
> > > +static void
> > > +applespi_remap_fn_key(struct keyboard_protocol *keyboard_protocol)
> > > +{
> > > + unsigned char tmp;
> >
> > > + u8 bit = BIT(fnremap - 1);
> >
> > The above is UB and I'm sorry I didn't find this earlier.
> >
> > So, something like this would work
> >
> > u8 bit = BIT((fnremap - 1) & 0x07);
>
> fnremap is already constrained by the following:
"already" is a wrong word here. Compiler checks in the order of appearing, so,
for it it is UB and we need to limit bits to allowed range, up to 31 for
unsigned int.
>
> > > +
> > > + if (!fnremap || fnremap > ARRAY_SIZE(applespi_controlcodes) ||
> > > + !applespi_controlcodes[fnremap - 1])
> > > + return;
>
> and the array-size of applespi_controlcodes is constrained to the
> number of bits in u8 according to this assertion
>
> > > + compiletime_assert(ARRAY_SIZE(applespi_controlcodes) ==
> > > + sizeof_field(struct keyboard_protocol, modifiers) * 8,
> > > + "applespi_controlcodes has wrong number of entries");
>
> So I don't see that the masking buys anything new.
It buys us the follow to the standard. But gcc is clever enough to strip number
to allowed one.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2019-04-16 12:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-15 8:12 [PATCH v5 0/2] Add Apple SPI keyboard and trackpad driver Ronald Tschalär
2019-04-15 8:12 ` [PATCH v5 1/2] drm/bridge: sil_sii8620: make remote control optional Ronald Tschalär
2019-04-15 8:58 ` Andrzej Hajda
2019-04-15 23:24 ` Life is hard, and then you die
2019-04-16 5:56 ` Andrzej Hajda
2019-04-16 10:25 ` Life is hard, and then you die
2019-04-15 8:13 ` [PATCH v5 2/2] Input: add Apple SPI keyboard and trackpad driver Ronald Tschalär
2019-04-15 9:03 ` Andy Shevchenko
2019-04-15 23:09 ` Life is hard, and then you die
2019-04-16 12:52 ` Andy Shevchenko [this message]
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=20190416125234.GD9224@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=a.hajda@samsung.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=federico@travelground.com \
--cc=gregkh@linuxfoundation.org \
--cc=inki.dae@samsung.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=ronald@innovation.ch \
--cc=rydberg@bitmath.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).