From nobody Sat Jun 13 01:44:02 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 4FA85423A6C for ; Mon, 11 May 2026 16:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515267; cv=none; b=NAReHXg5Jka5+8qx5OadNNQKzZmyj3EFONtNOinjwk1mvyOi/lN/wkZtiy0zc6FoHtZuqEB2EHoCfc47C1M1yV/6Z5Sjp9qxwvqTfZiV6c2kpZ0d6oBVb1P8W5vb6drftu9KyS3yAvmvnXuVgsbIiZALrKroGtDi+1Me2/Qv4Ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515267; c=relaxed/simple; bh=VE4Q1ZCwZKf4fv9nouGr+jDAoRVmu5G1nUzA/KgWMV0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hfmmrHlaV94O+3hT5nj8SSgePFlzDA2I9o78riMPfrrzXy1asqcOZb3Ve48E+jBrzHMiOuin5g+qifxU4eKWch1X0iaz1sGHCianI396Ou2IjOBJzZrTsuLuJTmOhc3FLQuyR2jAoYx2q2Bkdrxi9qVx/Fm2UtFmcJL8v8U7aMU= 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=QZhZGqDI; arc=none smtp.client-ip=185.171.202.116 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="QZhZGqDI" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id D249BC5E14B; Mon, 11 May 2026 16:01:54 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 45B0D60646; Mon, 11 May 2026 16:01:05 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0A2A211AF9F2B; Mon, 11 May 2026 18:01:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778515262; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=HbCCxTz9cn4uJyApC9R5AwO+H7RfGmQna7LBbuaMc5s=; b=QZhZGqDIETFQCP9Ud/9yGnt8M4zlCu5hFmlBdbHBWLiJ3AivdMDwOIOjmHO6Sfz1u2DNpv oT+1lFpOjDVmK7iM5eK+QPOht1+84hN8Z3LuR6y2XEzH6zIhuzXHndE0aHyZaTA007P6bm c22qnUt0HogEZTsMlerJlNafHUGlL9w0XVjipHB8NFrTL0MxPh7KGmMaMAb5UGSC5hfJ76 9W8u35+reWOnKVCScvG9xlDyebbiO5kUo7WNL67llRcHFIYCGim7DXOdXpZcBZ95mdoSPG s3MhpfkFKzlGCME7v0AYoaENYiUsv0oNsSQPDLfHfogfl+2GlweLNbSMYZoZ+w== From: Herve Codina To: Andrew Lunn , Rob Herring , Saravana Kannan , Wolfram Sang , Peter Rosin , Andi Shyti Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Daniel Machon , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH v7 1/3] i2c: core: Introduce i2c_get_adapter_physdev() Date: Mon, 11 May 2026 18:00:48 +0200 Message-ID: <20260511160051.34700-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260511160051.34700-1-herve.codina@bootlin.com> References: <20260511160051.34700-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" The physical device providing an I2C adapter is the device that calls i2c_add_adapter() or variants and i2c_del_adapter(). Most of the time this physical device is the parent of the adapter device. Exceptions exist with i2c muxes. Indeed, in case of i2c muxes, the parent of the mux adapter device points to the adapter device the mux is connected to instead of the physical of this mux adapter. Introduce i2c_get_adapter_physdev() and a new physdev field in the adapter structure in order to ease the adapter physical device retrieval. Signed-off-by: Herve Codina Reviewed-by: Andi Shyti --- drivers/i2c/i2c-core-base.c | 16 ++++++++++++++++ include/linux/i2c.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 9c46147e3506..59214f0c84ec 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1919,6 +1919,22 @@ struct i2c_adapter *i2c_get_adapter_by_fwnode(struct= fwnode_handle *fwnode) } EXPORT_SYMBOL(i2c_get_adapter_by_fwnode); =20 +/** + * i2c_get_adapter_physdev() - Get the physical device of an adapter + * @adapter: the adapter to get the physical device from + * + * Return: + * Look up and return the &struct device corresponding to the device suppl= ying + * this @adapter. + * + * The user must call put_device() once done with the physical device retu= rned. + */ +struct device *i2c_get_adapter_physdev(struct i2c_adapter *adapter) +{ + return get_device(adapter->physdev ?: adapter->dev.parent); +} +EXPORT_SYMBOL(i2c_get_adapter_physdev); + static void i2c_parse_timing(struct device *dev, char *prop_name, u32 *cur= _val_p, u32 def_val, bool use_def) { diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 20fd41b51d5c..dff04d20cafe 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -744,6 +744,7 @@ struct i2c_adapter { int timeout; /* in jiffies */ int retries; struct device dev; /* the adapter device */ + struct device *physdev; /* the physical device */ unsigned long locked_flags; /* owned by the I2C core */ #define I2C_ALF_IS_SUSPENDED 0 #define I2C_ALF_SUSPEND_REPORTED 1 @@ -911,6 +912,8 @@ struct i2c_adapter *i2c_get_adapter(int nr); void i2c_put_adapter(struct i2c_adapter *adap); unsigned int i2c_adapter_depth(struct i2c_adapter *adapter); =20 +struct device *i2c_get_adapter_physdev(struct i2c_adapter *adap); + void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool = use_defaults); =20 /* Return the functionality mask */ --=20 2.54.0 From nobody Sat Jun 13 01:44:02 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 A432B425CC2 for ; Mon, 11 May 2026 16:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515270; cv=none; b=H+NzcPTEQwBmqhdMdJJhvoEfu0qRANXRyaqKnQt1jgnsUQ86tJLZ2MiCWXo+k2zspX02XVWlNxteA+1jye4Z39xrvF/6DYRynyRD0WueyV9oJXj6u9bvFoecTvf1DSgTCcbtIJdFwkV9t6+Iuthh9yDweTIUnWbIw2HUZuuiuZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515270; c=relaxed/simple; bh=AWzsAlFki5r8/Nzxjbdv5ewKshsRLiRR79F5oNS5n7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MaGfLsrHYKoY1QXq320N1QxmlUh7cOFb4iOet5sX0RD0C4OknXJg4BNAu0BOx146ztCmFzm4+K8gQpsTV4o1kg8mTVvmrxLgGARBX4EX2e0pFEYj1xvHtCVXJP/u2SF7/0w8SkXiaqY/7r6mj2S0YH8bdba2nMTnrKIA1jOcuNA= 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=K9wkb9/q; arc=none smtp.client-ip=185.246.84.56 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="K9wkb9/q" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 867421A350A; Mon, 11 May 2026 16:01:07 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5B22060646; Mon, 11 May 2026 16:01:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B826211AF9F2C; Mon, 11 May 2026 18:01:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778515266; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=qeSVgRzzcRZSwyW0NgN4yrI69j7Xls5GCIYU5hWpnG0=; b=K9wkb9/q9fuU2uczvMj+HYG1Pdwj1oVvky70rRYoqwkeSgNBPN51NV5QcjyLeeL8ZZmvfB 3oN4TauBhir9N7dTS6A/CiGIq/4WqycUj+pRoKICpeuIUFLTqzEVz5VN5n3wpKWi1EcrKg Inuoi5B3+Qy8ZWwK9IJcniHNiyahIlobudya4zL+tuzx26ubJmLNaiik65nn/EiNS3gHpG b9+drRtF75W1NtZspMvtpwUELzwpQ+jp9kYS4dCpFKEPkiKqcUiWWbDq+Z5Df6ddeDRO45 292BiMOIUVeq+jJbcJeKbYGB/I+wj6VGnfHJ8rZaeQinyLwwUfXoPI4rAGDbRg== From: Herve Codina To: Andrew Lunn , Rob Herring , Saravana Kannan , Wolfram Sang , Peter Rosin , Andi Shyti Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Daniel Machon , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH v7 2/3] i2c: mux: Set adapter physical device Date: Mon, 11 May 2026 18:00:49 +0200 Message-ID: <20260511160051.34700-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260511160051.34700-1-herve.codina@bootlin.com> References: <20260511160051.34700-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" For i2c muxes, the parent of the mux adapter device is the adapter device the mux is connected to. This parent is not the physical device related to the mux adapter. Indeed, the physical device of the mux adapter is the mux device itself. Fill the adap.physdev with the mux device. Signed-off-by: Herve Codina Reviewed-by: Andi Shyti --- drivers/i2c/i2c-mux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index 681a201c239b..f4e73e7a0e33 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -315,6 +315,7 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, priv->adap.algo =3D &priv->algo; priv->adap.algo_data =3D priv; priv->adap.dev.parent =3D &parent->dev; + priv->adap.physdev =3D muxc->dev; priv->adap.retries =3D parent->retries; priv->adap.timeout =3D parent->timeout; priv->adap.quirks =3D parent->quirks; --=20 2.54.0 From nobody Sat Jun 13 01:44:02 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 D039543C057; Mon, 11 May 2026 16:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515272; cv=none; b=nnJHiH7S46SndBZmE0teWYpnAnEr48LKhpDgM5BQXRfCQU6yPuZ+uShW4ooJ7H/sPEVo9fDI+6VAa4cbZgh7PrwSbgQidvgc5AgE2CxMrAB+tMIVVeD0obXsDawpJ9jFK3/0e+a2GIIOj+u9TmjEXPguShyYJTyVTBMEnsTQY5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515272; c=relaxed/simple; bh=SbZ3GmM5UUa/He8gMXpnY22lMxFwiOeZKOZqNEyF7o4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VwnP7Jbkv3WgM8VLRkbzmhHe6CtDowVhwZv9Dco+sTO6fPOZD0hP3kXxUeiqNJ8238NcXd6yQn7CSrpJhJKgSEKe6YdoPlRq77iDdJmJrLBCwpfiTyrr/1IZSud36kaQmkkewk0/OYgD2ZIvXUkKN/9EZb1G8i5I0GPkXtvjexY= 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=ASMKxkwF; arc=none smtp.client-ip=185.246.84.56 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="ASMKxkwF" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id B644C1A1DD5; Mon, 11 May 2026 16:01:09 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8ADC960646; Mon, 11 May 2026 16:01:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id F1C4A11AF9F31; Mon, 11 May 2026 18:01:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778515268; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=+2/a7z4kjBKpmKEpMhtyITZXp8jZqoDa9BwRgh4CNNs=; b=ASMKxkwF2s0ZzaMkd3geI4FUFa54dU9x36pDKG1Y8T9y8IDCVYRWt4yjUfQ5smvOV5lKCU eOHxx9Q6sKGiUvVlW3A9od0MVqR0lnX6Xun/h24vtlyqJOu3KkTaoN280XSG1/x2jMLf+d IERlLbeyH2DRgtxXNEduOzrLOKkpXpzdVesJCIybD2r2YUBT7KXUCsZTxrMKJY/xNX2VQU nGcBek/Y7sgMN60kgr5Ys4ilGpBL1H/GVWTU2nrb284e/8u3yWsyq66z6FLYhkIAL5nLBA LxpqZxwqvkJkJOUBgadzmFby9aGAyf1TC7eFQKkMuuuypysBYuN1bU1xTv0uzw== From: Herve Codina To: Andrew Lunn , Rob Herring , Saravana Kannan , Wolfram Sang , Peter Rosin , Andi Shyti Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Daniel Machon , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni , Herve Codina Subject: [PATCH v7 3/3] i2c: mux: Create missing devlink between mux and adapter physical device Date: Mon, 11 May 2026 18:00:50 +0200 Message-ID: <20260511160051.34700-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260511160051.34700-1-herve.codina@bootlin.com> References: <20260511160051.34700-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.54.0