From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "zhangliuyang.zly" <zhangliuyang.zly@bytedance.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Input: evdev: drain queued events before reporting device removal
Date: Wed, 29 Jul 2026 11:34:38 -0700 [thread overview]
Message-ID: <ampG4-NiSpXev-Vu@google.com> (raw)
In-Reply-To: <20260729092753.1596400-1-zhangliuyang.zly@bytedance.com>
Hi,
On Wed, Jul 29, 2026 at 05:27:53PM +0800, zhangliuyang.zly wrote:
> When an input device is unregistered, the input core calls
> input_dev_release_keys() and sends a SYN_REPORT before closing the input
> handles. This is intended to deliver synthetic key-up events for keys that
> are still pressed when the device disappears.
>
> However, evdev_read() currently checks evdev->exist before draining the
> per-client event queue. If evdev_disconnect() marks the evdev node dead
> before userspace reads the queued synthetic release packet, read() returns
> -ENODEV immediately and the queued key-up events are lost from userspace's
> point of view.
>
> This can happen on Android with USB OTG 2.4G keyboard receivers. The input
> core generates the release event during disconnect, but Android EventHub
> may observe the evdev hangup/removal first and then fail to read the
> pending EV_KEY value=0 event. The framework then falls back to device
> reset/cancel semantics instead of dispatching a normal ACTION_UP.
>
> Allow evdev_read() to drain already queued events even after evdev->exist
> is cleared. Return -ENODEV only when the client queue is empty, or when
> the client has been revoked. Keep zero-length reads compatible with the
> previous error-checking behavior.
I'd rather Android handle devices going away properly. Input core tries
to clear the key state for its own internal purposes (sysrq handling,
etc); userspace should take care of this on its own.
Thanks.
--
Dmitry
prev parent reply other threads:[~2026-07-29 18:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 9:27 [PATCH] Input: evdev: drain queued events before reporting device removal zhangliuyang.zly
2026-07-29 9:39 ` sashiko-bot
2026-07-29 18:34 ` Dmitry Torokhov [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=ampG4-NiSpXev-Vu@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zhangliuyang.zly@bytedance.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