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=1796250625; b=AIKtOFJ/Ha2QpsB1Yo2JUfCYJKeAhdyHXr8UvdNy1XEzD5sQZIvghsQMrS7h0XHssbFb HcK/RJL4UeZgjVwRsNS8xi8RGW6dGS/bJqRlLPB3eZh4J4JcXrbxlzOnhNYFsgvf5rrFB 2vbEPlR2+A2PjWjA4ZcWFuXpfwIepOY1KLPkreeXwp1/msG+ekdN9EkaySEqbQiOl6eKY U8aIhF2wPZ+htkf9QanrKQpWZHyVsfhQdM4NboCB+aEBhMEX2+qFApdsuhlCqh/auV/NP oriOSk0gxkbIpvbf2sBZg+wGvz3+EBfpsu/QT0HEYpyWB0ltftlw+W82zx+aidAXZUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796250625; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=Z1F6wWgeOeHzW2iF0oYcjeFN4UheUVCW/ZaOKKqKGao=; b=t4/+4SlIqO0jowpmpmcMZqG+o5ytnMkHZ6wyEJu/j4iUZzbUf5XmUZE2hm+axr0+gvyE fQuMCb/lCFtVxyN/UzT3GLFjq5t4mTr5L8s+buE5IOXxRdcnTzx8pqUXBzpCLX4pa5bMQ HYKQ6ZRN7eCfR0wDKoWtIQsfH3Q2BYHFAV+rwu8O4VFkFal1CTlFFNroYzB3f0wtEgBg2 nkPoLl7YZnjjJuArpkE7TqdO7NcbbA6VOMf8vE9Oay+93w1ltnIX7B3JwsQH8TXMQR3gQ ToNqNifNeJYR83o0lyE2Q+zIBy6pwz5/S+g8VIy7akQMQ4mgMDLAvHQ4NX+f3rUDrKQ== 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=omPKO89O; 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 2A273606A322 for ; Wed, 2 Dec 2026 22:30:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2A273606A322 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=omPKO89O Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 751C2C2AC4F; Wed, 2 Dec 2026 22:30:34 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 1CA166075F; Wed, 2 Dec 2026 22:30:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8596611EA1E0E; Wed, 02 Dec 2026 23:30:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796250618; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding; bh=Z1F6wWgeOeHzW2iF0oYcjeFN4UheUVCW/ZaOKKqKGao=; b=omPKO89OJW4JPVRVYV2G1L4OL9oLeerBjW9EUh5EGrLvlVapHpF45gWOdg1bka39ThIxJw K/WRR2eAb43Wdp9+M60Isr/eHK8amxmHllSFrZXQ8lF/4mpb4q8MYCMWb+i6nLYlZw/5ib Q1l1sG2Lld3wGFY2HudQW+coLQ8zb+pBy0tbUtreJICacZjDe+uctAcUDxyOt/ArvYcJBR if4o8nMBAWVx55ZxSaCo/CEYRig6BjVzZiIN/WZ7p5dg2By7KL+tkdZgQ0cZbj1Sz+9tFy OaE2VJs1NBO92fEybLLo7OgrocVznO30QvzbeTx5UYVQfDCObdggV6v0O49gJg== From: alexandre.belloni@bootlin.com To: Alexandre Belloni , Frank Li , Greg Kroah-Hartman , Arnd Bergmann , Boris Brezillon Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] i3c: master: Release fwnode reference of I2C boardinfo at unregistration Date: Wed, 2 Dec 2026 23:30:12 +0100 Message-ID: <20261202223014.696672-1-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.56.0 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 From: Alexandre Belloni i3c_master_add_i2c_boardinfo() takes a reference on the fwnode of each I2C device described on the bus to keep it alive while the boardinfo stores a pointer to it: the bus enumeration loop only holds the child node while it iterates. However, the reference is never released: the boardinfo entries are devm-allocated and freed with the master device, so one device node reference is leaked per I2C device when the master controller goes away. Drop the reference through a devm action, which runs when the devm resources of the master device are released, that is at master unregistration or when i3c_master_register_fwnode() fails. The reference cannot be dropped from the master device release callback because device_release() frees the devm resources before calling it, which would make the boardinfo list a use-after-free. fwnode_handle_get()/fwnode_handle_put() are no-ops on ACPI nodes, so the ACPI enumeration path is unaffected. Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure") Signed-off-by: Alexandre Belloni --- drivers/i3c/master.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 2bd1bd25c674..677d547bc12f 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -3140,6 +3140,13 @@ static inline int i3c_acpi_add_i2c_boardinfo(struct i2c_dev_boardinfo *boardinfo } #endif +static void i3c_master_i2c_boardinfo_fwnode_put(void *data) +{ + struct i2c_dev_boardinfo *boardinfo = data; + + fwnode_handle_put(boardinfo->base.fwnode); +} + static int i3c_master_add_i2c_boardinfo(struct i3c_master_controller *master, struct fwnode_handle *fwnode, u32 *reg) @@ -3179,8 +3186,13 @@ i3c_master_add_i2c_boardinfo(struct i3c_master_controller *master, return -EOPNOTSUPP; } - list_add_tail(&boardinfo->node, &master->boardinfo.i2c); fwnode_handle_get(fwnode); + ret = devm_add_action_or_reset(dev, i3c_master_i2c_boardinfo_fwnode_put, + boardinfo); + if (ret) + return ret; + + list_add_tail(&boardinfo->node, &master->boardinfo.i2c); return 0; } -- 2.56.0