From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47CC34519A4 for ; Wed, 29 Jul 2026 18:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785350086; cv=none; b=jylkqeHjoZrhRiTukEYKwOxiTOKt5P7+jYlWDjtLmC9fHFr6I9JUkJ/99ML0aU83X2gWX/JEN8Se/liuI2FPllVQd/6oyUf87LM3jQP0tmVNa7eSgEt6HuBqEryh+We5Lqb2DLJWzn/bgyjTCkp/x4AOQGk+T7GlYpkQYaFYGm8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785350086; c=relaxed/simple; bh=c2TsB0jY1H8c4jyzK0RgzjvEkLN7ODWjeKPNPAnP1T4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pdSErLq3Gp6rPIH99476GjpQH5XThk5S31o7EettGhQADP6+D1z3RgsGkfD/0uzjWqXm0kPbQGugVRhKwN76XLPlQx2HnWX132TYFgyNJsmVYl3kYhkv6LNJISuWnfRoo06XopJH/T2rRn+gqWy+NnLtX5huSKna6B9bBSOhSCE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XxS03VVZ; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XxS03VVZ" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2caed617615so16197415ad.3 for ; Wed, 29 Jul 2026 11:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785350081; x=1785954881; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ng6gcsobGxCVjmyl427Ar8FyFTwKr2tmMEzIY0pxgxQ=; b=XxS03VVZnMRzd8zYyYK3MNqHo+8NO3N/6SWmkv6rGpQzCcECWO/kEDxwSCllmpbBT6 Tv6Iwlm4Kvl4XtigwpqoJPV4iooPF0fBzl/XqlefA5h5ZWZRaxenCGhQZykB+qgmPuCs ZB6+y3ZXIJG3WxVGh19syNLJT4JPGBfEtoFat5eyRHCRS2LMA/fM+LqlgeI7dvoeXfVK nqWs44G1VsoKOaAaPHvnKJ7zbkWquJqktWLQSlNMC3S4ZcNtaRg4byAyFQq4rgj4uT3W mGpov1Mr1vTOLauWy5RkMmaZpfE29vPzEgIiFeqBeNpntobjEr2caetFsmDDEYuO7QMv ri1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785350081; x=1785954881; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ng6gcsobGxCVjmyl427Ar8FyFTwKr2tmMEzIY0pxgxQ=; b=R3Ng/xsEh45tlxbaugM6UJ73Q8FgGd4XiMijNFapkPFItogQwvukuoKVwu45Pt/74v XotIasVCpsnlD4zFGMVDLzLeGe2wNOz7s62Z7NfjuY1gDyJmMGrnfBUdZx04NqxOKuq8 jea1j9wuUDNiVBPdxYRU5rFuX9a72cqDc5Ivt3q4nFu/Wj8AnMoqLQ/MMdXaq1V0kqk8 6bMFhYAjnNovSne1yN05k4/lUHiXzYZdCkSovcyN3R2E7OVevi8tgXwZ8eynG6dF3/9N NsClRigkmP3iflMYxPap5OoDkSNWFSnqqLccMWo+KBhLguUNirF5na735xksW7mus6DJ e9hg== X-Forwarded-Encrypted: i=1; AHgh+Rru844h0UiWJYTYQcmE3/gihUrqzIzq9k3OGsZtEMbcUrlVqv9UCUwSWp0J45v8zkq8k4dam15KQsHwMeU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7uXDcd7cj4B95G8rnMbpNqLCr6xrGAQDmlJihp7uI9izpZJdE BnRcqa9zOFIWMnSwyLkIeg7k12QEbZCQ7o7miYKPmfTVnsTsv0dbnPPd X-Gm-Gg: AR+sD10SUkHDNXmkJOT9N/afL2aEZuzg4VyRrAksh2lM04ri1F/J+cBBxTiJ+yKOXnw kMnRdNr6b6VXnf9oNsyH5UKW9Va9ke+vhTpthmVfzvHl5p1s3mf+1QuKE17ES62ygMQQbRoc9+1 SIHRrfGOv/08LLv7XNBfSIw+8DUZwLpnZGS21P1mjsBBkWr6F4ptSD5oCm3LCIF4RU5VJ02h50p O0hLjCtcXAoTGWMq4MH/HVf9TMtvonOLu58TjxASWOjUhSm1bs7c00R65K0ynMDl3z1Eyb6gG/W Cs0FGyYqZ/cBbFK0mZeNFDVIssLwdwwyiV1m+11uKno/VHqb1oCIbqa2xdlkNZkaOCqqiV9II7c mFNMrx+9nuqbxGjC0rU5SDJ98+sjdbxxAdL6EenAptqzq0wEenLmCYjf3k5s+V6R4VM2RvzBCwe OLXrY8ClRKZ6sxZOXukklL4R4mZBEi+wYtLK0qNGu/7xw3zjCott8tzdxO273vgFknTWmqhOb4P rDj/mTeFLgSyUpxDQh/ayKqvfw5dFZjciDSZ42x3g== X-Received: by 2002:a05:6a21:99a6:b0:3bb:2883:a723 with SMTP id adf61e73a8af0-3c8ba5b9c38mr8511518637.35.1785350081331; Wed, 29 Jul 2026 11:34:41 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:7d64:4b7a:74dc:6d35]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31504d37368sm22611947eec.22.2026.07.29.11.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2026 11:34:40 -0700 (PDT) Date: Wed, 29 Jul 2026 11:34:38 -0700 From: Dmitry Torokhov To: "zhangliuyang.zly" Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Input: evdev: drain queued events before reporting device removal Message-ID: References: <20260729092753.1596400-1-zhangliuyang.zly@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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