Re: [PATCH v4 18/29] i2c: mux: Create missing devlink between mux and adapter physical device

From: Andi Shyti

Date: Thu Oct 30 2025 - 11:23:29 EST


Hi Herve,

...

> When an i2c mux is involved in an i2c path, the struct dev topology is
> the following:

supernitpick: I'd leave blank line here.

> +----------------+ +-------------------+
> | i2c controller | | i2c mux |
> | device | | device |
> | ^ | | |
> | | | | |
> | dev's parent | | |
> | | | | |
> | i2c adapter | | i2c adapter chanX |
> | device <---- dev's parent ------ device |
> | (no driver) | | (no driver) |
> +----------------+ +-------------------+
>

...

> No relationship exists between the i2c mux device itself and the i2c
> controller device (physical device) in order to have the i2c mux device
> calling i2c_del_adapter() to remove its downtream adapters and so,

/downtream/downstream/

> release references taken to the upstream adapter.

...

> + /*
> + * There is no relationship set between the mux device and the physical
> + * device handling the parent adapter. Create this missing relationship
> + * in order to remove the i2c mux device (consumer) and so the dowstream
> + * channel adapters before removing the physical device (supplier) which
> + * handles the i2c mux upstream adapter.
> + */
> + parent_physdev = i2c_get_adapter_physdev(parent);
> + if (!parent_physdev) {
> + dev_err(muxc->dev, "failed to get the parent physical device\n");
> + ret = -EINVAL;

-ENODEV?

> + goto err_free_priv;
> + }
> + dl = device_link_add(muxc->dev, parent_physdev, DL_FLAG_AUTOREMOVE_CONSUMER);

Not to call twice put_device, I would add it once here and then
check for !dl.

> + if (!dl) {
> + dev_err(muxc->dev, "failed to create device link to %s\n",
> + dev_name(parent_physdev));
> + put_device(parent_physdev);
> + ret = -EINVAL;

same here, should this be -ENODEV?

Andi

> + goto err_free_priv;
> + }
> + put_device(parent_physdev);
> +
> if (force_nr) {
> priv->adap.nr = force_nr;
> ret = i2c_add_numbered_adapter(&priv->adap);
> --
> 2.51.0
>