Linux-i3c Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
@ 2026-11-27  6:20 Billy Tsai
  2026-11-27  6:31 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Billy Tsai @ 2026-11-27  6:20 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li, Peter Yin
  Cc: linux-i3c, linux-kernel, stable, Billy Tsai

Commit f26ecaa0f0ab ("i3c: master: dw-i3c: Fix missing of_node for
virtual I2C adapter") made the DesignWare I3C master's virtual legacy
I2C adapter reuse the I3C bus platform device's of_node, so consumers
can resolve the adapter by phandle. i2c_register_adapter() reacts to
any adapter with a non-NULL of_node by unconditionally calling
of_i2c_register_devices(), which walks every child of that node and
requires a "compatible" property to build a modalias.

The I3C core already owns and fully parses every child of the bus node
via fwnode_populate_i3c_bus()/i3c_master_add_of_dev(), for both native
I3C devices (no "compatible" needed per the i3c.yaml binding) and
legacy-I2C-under-I3C devices (registered explicitly through
master->boardinfo.i2c in i3c_master_i2c_adapter_init()). Since neither
path marks the node OF_POPULATED, the generic of_i2c_register_devices()
walk that now runs afterwards treats every child as unclaimed:

 - native I3C-only nodes have no "compatible", so of_i2c_get_board_info()
   fails the modalias lookup and logs "of_i2c: modalias failure" /
   "Failed to create I2C device" noise for a device that is already
   correctly registered on the I3C bus.

 - legacy-I2C nodes do have "compatible", so of_i2c_register_devices()
   silently creates a duplicate i2c_client for the same address that
   i3c_master_i2c_adapter_init() also registers from boardinfo.i2c.

Mark each OF bus child OF_POPULATED once i3c_master_add_of_dev() has
accounted for it. ACPI-described children are left untouched, since
OF_POPULATED and of_i2c_register_devices() only apply to the
devicetree case. fwnode_populate_i3c_bus() always runs before the I2C
adapter is registered, so of_i2c_register_devices() sees the flag
already set and skips these nodes entirely, without disturbing the
of_node propagation from f26ecaa0f0ab.

Fixes: f26ecaa0f0ab ("i3c: master: dw-i3c: Fix missing of_node for virtual I2C adapter")
Cc: stable@vger.kernel.org
Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
---
 drivers/i3c/master.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 01e05bad8661..f025c9e9a046 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -3353,15 +3353,25 @@ static int fwnode_populate_i3c_bus(struct i3c_master_controller *master)
 		return 0;
 
 	fwnode_for_each_available_child_node_scoped(fwnode, child) {
-		if (is_of_node(child))
+		if (is_of_node(child)) {
 			ret = i3c_master_add_of_dev(master, child);
-		else if (is_acpi_device_node(child))
-			ret = i3c_master_add_acpi_dev(master, child);
-		else
-			continue;
+			if (ret)
+				return ret;
 
-		if (ret)
-			return ret;
+			/*
+			 * Claim the node so that i2c_register_adapter(),
+			 * called later for the legacy I2C adapter sharing
+			 * this same of_node, does not also run
+			 * of_i2c_register_devices() on it: every child here
+			 * is already fully accounted for, whether it ends up
+			 * I3C or legacy-I2C boardinfo.
+			 */
+			of_node_set_flag(to_of_node(child), OF_POPULATED);
+		} else if (is_acpi_device_node(child)) {
+			ret = i3c_master_add_acpi_dev(master, child);
+			if (ret)
+				return ret;
+		}
 	}
 
 	/*

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261127-i3c-master-of-populated-2ef07c2bb743

Best regards,
-- 
Billy Tsai <billy_tsai@aspeedtech.com>


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
  2026-11-27  6:20 [PATCH] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
@ 2026-11-27  6:31 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-27  6:31 UTC (permalink / raw)
  To: Billy Tsai; +Cc: linux-i3c, Frank.Li, Alexandre Belloni

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] i3c: master: duplicate I2C target registration in
  i3c_master_add_acpi_dev() [1]
--

commit 90a128e17ec3265217e6df1035f55519b17c0fc3
Author: Billy Tsai <billy_tsai@aspeedtech.com>

i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan

This commit marks devicetree child nodes of an I3C bus as OF_POPULATED in
fwnode_populate_i3c_bus() so that registering a virtual legacy I2C adapter
sharing the bus of_node does not re-parse or duplicate them via
of_i2c_register_devices().

> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 01e05bad8661e..f025c9e9a0466 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -3353,15 +3353,25 @@ static int fwnode_populate_i3c_bus(struct i3c_master_controller *master)
>  		return 0;
>  
>  	fwnode_for_each_available_child_node_scoped(fwnode, child) {
> -		if (is_of_node(child))
> +		if (is_of_node(child)) {
>  			ret = i3c_master_add_of_dev(master, child);
> -		else if (is_acpi_device_node(child))
> -			ret = i3c_master_add_acpi_dev(master, child);
> -		else
> -			continue;
> +			if (ret)
> +				return ret;
>  
> -		if (ret)
> -			return ret;
> +			/*
> +			 * Claim the node so that i2c_register_adapter(),
> +			 * called later for the legacy I2C adapter sharing
> +			 * this same of_node, does not also run
> +			 * of_i2c_register_devices() on it: every child here
> +			 * is already fully accounted for, whether it ends up
> +			 * I3C or legacy-I2C boardinfo.
> +			 */
> +			of_node_set_flag(to_of_node(child), OF_POPULATED);
> +		} else if (is_acpi_device_node(child)) {
> +			ret = i3c_master_add_acpi_dev(master, child);
> +			if (ret)
> +				return ret;
> +		}
>  	}

[Severity: High]
This problem wasn't introduced by this patch, but can
i3c_master_add_acpi_dev() register duplicate I2C boardinfo across multiple
I3C controllers [1]?

drivers/i3c/master.c:i3c_master_add_acpi_dev() {
    ...
	if (!acpi_has_method(adev->handle, "_ADR")) {
		ret = i3c_master_add_i2c_boardinfo(master, fwnode, reg);
		if (ret == -ENODEV)
			return 0;

		return ret;
	}
    ...
}

When an I3C controller is part of an MFD sharing a parent PCI device's
ACPI node, every controller instance iterates over the shared ACPI child
nodes in fwnode_populate_i3c_bus().  Unlike I3C targets, ACPI child nodes
for I2C devices have no _ADR method, so they bypass controller filtering
and are added to master->boardinfo.i2c on every controller instance,
causing multiple logical I3C buses to instantiate and probe the same
physical I2C target.

[1] https://sashiko.dev/#/bug/linux-d64b161b-09ef-4f5f-9be2-2f469152abee

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-i3c-master-of-populated-v1-1-29d2a6a5509c@aspeedtech.com?part=1

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-27  6:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  6:20 [PATCH] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
2026-11-27  6:31 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox