From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.171.202.116 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795009260; b=nZGl9eAJoaXZ+rVmcSZNkw6//R2lELN3q+bILBln0CgKf5hXa3UEV2CCmj9UvLFFkY9R sDTKx7iiS9ck3+35lDfK1D4kJGlSQgVb9VZnkDvujKARJZDm60ZYoR0HiOBbIPO+IU1eB MTIBKUSAOLQcL03v3Nz9Fv9ShOH9XxrQxC/nS0nHLCCdLBUDf5L8zB8ClHobpmKvvFjn/ cRCS16oi3p9r4mbaWuSNvHlmIsFnq9GyqylmUYRppW5UZp1cli40VQpPs09ar6cg2ZeHj BcxH8EisI2uBDjEXHuet+Ik/28qYKs7mORpLvW1sNtK6MaWzX/cNs0mUhQ6Xgy/4fVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795009260; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=S2qC93mmpO3j7YEXCndfyVrlAonLbo+0MinHXVsL1yI=; b=CXA/0nMI73E7bVuItCwYwCnf7FhyuN+q+AAVAD+zl00J2suL0hKednrdU4GZUtWwOoI1 irq+FY8T3KIk2xQVBGfozzivPE9W2C1S41ZkoeBjlkNmUqiUD88ItDL+sRzTlp+KHHXPH 8MucO7/idG0pBK9WvV5tiC7qOr4Gyz00BdJ+H27Xoh74+JOPbdiTj7CVXx6TUEPYM3q6h kxFOZeBSGrlUButTa1r63BxJxV1PE3zGfuI/kHMOpiPYvJYVxKhRwZGDqknRGLxasIhK6 Gw0BZ334onMKaSSdJs0rhuMjecgQVm0idO7BtOoyETs9Kj1v5CEHFi5FgEaOW4QIeSw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=HCOkK50L; arc=none smtp.remote-ip=185.171.202.116 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C16B6606A33D for ; Wed, 18 Nov 2026 13:40:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C16B6606A33D 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.a=rsa-sha256 header.s=dkim header.b=HCOkK50L Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 4BDE6C4CBD9; Wed, 18 Nov 2026 13:41:03 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 7591E5FE9B; Wed, 18 Nov 2026 13:40:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1DAD811BC20A3; Wed, 18 Nov 2026 14:40:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1795009257; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=S2qC93mmpO3j7YEXCndfyVrlAonLbo+0MinHXVsL1yI=; b=HCOkK50LZvIFdVK4mwIoqaie++9WKmVL/J/+0kYnhEZZGdY34uJTG9xfYZlE2616i1DJ1N F/MyHW9jGzaI7VM08pJ9tD1hRTJE0fGwdGMUaUE+f/4QcqVGyWCX4mYlCC/ICvqf5D3NTr yQLl72BgbkdbJcIz8Tr1QCbUeu3w+9tykNW2adRfr9oa8JcQVsP0wBryWZaoJNW+NxY8RF zXdVxnuM5uKRqDFXJ43YWHTQmjvA8FhO0gijZ7G3LxcNKLu8j53/+7Vx5kdSUqRvvK/JPF Pl/Mi6CVIQkU2FTf/iIReOq+ZXO7uRk+eXjfJCjW9nxjxIMyWbBwJ7YNxntNiA== From: Herve Codina To: Andrew Lunn , Rob Herring , Saravana Kannan , Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Andi Shyti , Peter Rosin , Mauro Carvalho Chehab Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Daniel Machon , Steen Hegelund , Thomas Petazzoni , Herve Codina Subject: [PATCH v10 4/6] i2c: mux: Create missing devlink between mux and adapter physical device Date: Wed, 18 Nov 2026 14:39:13 +0100 Message-ID: <20261118133927.366482-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118133927.366482-1-herve.codina@bootlin.com> References: <20261118133927.366482-1-herve.codina@bootlin.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 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/atr 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 | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index c1836114ef56..702ccca22245 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -314,7 +314,10 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, u32 force_nr, u32 chan_id) { struct i2c_adapter *parent = muxc->parent; + struct device *parent_physdev; struct i2c_mux_priv *priv; + struct i2c_client *client; + struct device_link *dl; char symlink_name[20]; int ret; @@ -382,6 +385,47 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, ACPI_COMPANION(muxc->dev), chan_id); + /* + * 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 + * downstream channel adapters before removing the physical device + * (supplier) which handles the i2c mux upstream adapter. + */ + parent_physdev = i2c_get_adapter_physdev(parent); + client = i2c_verify_client(muxc->dev); + if (!parent_physdev) { + dev_warn(muxc->dev, + "no physical device for the parent adapter, skip device link\n"); + } else if (parent_physdev == muxc->dev) { + /* + * The parent physical device is the mux device itself. + * Skip the device link + */ + put_device(parent_physdev); + } else if (client && client->adapter == parent) { + /* + * The mux device is an I2C client on the parent adapter. + * i2c_del_adapter(parent) will unregister it and remove + * its downstream adapters before waiting for the parent + * adapter to be released. No device link is needed, and + * adding one would make the driver core unbind the mux + * before the parent physical device's .remove() callback. + */ + put_device(parent_physdev); + } else { + dl = device_link_add(muxc->dev, parent_physdev, + DL_FLAG_AUTOREMOVE_CONSUMER); + if (!dl) { + dev_err(muxc->dev, "failed to create device link to %s\n", + dev_name(parent_physdev)); + put_device(parent_physdev); + ret = -EINVAL; + goto err_free_priv; + } + put_device(parent_physdev); + } + if (force_nr) { priv->adap.nr = force_nr; ret = i2c_add_numbered_adapter(&priv->adap); -- 2.56.0