🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18718

[PATCH v3 17/31] Input: serio - use the compatibility driver attachment API

#18718
From: Leon Romanovsky
Date: Wed, 18 Nov 2026 19:26
72 lines
10450 bytes
From: Leon Romanovsky <leonro@nvidia.com>

Manual serio binding holds serio_mutex, but generic sysfs probing does
not take that mutex. The two paths can race while updating driver state
or cleaning up a failed probe.

Use device_driver_attach_unrestricted() after the port ID check to
centralize binding and cleanup. Acquire the device lock with
device_trylock() to exclude generic probing, returning -EBUSY instead of
waiting while holding serio_mutex. Map legacy -1 connect failures to
-ENODEV in the probe callback so they are not reported as -EPERM, while
preserving errors returned by the attachment helper.

Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/input/serio/serio.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 54dd26249b027..f239217d7de45 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -83,26 +83,15 @@ static int serio_bind_driver(struct serio *serio, struct serio_driver *drv)
 {
 	int error;
 
-	if (serio_match_port(drv->id_table, serio)) {
+	if (!serio_match_port(drv->id_table, serio))
+		return 0;
 
-		serio->dev.driver = &drv->driver;
-		if (serio_connect_driver(serio, drv)) {
-			serio->dev.driver = NULL;
-			return -ENODEV;
-		}
+	if (!device_trylock(&serio->dev))
+		return -EBUSY;
 
-		error = device_bind_driver(&serio->dev);
-		if (error) {
-			dev_warn(&serio->dev,
-				 "device_bind_driver() failed for %s (%s) and %s, error: %d\n",
-				 serio->phys, serio->name,
-				 drv->description, error);
-			serio_disconnect_driver(serio);
-			serio->dev.driver = NULL;
-			return error;
-		}
-	}
-	return 0;
+	error = device_driver_attach_unrestricted(&drv->driver, &serio->dev);
+	device_unlock(&serio->dev);
+	return error;
 }
 
 static void serio_find_driver(struct serio *serio)
@@ -744,8 +733,10 @@ static int serio_driver_probe(struct device *dev)
 {
 	struct serio *serio = to_serio_port(dev);
 	struct serio_driver *drv = to_serio_driver(dev->driver);
+	int error;
 
-	return serio_connect_driver(serio, drv);
+	error = serio_connect_driver(serio, drv);
+	return error == -1 ? -ENODEV : error;
 }
 
 static void serio_driver_remove(struct device *dev)

-- 
2.56.1
Technical Details
Message-ID: <20261118-device-trust-core-v3-17-d655875c4bfb@nvidia.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366389-linux-kernel-netdev=dewy.ru
References: <20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366389-linux-kernel-netdev=dewy.ru
From: leon@kernel.org (Leon Romanovsky)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v3 17/31] Input: serio - use the compatibility driver attachment API
Date: Wed, 18 Nov 2026 21:26:47 +0200
Organization: Usenet Network
Message-ID: <20261118-device-trust-core-v3-17-d655875c4bfb@nvidia.com>
References: <20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2682082"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:JWBvV7BjkShxQOBibow1bjrp+5c= sha256:xFMOHAj/UIFcU2mrtMqqbfpyLYzSLWPzmsenIZtyNYg=
	sha1:Hw0Ms7uhTDMdBrkrMuLFXqBcRu8= sha256:Bn9SfXh0TVthxQYoNKwRF0Zd1p3xX0mpf/jl3FqdE7o=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 010871153A5; Wed, 18 Nov 2026 22:35:31 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.301
