public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff LaBundy <jeff@labundy.com>
To: "Tomáš Mudruňka" <tomas.mudrunka@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] Fix freeze in lm8333 i2c keyboard driver
Date: Thu, 27 Apr 2023 13:47:03 -0500	[thread overview]
Message-ID: <ZErDJxLszj0ZRHXa@nixie71> (raw)
In-Reply-To: <CAH2-hcLOA0ECg7ubKh_r9BryRuGPjJ1Cv1ErUpMmQ+Yag5qnWA@mail.gmail.com>

Hi Tomas,

On Thu, Apr 27, 2023 at 10:13:22AM +0200, Tomáš Mudruňka wrote:
> Hello, thanks for your notes.
> 
> > This is the right idea. I am sort of splitting hairs here, however I
> > think it makes sense to place this read before the IRQ is requested
> > and not after.
> >
> >
> > As written, there is room for an ever-so-tiny race condition wherein
> > the IRQ is asserted just after it is requested. Before the threaded
> > handler has run however, the new read in probe swallows the IRQ status
> > before the threaded handler can read it and react to errors.
> 
> In fact i believe quite the opposite case to be true.
> If i read before registering IRQ there will be ever-so-tiny race condition that
> would allow to miss the edge (exactly the bug this patch is fixing,
> but limited).

I thought the original problem is that the IRQ is already low by the time
the driver loads. Since a high-to-low transition (i.e. falling edge) is
never witnessed, the handler is never called to read the status and allow
the IRQ to go high again. Therefore, key events are gone forever.

The concern you mention is simply that of not responding to key events
until the interrupt handler is registered; there is no way around that.
Any event that occurs before then is off the table. Instead, we can only
make sure that none of those prior events place us in a bad state.

> 
> In the case you describe the worst scenario is likely that the interrupt handler
> will be called only to re-read status and immediately return on this condition:
> 
> if (!status) return IRQ_NONE;

Right, I am simply saying this is one key press that could have been
preserved. As a matter of principle, once the interrupt handler is live,
you should not disturb the precious read-on-clear registers on your own
without concurrency protection. It is much more common to clear suprious
interrupts and _then_ make the handler go live.

> 
> > Also, I think you should at least capture and evaluate lm8333_read8()'s
> > return value as is already done for the calls to lm8333_write8().
> 
> Well. If you think this will bring any benefits, i might as well just call
> lm8333_irq_thread() instead of lm8333_read8()
> Would that be acceptable solution?

Looking at the datasheet, it seems this devices builds up scan codes in
a FIFO. To protect against the rare case in which this dummy read includes
actual data, perhaps it is better to call lm8333_irq_thread() instead of
lm8333_read8() so that the FIFO is flushed.

> 
> Tom.

Kind regards,
Jeff LaBundy

  reply	other threads:[~2023-04-27 18:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 13:00 [PATCH] Fix freeze in lm8333 i2c keyboard driver Tomas Mudrunka
2023-04-25 15:39 ` Jeff LaBundy
2023-04-25 16:49   ` [PATCH v2] " Tomas Mudrunka
2023-04-27  0:41     ` Jeff LaBundy
2023-04-27  8:13       ` Tomáš Mudruňka
2023-04-27 18:47         ` Jeff LaBundy [this message]
2023-04-28 10:09       ` [PATCH v3] " Tomas Mudrunka
2023-04-28 10:20       ` [PATCH v4] " Tomas Mudrunka
2023-05-03  3:02         ` Jeff LaBundy
2023-05-03  8:54           ` Tomáš Mudruňka
2023-05-03 15:32             ` [PATCH v5] " Tomas Mudrunka
2023-05-04  1:44               ` Jeff LaBundy
2023-05-11 23:44                 ` Dmitry Torokhov
2023-05-12 16:54                   ` Jeff LaBundy
2023-05-12 16:55                   ` Tomáš Mudruňka
2023-05-12 17:28                     ` Jeff LaBundy
2023-11-14 12:30                       ` [PATCH v6] " Tomas Mudrunka
2023-12-14  2:24                         ` Jeff LaBundy
2023-12-15 15:56                           ` [PATCH v7] " Tomas Mudrunka
2025-02-19 14:51                             ` Tomas Mudrunka
2023-04-26 23:16   ` [PATCH] " Dmitry Torokhov
2023-04-27  0:27     ` Jeff LaBundy
2023-04-27  8:19       ` Tomáš Mudruňka
2023-04-27 18:54         ` Jeff LaBundy

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=ZErDJxLszj0ZRHXa@nixie71 \
    --to=jeff@labundy.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tomas.mudrunka@gmail.com \
    /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