mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
@ 2026-12-02  8:23 Billy Tsai
  2026-12-02 19:47 ` Frank Li
  2026-12-02 22:16 ` Alexandre Belloni
  0 siblings, 2 replies; 3+ messages in thread
From: Billy Tsai @ 2026-12-02  8:23 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 v3:
- Move fwnode_depopulate_i3c_bus() to where its forward declaration was,
  so i3c_master_bus_cleanup() calls the real definition directly
  (Frank Li).
- Also clear OF_POPULATED on the fwnode_populate_i3c_bus() success but
  i3c_master_bus_init() (or an earlier step in the same window) failure
  path in i3c_master_register_fwnode(), which previously went straight
  to err_put_dev and skipped i3c_master_bus_cleanup() entirely, leaving
  the flag set after registration aborts (Sashiko AI review).
- Link to v2: https://lore.kernel.org/r/20261127-i3c-master-of-populated-v2-1-c52095d00218@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 | 61 ++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 50 insertions(+), 11 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 01e05bad8661..d0b0248ad6b3 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2667,6 +2667,26 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
 	return ret;
 }
 
+/*
+ * 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 void i3c_master_bus_cleanup(struct i3c_master_controller *master)
 {
 	if (master->ops->bus_cleanup) {
@@ -2681,6 +2701,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 +3374,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;
+			}
+		}
 	}
 
 	/*
@@ -3932,7 +3967,7 @@ int i3c_master_register_fwnode(struct i3c_master_controller *master,
 			break;
 		default:
 			ret = -EINVAL;
-			goto err_put_dev;
+			goto err_depopulate_bus;
 		}
 
 		if (i2cbi->lvr & I3C_LVR_I2C_FM_MODE)
@@ -3941,19 +3976,19 @@ int i3c_master_register_fwnode(struct i3c_master_controller *master,
 
 	ret = i3c_bus_set_mode(i3cbus, mode, i2c_scl_rate);
 	if (ret)
-		goto err_put_dev;
+		goto err_depopulate_bus;
 
 	master->wq = alloc_workqueue("%s", WQ_PERCPU | WQ_FREEZABLE, 0, dev_name(parent));
 	if (!master->wq) {
 		ret = -ENOMEM;
-		goto err_put_dev;
+		goto err_depopulate_bus;
 	}
 	INIT_WORK(&master->hj_work, i3c_master_hj_work_fn);
 	INIT_WORK(&master->reg_work, i3c_master_reg_work_fn);
 
 	ret = i3c_master_bus_init(master);
 	if (ret)
-		goto err_put_dev;
+		goto err_depopulate_bus;
 
 	ret = device_add(&master->dev);
 	if (ret)
@@ -3997,6 +4032,10 @@ int i3c_master_register_fwnode(struct i3c_master_controller *master,
 
 err_cleanup_bus:
 	i3c_master_bus_cleanup(master);
+	goto err_put_dev;
+
+err_depopulate_bus:
+	fwnode_depopulate_i3c_bus(master);
 
 err_put_dev:
 	i3c_master_rpm_put(master);

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

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


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

* Re: [PATCH v3] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
  2026-12-02  8:23 [PATCH v3] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
@ 2026-12-02 19:47 ` Frank Li
  2026-12-02 22:16 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-12-02 19:47 UTC (permalink / raw)
  To: Billy Tsai
  Cc: Alexandre Belloni, Frank Li, Peter Yin, linux-i3c, linux-kernel, stable

On Wed, Dec 02, 2026 at 04:23:53PM +0800, Billy Tsai wrote:
> 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> Changes in v3:
> - Move fwnode_depopulate_i3c_bus() to where its forward declaration was,
>   so i3c_master_bus_cleanup() calls the real definition directly
>   (Frank Li).
> - Also clear OF_POPULATED on the fwnode_populate_i3c_bus() success but
>   i3c_master_bus_init() (or an earlier step in the same window) failure
>   path in i3c_master_register_fwnode(), which previously went straight
>   to err_put_dev and skipped i3c_master_bus_cleanup() entirely, leaving
>   the flag set after registration aborts (Sashiko AI review).
> - Link to v2: https://lore.kernel.org/r/20261127-i3c-master-of-populated-v2-1-c52095d00218@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 | 61 ++++++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 50 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 01e05bad8661..d0b0248ad6b3 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -2667,6 +2667,26 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
>  	return ret;
>  }
>
> +/*
> + * 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 void i3c_master_bus_cleanup(struct i3c_master_controller *master)
>  {
>  	if (master->ops->bus_cleanup) {
> @@ -2681,6 +2701,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 +3374,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;
> +			}
> +		}
>  	}
>
>  	/*
> @@ -3932,7 +3967,7 @@ int i3c_master_register_fwnode(struct i3c_master_controller *master,
>  			break;
>  		default:
>  			ret = -EINVAL;
> -			goto err_put_dev;
> +			goto err_depopulate_bus;
>  		}
>
>  		if (i2cbi->lvr & I3C_LVR_I2C_FM_MODE)
> @@ -3941,19 +3976,19 @@ int i3c_master_register_fwnode(struct i3c_master_controller *master,
>
>  	ret = i3c_bus_set_mode(i3cbus, mode, i2c_scl_rate);
>  	if (ret)
> -		goto err_put_dev;
> +		goto err_depopulate_bus;
>
>  	master->wq = alloc_workqueue("%s", WQ_PERCPU | WQ_FREEZABLE, 0, dev_name(parent));
>  	if (!master->wq) {
>  		ret = -ENOMEM;
> -		goto err_put_dev;
> +		goto err_depopulate_bus;
>  	}
>  	INIT_WORK(&master->hj_work, i3c_master_hj_work_fn);
>  	INIT_WORK(&master->reg_work, i3c_master_reg_work_fn);
>
>  	ret = i3c_master_bus_init(master);
>  	if (ret)
> -		goto err_put_dev;
> +		goto err_depopulate_bus;
>
>  	ret = device_add(&master->dev);
>  	if (ret)
> @@ -3997,6 +4032,10 @@ int i3c_master_register_fwnode(struct i3c_master_controller *master,
>
>  err_cleanup_bus:
>  	i3c_master_bus_cleanup(master);
> +	goto err_put_dev;
> +
> +err_depopulate_bus:
> +	fwnode_depopulate_i3c_bus(master);
>
>  err_put_dev:
>  	i3c_master_rpm_put(master);
>
> ---
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> change-id: 20261127-i3c-master-of-populated-2ef07c2bb743
>
> Best regards,
> --
> Billy Tsai <billy_tsai@aspeedtech.com>
>

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

* Re: [PATCH v3] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
  2026-12-02  8:23 [PATCH v3] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
  2026-12-02 19:47 ` Frank Li
@ 2026-12-02 22:16 ` Alexandre Belloni
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2026-12-02 22:16 UTC (permalink / raw)
  To: Frank Li, Peter Yin, Billy Tsai; +Cc: linux-i3c, linux-kernel, stable

On Wed, 02 Dec 2026 16:23:53 +0800, Billy Tsai wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
      https://git.kernel.org/i3c/c/7e0cef0dcbe0

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

end of thread, other threads:[~2026-12-02 22:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02  8:23 [PATCH v3] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
2026-12-02 19:47 ` Frank Li
2026-12-02 22:16 ` Alexandre Belloni

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

all inboxes | Powered by JetHome®