From patchwork Mon Apr 7 14:55:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 878716 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 4A38A1FDA73; Mon, 7 Apr 2025 14:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744037790; cv=none; b=USyNTau8YSGRxaUjMeRJQoozndlUCfoZxaVSHMuhDfLUXTetU0uFGakw8VvUj+BaCU3+umWJhZvCNf9OtKORnzDY8tV9SiulFqMaOyo0PIxfOxsAnGya5mEo9ItYqCpgrqFCY0bMm5E7B3pbc5d5CMfC+bZypnI1I4BExkwsTJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744037790; c=relaxed/simple; bh=V5zIkGJHFQsz+4EYLMqChHFiPbdwcayQREVfLlOtELQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DR68npowsnmNUyNW+BaZ2VYWhz4xaaO+cUZ5yN28sRWrp8jeBMHomfg1e8dmsTe+OtU4FGdlyU946yIlnTkQpREbXLD/+J5YFUHmjQsujk/buV+YbjNxdKCzfocXdZVN4Vx9GEEQxuwQJc1uyDfI4dliXp6ik00m0q+yyUhSuVU= 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=WsvImHZf; arc=none smtp.client-ip=217.70.183.197 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="WsvImHZf" Received: by mail.gandi.net (Postfix) with ESMTPA id CCD0C4433E; Mon, 7 Apr 2025 14:56:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1744037785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aItmirLdEVI7NHCsRGR9Uysz/lglV3mIfktUv8r1Nvo=; b=WsvImHZf8/ypzjdPBUs2PPKIK49DxWcoSWB6Mcnww6f5MVeVYwZZQbv1IJh3RQFXicMJxy /2HQmIvz9+45kBP7THQyY6yBdYIcB+7RfOWNcnUudJB//Uts5yI1W9GOPBFWNcPXRMd1Lc 9FG/mUAbBgggzWKSB/7oCIvb/e9USVjgilXdzubN4JdIZBorlLZJhsHErJOC9mZ6fk3NNN ePAzGbupcjdoXVCQ7RAbf9QoSF8NW9il3M5LAgh0+q8S7AMx+j3I/6lElStUac0+266kFA W59HSTDgxkwMpRG3Y5OHRf0mHJGr3L/N2WtlKPMaQ/dfXZvg17ATPifcOPS84w== From: Herve Codina To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Michael Turquette , Stephen Boyd , Andi Shyti , Wolfram Sang , Peter Rosin , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Herve Codina , Rob Herring , Saravana Kannan , Bjorn Helgaas , Mark Brown , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus Cc: Wolfram Sang , Geert Uytterhoeven , linux-kernel@vger.kernel.org, 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-spi@vger.kernel.org, linux-acpi@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni Subject: [PATCH 10/16] i2c: mux: Create missing devlink between mux and adapter supplier Date: Mon, 7 Apr 2025 16:55:39 +0200 Message-ID: <20250407145546.270683-11-herve.codina@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250407145546.270683-1-herve.codina@bootlin.com> References: <20250407145546.270683-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtddtgeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefjvghrvhgvucevohguihhnrgcuoehhvghrvhgvrdgtohguihhnrgessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepheffiefgjeeuleeuueffleeufefglefhjefhheeigedukeetieeltddthfffkeffnecukfhppeeltddrkeelrdduieefrdduvdejnecuvehluhhsthgvrhfuihiivgepieenucfrrghrrghmpehinhgvthepledtrdekledrudeifedruddvjedphhgvlhhopehlohgtrghlhhhoshhtrdhlohgtrghlughomhgrihhnpdhmrghilhhfrhhomhephhgvrhhvvgdrtghoughinhgrsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeeguddprhgtphhtthhopehgrhgvghhkhheslhhinhhugihfohhunhgurghtihhonhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrkhhrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehshhgrfihnghhuoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshdrhhgruhgvrhesphgvnhhguhhtrhhonhhigidruggvpdhrt ghpthhtohepkhgvrhhnvghlsehpvghnghhuthhrohhnihigrdguvgdprhgtphhtthhopehfvghsthgvvhgrmhesghhmrghilhdrtghomhdprhgtphhtthhopehmthhurhhquhgvthhtvgessggrhihlihgsrhgvrdgtohhm X-GND-Sasl: herve.codina@bootlin.com 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 dev 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 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 in order to have the i2c mux device calling i2c_del_adapter() to remove its downtream 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 supplier of the adapter a mux is connected to, rely on the newly introduced i2c_adapter_get_supplier() and create the missing devlink between the i2c mux device and the supplier 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index d8bdb3b40acf..84ffd58e4d6d 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -271,7 +271,9 @@ 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_supplier; struct i2c_mux_priv *priv; + struct device_link *dl; char symlink_name[20]; int ret; @@ -378,6 +380,24 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, ACPI_COMPANION(muxc->dev), chan_id); + /* + * There is no relationship set between the mux dev and the 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 device (supplier) which handles + * the i2c mux upstream adapter. + */ + parent_supplier = i2c_get_adapter_supplier(parent); + dl = device_link_add(muxc->dev, parent_supplier, DL_FLAG_AUTOREMOVE_CONSUMER); + if (!dl) { + dev_err(muxc->dev, "failed to create device link to %s\n", + dev_name(parent_supplier)); + put_device(parent_supplier); + ret = -EINVAL; + goto err_free_priv; + } + put_device(parent_supplier); + if (force_nr) { priv->adap.nr = force_nr; ret = i2c_add_numbered_adapter(&priv->adap);