🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21663

[PATCH v4 18/33] Input: serio - use the compatibility driver attachment API

#21663
From: Leon Romanovsky
Date: Tue, 24 Nov 2026 09:43
72 lines
10457 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: <20261124-device-trust-core-v4-18-037eb0d17b1f@nvidia.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370182-linux-kernel-netdev=dewy.ru
References: <20261124-device-trust-core-v4-0-037eb0d17b1f@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370182-linux-kernel-netdev=dewy.ru
From: leon@kernel.org (Leon Romanovsky)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v4 18/33] Input: serio - use the compatibility driver attachment API
Date: Tue, 24 Nov 2026 11:43:49 +0200
Organization: Usenet Network
Message-ID: <20261124-device-trust-core-v4-18-037eb0d17b1f@nvidia.com>
References: <20261124-device-trust-core-v4-0-037eb0d17b1f@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4104289"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:5hMECd4f2mg59ZpzPns7WX/lXpU= sha256:OsDdBxXtg18RVUhLjKPPuPHZ8KV9cwAI5X+kQoflYQI=
	sha1:zixH0W2u/Dxo6bzVIqXrRAZN9d4= sha256:K0vOACZ2gIYXAeB1PYw/Aw7oPmySJCrDecaw60+UvAU=
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 58EC3125DE8; Tue, 24 Nov 2026 12:47:56 +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 UXWjoMI_shJt;
	Tue, 24 Nov 2026 12:47:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370182-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 03200125DEC; Tue, 24 Nov 2026 12:47:44 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 8434A3ED04; Tue, 24 Nov 2026 09:47:09 +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=1795513544;
	b=byPe0175prJUfQR5vs1R1xWdmxjBqAQsjRwF2bGJq6p5kkAQYUbA//mGN7OZ5oflkHSH
	 bqwbupBbUHz624uH+CtQ/r8+bUHnWgoUJ+DG057Dhu7p20mgHGCuRrOYi3lyymk+gcs8j
	 RUSwVZNosjSGUjL0jhj8tMJZFXcBEqKOzBZMOQzsEEqVKYxRw3kAqFKP7FPTxIse0s5Cf
	 mJYbHYdf8cVNehJOqXcNKxD4gILCg1JNZo5TDHZNt4oQ9DU1V7VUYFNpPCP35beB2tR2A
	 tdbNtmCZR6uXo2PW/jlh5EhQJzSC9JgabYHmcnFXAeldEi0iJOuHvURcodCZO6aA71Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795513544;
	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=bKMsl4kX5vXR3WUMEFhiR2m7aihJkO1s/NcVzr0CLLqVPzPwbU88jUAtqJWD1Tx8nwal
	 vEKeX60eWsvP3sOP+UbeqQD00F0yN2aBHQ7mim96/hbE8iKdBxnALUybtnuKmynVjOoiM
	 7phLXnwvLnmW+5wNNAsSNUboelgAIDhXws5IhU4jHHRb9SKrHQRn1jVfVCx4p0gtEdxQY
	 haI4pflEWpwPTWzmT4tRoSFsJZA3W2leYVn70sZK856tFJg+8RHl0jmzI3mnVcpQYnwSp
	 d3L4r1kkudpR13WGechlsPJmbur4IBeMwmWTubLiVS3+ck2TmIn62hbu1WuqWY2EzHA==
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=IJNHHCiG;
	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 AB596606E596;
	Tue, 24 Nov 2026 09:45:44 +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=IJNHHCiG
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=1795513533;
	b=sneVlvtDlSI5lGg/sgvIBUsdR7kpVLBjslyw6wwTou6zUat7yU1iGHIkNpVuAXDMWLpH
	 hQM0JMt9QPcYxRTU4JzbyBE94TKxqYmS/7qsy3c2+35RPMjBbC5rvfR2pHzuRI29KpJiO
	 6Ryn+6M/parTWuWzuaeuqWFIuoAl7/PtmNvvA8w9IvCUrsxg6B07xF4fR+3trmqF5d4+9
	 gfc07WcK5nrqNT7+w9ip3pQXh0PAVBxb1Nftud2BNawJvumYP0WbLxnMLue1E1VoQTe86
	 jdOhru3orD415fsa/ZNYo3mCEYzBnYVONlGpctqeFhPtYRcaK2d3vva/FeCk79OeTNA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795513533;
	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=z2mPQGRImZhTVsQXboflvRjJPGAVUCWtYlJX78SMego8+BMA9aLm2oF6F9h0SMEYomoy
	 aoB7LFqNbYCjfWEWnRD+IJRz/g1tGNLy+mjBXogxGkJhOyKtYMRKezsGbAqQ+VBQZ+PFz
	 lv2QyUtSlE8wWRoVRbUC79sLqnb+gISXV9udte4stzlo+9ex5zpWLva1BCqHriVj35Y4E
	 1XmV6Z4xLAKiHkeIC9jkARWwoHbZJt1W8+KSS/iowOGC+bdh74zrjUkJTxeC03Lnk3f/B
	 0IZVXMi310JlZuQYFinYcwsrOQ+fwkJnaEY3CwxsJT8s15Kt5cL98/WrXmecyVGkuqg==
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=IJNHHCiG;
	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 C2A52606B009;
	Tue, 24 Nov 2026 09:45:33 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C3EE1F000F4;
	Tue, 24 Nov 2026 09:45:32 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795513533;
	bh=ePO1HaQy6BuunjZvvPsV5K/2vWM8debo/YiENR3jWNU=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=IJNHHCiGzv0WWwdpPr1FMAlFOt8wwBxS5sXv8kmA4ekRytwPIv8fStFQiwgccPJrP
	 FJcDzCZEXAOXDaG+hW7vVoSHtCvFqsNVshNhdnEkJL8jKIzWWigshXntueRO2pXPqX
	 2D64PCUgFN2FwBt+1y7HOY4T4SFRY1TX0S+un8UcYb4OFVFHLcDWQBcn17adMbhsmy
	 /b/g/D8+J1SwD5uUGpy2mMmy0mXkKgT4/6xbQSaTcXsAgfybEHx+HIwbeRtuvdUMym
	 kTGklVtTRxr9d3w/5mJUYPzDg0/hXfrKvbszu6tItwb8wygBsOuwj8maD4SuAGbryo
	 ECFVMc6pEGaPg==
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: <20261124-device-trust-core-v4-0-037eb0d17b1f@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