Linux-i3c Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
@ 2026-11-27  6:58 Billy Tsai
  2026-11-27  7:12 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Billy Tsai @ 2026-11-27  6:58 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.

OF_POPULATED is a property of the device_node itself, which outlives
this master's registration. fwnode_depopulate_i3c_bus() is the
counterpart that clears the flag again, called from
i3c_master_bus_cleanup() (shared by the registration error path and
i3c_master_unregister()) and from fwnode_populate_i3c_bus()'s own
error path. Without it, the nodes stay claimed after this master is
unbound or fails to register, and a later re-probe or rebind finds
them already marked and silently skips creating their devices.

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>
---
Changes in v2:
- Also clear OF_POPULATED again on teardown and on a mid-loop probe
  failure (fwnode_depopulate_i3c_bus(), called from
  i3c_master_bus_cleanup() and from fwnode_populate_i3c_bus()'s own
  error path), so unregister/rebind and a failed probe do not leave OF
  bus children permanently marked.
- Link to v1: https://lore.kernel.org/r/20261127-i3c-master-of-populated-v1-1-29d2a6a5509c@aspeedtech.com
---
 drivers/i3c/master.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 01e05bad8661..e85307678fdc 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2667,6 +2667,8 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
 	return ret;
 }
 
+static void fwnode_depopulate_i3c_bus(struct i3c_master_controller *master);
+
 static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
 {
 	if (master->ops->bus_cleanup) {
@@ -2681,6 +2683,7 @@ static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
 		}
 	}
 
+	fwnode_depopulate_i3c_bus(master);
 	i3c_master_detach_free_devs(master);
 }
 
@@ -3353,15 +3356,29 @@ 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) {
+				fwnode_depopulate_i3c_bus(master);
+				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) {
+				fwnode_depopulate_i3c_bus(master);
+				return ret;
+			}
+		}
 	}
 
 	/*
@@ -3378,6 +3395,26 @@ static int fwnode_populate_i3c_bus(struct i3c_master_controller *master)
 	return 0;
 }
 
+/*
+ * Counterpart to fwnode_populate_i3c_bus(): drop the OF_POPULATED claim on
+ * every OF bus child so a later re-probe of this master, or the legacy I2C
+ * adapter's of_i2c_register_devices() walk on a different master sharing
+ * the same of_node, does not find these nodes permanently locked out.
+ * ACPI-described children were never marked, so they are skipped here too.
+ */
+static void fwnode_depopulate_i3c_bus(struct i3c_master_controller *master)
+{
+	struct fwnode_handle *fwnode = dev_fwnode(&master->dev);
+
+	if (!fwnode)
+		return;
+
+	fwnode_for_each_available_child_node_scoped(fwnode, child) {
+		if (is_of_node(child))
+			of_node_clear_flag(to_of_node(child), OF_POPULATED);
+	}
+}
+
 static int i3c_master_i2c_adapter_xfer(struct i2c_adapter *adap,
 				       struct i2c_msg *xfers, int nxfers)
 {

---
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 v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
  2026-11-27  6:58 [PATCH v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
@ 2026-11-27  7:12 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-27  7:12 UTC (permalink / raw)
  To: Billy Tsai; +Cc: linux-i3c, Frank.Li, Alexandre Belloni

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] i3c: master: OF_POPULATED leaked on pre-device_add()
  registration errors
--

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

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

This commit marks OF child nodes of the I3C bus with OF_POPULATED in
fwnode_populate_i3c_bus() so that i2c_register_adapter() skips them, and
clears the flag in fwnode_depopulate_i3c_bus() on error and bus cleanup.

> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 01e05bad8661e..e85307678fdcf 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -2667,6 +2667,8 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
>  	return ret;
>  }
>  
> +static void fwnode_depopulate_i3c_bus(struct i3c_master_controller *master);
> +
>  static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
>  {
>  	if (master->ops->bus_cleanup) {
> @@ -2681,6 +2683,7 @@ static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
>  		}
>  	}
>  
> +	fwnode_depopulate_i3c_bus(master);
>  	i3c_master_detach_free_devs(master);
>  }

[Severity: Medium]
Does placing fwnode_depopulate_i3c_bus() in i3c_master_bus_cleanup() still
leave OF_POPULATED set when i3c_master_register_fwnode() fails after
fwnode_populate_i3c_bus() succeeds but before device_add()?

Every error path in i3c_master_register_fwnode() between
fwnode_populate_i3c_bus() and device_add(), including
i3c_master_bus_init() failure, jumps directly to err_put_dev and skips
i3c_master_bus_cleanup():

drivers/i3c/master.c:i3c_master_register_fwnode() {
	...
	ret = fwnode_populate_i3c_bus(master);
	if (ret)
		goto err_put_dev;
	...
	ret = i3c_master_bus_init(master);
	if (ret)
		goto err_put_dev;

	ret = device_add(&master->dev);
	if (ret)
		goto err_cleanup_bus;
	...
err_cleanup_bus:
	i3c_master_bus_cleanup(master);

err_put_dev:
	i3c_master_rpm_put(master);
	put_device(&master->dev);
}

If i3c_master_bus_init() fails, the OF child nodes remain marked
OF_POPULATED after registration aborts, preventing device creation on a
later re-probe or rebind.  Calling fwnode_depopulate_i3c_bus() from
i3c_masterdev_release() (or on the err_put_dev teardown path) would cover
these failures as well.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-i3c-master-of-populated-v2-1-c52095d00218@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  7:12 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:58 [PATCH v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
2026-11-27  7:12 ` sashiko-bot

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