From nobody Fri Apr 3 02:58:09 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A65C53F8DE7; Wed, 25 Mar 2026 14:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774449669; cv=none; b=Nxmc0yy3MJ+wyZy1L5haoqlsZ39WBEKjIJ3W3ewvl/vBEuXIClkWyZDkVUGetcmZWvL53GjVyxjQqUrsknIZyJSyvROrwabm4IkJgaX9GNRy1J40WdY+O9AswONVPhkaN84E+9KJymrAEs6DR4Tz+mAtmOsL1GcUoYHzcmeuqYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774449669; c=relaxed/simple; bh=uDuPgt2o/9oBQHh+Cpy7Gf83um6TASnvbhCiTbvCQdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vC5dYS6C44c08CXHiVn4h8xI68VPk4hJ/Kv7LSNTO7Ax/dpPQKAILKhwUo1gAanYIPO6k6P7mCUR9z0hw11NWS3Qy1HhUaTlLY6hIhDxdDofdIJ4bCcR0n9ZKExm9n8wQ9So+L/STUaAGyV+w2aRaukML9h+08yZPnXqXJBgGtY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=x9aXYJt2; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="x9aXYJt2" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 2FD9E4E427EF; Wed, 25 Mar 2026 14:41:05 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 05245601FA; Wed, 25 Mar 2026 14:41:05 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5F96E104513C1; Wed, 25 Mar 2026 15:40:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1774449661; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=EB2C+jRFMxDkKtJvrc3FzQhnrQCg9ZYzY6GBMb2A8G4=; b=x9aXYJt2Xgv4kB01GyPszWYFEN17VsPTuRWho3EM5oIObrs0bojHjDhISOKnG44m1DMxNq cKQJDZLmCapQChTQoa3OODYY+pV9TVmx+9r2a1wgUgaAXGCgOsYXiXVRNoih0o25MH/3Fc MGwNg9BPQmrmMvUjiRSJxCoactYMhwFr7lQUqyE9QjOGv6YC/kIA9QXZRIxrN+qsbAaGeQ aKwIxzVON7u5qPOVEvBm8Em5pWnL1+NdeOnjZHFydwFiUarG2Xc/wCG2XUwBwISErwUn2f ysLd8Zbxa66++hAPrjNqzamzw69xul/RiuxCwgrNipfI3j+0AvjiRJ2e4Ea7CQ== From: Herve Codina To: Andrew Lunn , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Kalle Niemi , Matti Vaittinen , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Michael Turquette , Stephen Boyd , Andi Shyti , Wolfram Sang , Peter Rosin , Arnd Bergmann , Herve Codina , Saravana Kannan , Bjorn Helgaas , Charles Keepax , Richard Fitzgerald , David Rhodes , Linus Walleij , Ulf Hansson , Mark Brown , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Shawn Guo Cc: Wolfram Sang , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, patches@opensource.cirrus.com, linux-gpio@vger.kernel.org, linux-pm@vger.kernel.org, linux-spi@vger.kernel.org, linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni Subject: [PATCH v6 16/27] i2c: mux: Create missing devlink between mux and adapter physical device Date: Wed, 25 Mar 2026 15:35:43 +0100 Message-ID: <20260325143555.451852-17-herve.codina@bootlin.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260325143555.451852-1-herve.codina@bootlin.com> References: <20260325143555.451852-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" When removing an i2c controller device handling an i2c bus where an i2c mux is connected to, the removal process hangs and is stuck in the wait_completion() call done in i2c_del_adapter(). The i2c_del_adapter() tries to removed the i2c adapter related to the i2c controller device and the wait_completion() is waiting for the i2c adapter device release. This release is performed when the device is no more used (i.e. refcount reaches zero). When an i2c mux is involved in an i2c path, the struct dev topology is the following: +----------------+ +-------------------+ | i2c controller | | i2c mux | | device | | device | | ^ | | | | | | | | | dev's parent | | | | | | | | | i2c adapter | | i2c adapter chanX | | device <---- dev's parent ------ device | | (no driver) | | (no driver) | +----------------+ +-------------------+ When an i2c mux device creates an i2c adapter for its downstream channel, a reference is taken to its adapter dev's parent. This parent is the i2c mux upstream adapter device. No relationship exists between the i2c mux device itself and the i2c controller device (physical device) in order to have the i2c mux device calling i2c_del_adapter() to remove its downstream adapters and so, release references taken to the upstream adapter. This consumer/supplier relationship is typically a devlink relationship. Also, i2c muxes can be chained and so, the upstream adapter can be supplied by either an i2c controller device or an other i2c mux device. In order to get the physical device of the adapter a mux is connected to, rely on the newly introduced i2c_adapter_get_physdev() and create the missing devlink between the i2c mux device and the physical device of the adapter the mux is connected to. With that done, the i2c mux device is removed before the device handling the upstream i2c adapter (i2c controller device or i2c mux device). All references are released and the i2c_del_adapter() call performed by driver handling the upstream adapter device is not blocking anymore. Signed-off-by: Herve Codina --- drivers/i2c/i2c-mux.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index f4e73e7a0e33..26470a7c2eea 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -268,7 +268,9 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, u32 force_nr, u32 chan_id) { struct i2c_adapter *parent =3D muxc->parent; + struct device *parent_physdev; struct i2c_mux_priv *priv; + struct device_link *dl; char symlink_name[20]; int ret; =20 @@ -375,6 +377,29 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, ACPI_COMPANION(muxc->dev), chan_id); =20 + /* + * There is no relationship set between the mux device and the physical + * device handling the parent adapter. Create this missing relationship + * in order to remove the i2c mux device (consumer) and so the dowstream + * channel adapters before removing the physical device (supplier) which + * handles the i2c mux upstream adapter. + */ + parent_physdev =3D i2c_get_adapter_physdev(parent); + if (!parent_physdev) { + dev_err(muxc->dev, "failed to get the parent physical device\n"); + ret =3D -ENODEV; + goto err_free_priv; + } + dl =3D device_link_add(muxc->dev, parent_physdev, DL_FLAG_AUTOREMOVE_CONS= UMER); + if (!dl) { + dev_err(muxc->dev, "failed to create device link to %s\n", + dev_name(parent_physdev)); + put_device(parent_physdev); + ret =3D -EINVAL; + goto err_free_priv; + } + put_device(parent_physdev); + if (force_nr) { priv->adap.nr =3D force_nr; ret =3D i2c_add_numbered_adapter(&priv->adap); --=20 2.53.0