mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Billy Tsai <billy_tsai@aspeedtech.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Frank Li <Frank.Li@nxp.com>,
	Peter Yin <peteryin.openbmc@gmail.com>,
	linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v3] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
Date: Wed, 2 Dec 2026 14:47:14 -0500	[thread overview]
Message-ID: <axB1wro1AIo4CcCM@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20261202-i3c-master-of-populated-v3-1-68d504643bdf@aspeedtech.com>

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>
>

  reply	other threads:[~2026-12-02 19:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:23 Billy Tsai
2026-12-02 19:47 ` Frank Li [this message]
2026-12-02 22:16 ` Alexandre Belloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axB1wro1AIo4CcCM@lizhi-Precision-Tower-5810 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=billy_tsai@aspeedtech.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peteryin.openbmc@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®