From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 3D96A325706 for ; Wed, 24 Jun 2026 05:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782280217; cv=none; b=Y07PeUrUAf9bVpgjLusJ4Yc/ugsxUXL8pkEfb+4gZpRKwmCUIbJdeN0NkMXCr/xE7bJBQaRv84FbtmkLt7vnCNAuFkP35oDayRnRVbiRquDpRNsWT4Ukqb7YrXXZxiEFpjcV4h6ysz612Qs2GeqCrco8PhKOisZMcn1qhLzSgVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782280217; c=relaxed/simple; bh=TwiVGZE/cuOmWdJJ140dlIbrb3T4IAV5EW0SjxJneQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mjKxuyB/G34okm8TnkGER98DDWVgrXUH7wwZvIYrmvszfz9tJCX3VsxL36gRZO8AjHfjSXvaVykAHdqVhpvG5NJ8sNgaLjI2yFafTOy/7WrMUJFSmVnVc239mG86926nmaW8CnzSTw75vLquUz05HcjIkG2NUC4+XzwMdA2+S8A= 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=ZaVw5Ps8; arc=none smtp.client-ip=74.125.82.169 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="ZaVw5Ps8" Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-30b6dad2382so1121076eec.0 for ; Tue, 23 Jun 2026 22:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782280215; x=1782885015; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0Mp2tjlqoqiSzDWEvjpQJpeD9swQKcxQhwmEs2BGYOM=; b=ZaVw5Ps8KlXsEv7kyu+YwAmOEgUPc1fcEnuHnuib+wzKvHccdvg44zCJums7FABzd6 zd4vSmW8k/JJ/x+dL4U75NgHGVEkTr39om1nJdCHAAKgOtPT4GgTrcFz4iHKY1AsReVF OG499ISseuD875no3COYjW2ksW2daFd5inRZa+P37LPUCjaJtSJLtyReTZofV3rkIRGU XDCaUPBUNzcDS3x3LXhYw6nDLFB0rxVm07jTJzNs9irEbaOBySUZ7ZKWgwjpcIctl6Sg divKpOjWy0hO8KanVkDmhIkLqmf4I2qS+O0SCRGqQZ6t3sWmtRdOam2QwOLpxRguU9JF lA2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782280215; x=1782885015; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0Mp2tjlqoqiSzDWEvjpQJpeD9swQKcxQhwmEs2BGYOM=; b=TuhJXfECE9Z2X6MZgkKnBkGC/3MTiYw/86Emkz9c89/8xDpxGle/NIpCqFdYKReTbe ssfyfU2vBKKqlWFOKEtC9MLNY8kixOTXhgETiCbYuVghw1yW2cswmDO3RvWKenhKMqW2 9dtOyXjcTZvpvs1qBmbTskqtiSPmQHoL1C1UZKmXi7iIz8mI/vIgq/gMoMfBSsUaRdTJ j+qOhQGH5hl7kVjzS4oWk12lzpBDNJpNqKl6wTbDUyaxO8ur/dPn67IYKebzX3EPecyD ZPxMUT4C8kApYFDro+qaS/29jzIpjSxncSNfY7blmbx+Lx3nEHcASLHMlrC0Iq+Mouyj I20Q== X-Gm-Message-State: AOJu0Yw+EHIfXri8cxNOEwd0bx87X7BxJOiHpxHewRRIhMdWTqBOoojH 9vULIDG9q5+QO6I7c7iHnFTbBg1AyIeOe8i2ntWh1oV1hGWRchv3uFQi X-Gm-Gg: AfdE7ckQzlQA9J8b46/4Msg1b7ySO8ZkBHwXFMfSuYMoIwE53XxZoNj0XSwR4tOGYsk gvRhlDtBXzLnHeNYUtNF/wexEBgZtbelv57GFgT8RLieme6rIYvp7RU8y7wNXbDRdkceTIicokO Ly/95I2nWx1NJ/XGtDi21z59hKmoJmn+GtB0cd/tDSgvqKDtYt5CvdQZMurM3N9f4UO+0Fn6npr 7KWJOgKQ548W8BeuQc19xm1oN4VT3DwNIx+M4ab+tMQQlBcdpcFn52X3IGBhyEAk4q2xcSa9aPB kow8T3TzJlYNVESv/WaxKSL0045QONOLu/65n36CPwYPo4vEJFgQBhpUTUl1GGUPYc+1d4/7nDB H1J/xPtL+yJNe7kx9LzFzVukk+dQgcIl/6Li6BLwZcuAY9ZBGh8yNWWfKlxFPKJOXv2kzomynU1 BPVYHWl65RKirGf4PSuvS3UCIjN7MVuKVR7mFUliBaLadwHucaIDRCmH/gXpEvHnyFkH1JlYZyq eRL X-Received: by 2002:a05:7300:3242:b0:2be:833c:149d with SMTP id 5a478bee46e88-30c58cde733mr5020377eec.28.1782280215291; Tue, 23 Jun 2026 22:50:15 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:6026:1e6d:4a80:9bd0]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c430553d1sm14073419eec.11.2026.06.23.22.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 22:50:14 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Jiri Kosina , Benjamin Tissoires Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/4] Input: defer handler's start() until device is opened Date: Tue, 23 Jun 2026 22:50:06 -0700 Message-ID: <20260624055008.2494980-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog In-Reply-To: <20260624055008.2494980-1-dmitry.torokhov@gmail.com> References: <20260624055008.2494980-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When registering an input handle, handler->start() is currently called immediately. However, the input device might not be fully opened or ready to process events at this stage, meaning any state synchronization events (like setting LED states) injected by the handler's start method might be dropped. Move the handler->start() invocation to input_open_device(). If it is the first handle opening the device, start() is called after the driver's open() method has successfully completed and the device is fully prepared. To facilitate this, factor out the device startup logic (calling driver's open and starting polling) into input_start_device(). For passive observer handlers, their start() method is also deferred until the handle is opened. Since opening a passive observer handle does not start the underlying hardware device, their start() method is called immediately upon opening, regardless of whether the device is active. Fixes: c7e8dc6ee6d5 ("Input: add start() method to input handlers") Signed-off-by: Dmitry Torokhov --- drivers/input/input.c | 45 +++++++++++++++++++++++++------------------ include/linux/input.h | 5 +++-- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index c2a038d31beb..0a95cbdc467e 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -568,6 +568,28 @@ void input_release_device(struct input_handle *handle) } EXPORT_SYMBOL(input_release_device); +static int input_start_device(struct input_dev *dev) +{ + int error; + + lockdep_assert_held(&dev->mutex); + + if (dev->users++ == 0 && !dev->inhibited) { + if (dev->open) { + error = dev->open(dev); + if (error) { + dev->users--; + return error; + } + } + + if (dev->poller) + input_dev_poller_start(dev->poller); + } + + return 0; +} + /** * input_open_device - open input device * @handle: handle through which device is being accessed @@ -586,21 +608,9 @@ int input_open_device(struct input_handle *handle) handle->open++; - if (handle->handler->passive_observer) - return 0; - - if (dev->users++ || dev->inhibited) { - /* - * Device is already opened and/or inhibited, - * so we can exit immediately and report success. - */ - return 0; - } - - if (dev->open) { - error = dev->open(dev); + if (!handle->handler->passive_observer) { + error = input_start_device(dev); if (error) { - dev->users--; handle->open--; /* * Make sure we are not delivering any more @@ -611,8 +621,8 @@ int input_open_device(struct input_handle *handle) } } - if (dev->poller) - input_dev_poller_start(dev->poller); + if (handle->open == 1 && handle->handler->start) + handle->handler->start(handle); } return 0; @@ -2662,9 +2672,6 @@ int input_register_handle(struct input_handle *handle) */ list_add_tail_rcu(&handle->h_node, &handler->h_list); - if (handler->start) - handler->start(handle); - return 0; } EXPORT_SYMBOL(input_register_handle); diff --git a/include/linux/input.h b/include/linux/input.h index 3022bb730898..f7a2cfad5448 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -284,8 +284,9 @@ struct input_handle; * @connect: called when attaching a handler to an input device * @disconnect: disconnects a handler from input device * @start: starts handler for given handle. This function is called by - * input core right after connect() method and also when a process - * that "grabbed" a device releases it + * input core when device is open and ready to process events, + * and also when device is uninhibited or when a process that "grabbed" + * a device releases it * @passive_observer: set to %true by drivers only interested in observing * data stream from devices if there are other users present. Such * drivers will not result in starting underlying hardware device -- 2.55.0.rc0.799.gd6f94ed593-goog