X-Spam-Status: No, score=-2.301 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001,
	DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id VaTjF4_gCZBH;
	Wed, 18 Nov 2026 22:35:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-366389-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id E0D9111539B; Wed, 18 Nov 2026 22:35:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id F2ABA811A3; Wed, 18 Nov 2026 19:31:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795030103;
	b=XCNn6PPIL7PbgwO+e1VEJsyvMS8ZoZs55ZONjuPHOREOd2hZF95mWH5DT5bizxh1NOl9
	 ERD0/uv6uI20kvwQ9mPIeX/mqjCa8zz+sAyWSDkf/4cbrAPiKsyQd5bmbednnSTizNZKQ
	 I94H0zqmNGSFAOvM5PTwYqE8m3QxBZzWEY2a0iM3+KN00DyYNUSxQPRY0qHKIrurq82Y5
	 Ycmgw69e4pZnvzgerfAz8eKQFDVFvt6FaGzqgti7iUegF8fCIZQWIhgsdMGy2IK+oufob
	 ia2lh3fj+LetMcOxN+VBoBqDfyjQnEXvOt9W02bsmxWgX3QUxE7CYa7gUuxoIQmLQWg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795030103;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Content-Type:X-Mailer:
	 Content-Transfer-Encoding;
	bh=ePO1HaQy6BuunjZvvPsV5K/2vWM8debo/YiENR3jWNU=;
	b=y2MsyhFC+GsKoYiBjqPdx8EEcxMpJ902WSrnowKmai2cOL1wmuyg8OzFyqS9GNCwDQyb
	 3WKD3uKrTBwrh/qjRx5bfGa9HF1HlBunNxWHlUTOiJQKLoZXlBz7s0XmuvC99tctdVcTD
	 0ubzbeBll1HiwY31Y5XicgY/o5Kf+0/Air9Cg1Xw/ebUP1zx4uZm+9GYVWxk47kJh3COV
	 RrkyhaePuwuR+TYPX/moNPoyjDueU0P9r36DU8PYLpJSxMxoZ6SNRu1S4hX+5KGD5p6Re
	 6Nh2phW3pcj4tbRdv7R00D3hqNKcbqZz3kve/n+Z1YEvhx0UG6PPQGxOylNRzMZxzGA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ijm0HvjC;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id F0821606FF61;
	Wed, 18 Nov 2026 19:28:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ijm0HvjC
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795030102;
	b=JENCuCzjGl4oD6HXKU73rYhn6YAaAxXbnjrSE7IkesQP23zWBOi05ZQMuRU4P62x2Qfw
	 VvhE/mcmV6eYCQPaRD5ThWpNggmE9P6juDKAdmRNtcgSuy3C+nITMAIRGErsRDlfvSmUV
	 Hnch90igjWToQ2Z/PJsKoga1rp3ZtYckmJ83VzFt7YxKqXI2yE8xwFs3YK1QLTy6MT47I
	 1HTTaKcdtNPmb2CQxjiBMYdacRTSzDMMbhFS8pi9gNJX3wBvCp+fkv7PMo1PnE5y4U93d
	 sJ5Jp4Rd7HTkAAnwHopEW/BaGqtvRVeadqf5JLYwWk097yyje7P6fMrL7aqf2DhRT7A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795030102;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Type:X-Mailer:
	 Content-Transfer-Encoding;
	bh=ePO1HaQy6BuunjZvvPsV5K/2vWM8debo/YiENR3jWNU=;
	b=RDdK6gDiriUryUGmu9kEsyAynEnU0oqtek4GYX82tkJ9sHoPx0ammHT7Zx6wPJpx+f13
	 UDQEZY9wdPTnwntnO8t3leWTlBNKYNnDV8GMIRgurdT06ZHcCQh2jy4wL8dxMiqHhaDpn
	 sIHNke5SgKHR1/CmchnWL7duxiZK0m4BYkz610LABtwjGk6SThP9OWmp/dYuxz3WGEBHj
	 oNiDjLkWS3++w+PKYoYgGCDgNrjkc3Lv8dO/8SYxwOxhRdkjQ7Vg/EWNXcugSJEaQIBYU
	 RfOqB/1iefWppWx4ObsX7mcbxD3wLtNC2Iw2mSdjQcqjf0ZvhYvncWVoezaWMp3I2Jw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ijm0HvjC;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 166EC60A6F61;
	Wed, 18 Nov 2026 19:28:22 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9AED1F000C6;
	Wed, 18 Nov 2026 19:28:20 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795030101;
	bh=ePO1HaQy6BuunjZvvPsV5K/2vWM8debo/YiENR3jWNU=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=Ijm0HvjCOyPj2Sz14XGqAh55LuqsbUomOOgZ/+CyYcJsyWT2xlKZfIt/W7eAFOI1H
	 0Lp7EgtnU0lqKrNd6DVcVQCMqg41Y4UgL8ih3FVULgHtVGgqTGyYI9Q/T3tAASroeJ
	 ceuB40VBCqdG/AL2VMHN4JOkQ3c6dM/d6qB3ZpprZTBgfqSh8M3Ciy1PUfC5WKioBx
	 bKB/2uY7Is496NoS7pRKe6XChnfzk/UxprutVByaTIpTetUb6cHbjEa8Ug4n+Mal/5
	 7EJ4UaG0HnXuSY1V1wpiXy9b+b98pvsCBP/4PflIFZunvhobQEXqetAAlty2EdHZc7
	 0JmA9Kiaz9mgQ==
X-Cc: linux-kernel@vger.kernel.org,
	driver-core@lists.linux.dev,
	linux-input@vger.kernel.org,
	netdev@vger.kernel.org,
	linux-wireless@vger.kernel.org,
	linux-usb@vger.kernel.org,
	linux-bluetooth@vger.kernel.org,
	linux-acpi@vger.kernel.org,
	linux-doc@vger.kernel.org,
	linux-pci@vger.kernel.org,
	iommu@lists.linux.dev,
	linux-coco@lists.linux.dev,
	Alexey Kardashevskiy <aik@amd.com>,
	Luiz Augusto von Dentz <luiz.von.dentz@intel.com>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	linux-sound@vger.kernel.org,
	Jason Gunthorpe <jgg@ziepe.ca>
X-Mailer: git-send-email 2.56.1
X-In-Reply-To: <20261118-device-trust-core-v3-0-d655875c4bfb@nvidia.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-Mailer: b4 0.15-dev-18f8f