Re: [PATCH v4 18/29] i2c: mux: Create missing devlink between mux and adapter physical device
From: Herve Codina
Date: Mon Nov 03 2025 - 08:41:07 EST
Hi Andi,
On Thu, 30 Oct 2025 16:23:24 +0100
Andi Shyti <andi.shyti@xxxxxxxxxx> wrote:
> 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.
Will be added.
>
> > +----------------+ +-------------------+
> > | 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/
Will be fixed
>
> > 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?
Yes, -ENODEV makes sense here. Will be changed in the next iteration.
>
> > + 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.
As Andy already mentioned, we cannot do that. Indeed, dev_name(parent_physdev)
is called in the error path and so the device reference has to be kept.
>
> > + 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?
For this one, I am not so sure.
The failure is related to the device link creation and probably due to some
devlink invalid internal flags or state instead of a missing device.
That's said, if you really want the -ENODEV here, let me know.
Best regards,
Hervé