Re: [PATCH] Input: evdev: drain queued events before reporting device removal
Dmitry Torokhov <[email protected]> Wed, 29 Jul 2026 11:34:38 -0700
| Newsgroups | org.kernel.vger.linux-input,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
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