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=1796250630; b=GpqZ4mZtM0MP4iMrH62+8Wqi4cCotSFVxNeLqPfxon1muyr96rzcHS4o+U0PtvyDQ+61 di8HzmGByi2nqv2yN/mmYSBSLw/3P4/gXX3XGnQ0+/BfU7VjK4UzNzsddLpPC9zkk6GU2 d25VyamlxKxYQWcgChL+nCZz+p6YThAXS1mifcz/ey/U0cW0O+c+46otlKUotvqBW/+Tn fWcZbmqnHV0Ajb3J5Ym+I+etWRbYYy6TAyTPLB2Qr12dldetp1rQxIrjBI+NHS/PEszbo OdYbBNsR1zWvLetwVpHDtMAu6hJNkRt8oKP3t69PhObhMj5wxu8wH44QaeWO+DEmppw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796250630; 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=3Drvh+p1qyc+NN2GJOFIJVgp1A8DcODe2xFBzNomi+U=; b=sDvulh/2brMhrCATxnNR/J+kuEj8juh8UVWZn+cGZfWwThliTuuSLGSrsyqysO8R9R7k cLHjx6nV2Db/gETMizVmaGWholOlmNcFhhg8X+syCu5K1HQhIoVqYvPkmTau6WQuYG9cP 1+c4bt3q5GGesahDeIQtbmATTKXc4dDtNcfD5gHP1UzzskfsDUZBTWJmCUewvuGMTo7Qm P9keIIbXvY2WRp8+lkg0EogXpOOU7THyhQ1SnGNrm1I17/Io9cjCehBafx44+3a11J8BK i/4WtpCxUjE828Q19B7PLJRM/ej6d0rJ5xyvgJxwT3tAy05WIxK56SJC1ApwhBEhFxw== 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=KSBJgl4b; 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 0E0E0606A322 for ; Wed, 2 Dec 2026 22:30:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0E0E0606A322 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=KSBJgl4b Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id BB3BFC2AC4F; Wed, 2 Dec 2026 22:30:39 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9A8CC6075F; Wed, 2 Dec 2026 22:30:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 409DB11EA05CD; Wed, 02 Dec 2026 23:30:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796250624; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=3Drvh+p1qyc+NN2GJOFIJVgp1A8DcODe2xFBzNomi+U=; b=KSBJgl4bECGZdrskpueTYtDc9anb6/THiG2Jr0zlJ7Pupj2GChadogw+T7IjyfwuL7rjVB 4EVzu7JR5ffsjfOQ8hCOP2JklOAlS301tLSIrT5u8FfGW/pAJbAzPvxfjKs1sJvi0R7/u8 Y34M9Dw7647uAsB4rT93l2jaT+iVZvaanhFUiQjUtus3FSPNZUo2SQU7MHer2ohi73G0yi 8Oi0HtmKCfTdCPT9NLceXLlqoG4SinmPDLX7SQiS801vGQpPjx12rf9GxNLTmuSBzx6+Sq RF55f4e0jfNBZDptn5LPyMaAXlAUNFLCTI321aR9tzguuLOHPtUSAsTRX2G16A== From: alexandre.belloni@bootlin.com To: Alexandre Belloni , Frank Li , Greg Kroah-Hartman , Boris Brezillon , Arnd Bergmann Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] i3c: master: Give I3C devices their own fwnode reference Date: Wed, 2 Dec 2026 23:30:13 +0100 Message-ID: <20261202223014.696672-2-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261202223014.696672-1-alexandre.belloni@bootlin.com> References: <20261202223014.696672-1-alexandre.belloni@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 From: Alexandre Belloni i3c_dev_boardinfo entries take a reference on their fwnode, which is transferred to the I3C device created from the boardinfo by a plain pointer assignment in i3c_master_register_new_i3c_devs(). This leaks a reference for boardinfo entries that never match a device on the bus (the boardinfo is devm-freed with the master without dropping it), and if two device descriptors ever match the same boardinfo, both devices would release the single transferred reference, underflowing the fwnode refcount. Let each holder own its own reference: devices take a fresh reference in i3c_master_register_new_i3c_devs(), balanced by the existing fwnode_handle_put() in i3c_device_release(), while the boardinfo drops its own reference through a devm action when it is released. Devices are unregistered before the devm resources are released at master unregistration, but each reference is independent so the order does not matter. Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure") Signed-off-by: Alexandre Belloni --- drivers/i3c/master.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 677d547bc12f..409545a6eda3 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2242,8 +2242,13 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master) dev_set_name(&desc->dev->dev, "%d-%02x", master->bus.id, desc->info.static_addr); + /* + * The device takes its own reference on the fwnode, which + * is dropped by i3c_device_release(). + */ if (desc->boardinfo) - device_set_node(&desc->dev->dev, desc->boardinfo->fwnode); + device_set_node(&desc->dev->dev, + fwnode_handle_get(desc->boardinfo->fwnode)); /* If the device has IBI capability, set as wakeup capable */ if (master->ibi_wakeup && (desc->info.bcr & I3C_BCR_IBI_REQ_CAP)) @@ -3197,6 +3202,13 @@ i3c_master_add_i2c_boardinfo(struct i3c_master_controller *master, return 0; } +static void i3c_master_i3c_boardinfo_fwnode_put(void *data) +{ + struct i3c_dev_boardinfo *boardinfo = data; + + fwnode_handle_put(boardinfo->fwnode); +} + static int i3c_master_add_i3c_boardinfo(struct i3c_master_controller *master, struct fwnode_handle *fwnode, u32 *reg) @@ -3205,6 +3217,7 @@ i3c_master_add_i3c_boardinfo(struct i3c_master_controller *master, struct device *dev = &master->dev; enum i3c_addr_slot_status addrstatus; u32 init_dyn_addr = 0, static_addr_method = 0; + int ret; boardinfo = devm_kzalloc(dev, sizeof(*boardinfo), GFP_KERNEL); if (!boardinfo) @@ -3266,7 +3279,13 @@ i3c_master_add_i3c_boardinfo(struct i3c_master_controller *master, } boardinfo->init_dyn_addr = init_dyn_addr; + boardinfo->fwnode = fwnode_handle_get(fwnode); + ret = devm_add_action_or_reset(dev, i3c_master_i3c_boardinfo_fwnode_put, + boardinfo); + if (ret) + return ret; + list_add_tail(&boardinfo->node, &master->boardinfo.i3c); return 0; -- 2.56.0