Re: [PATCH v1] driver core: fw_devlink: Don't create device links for devices not on a bus

From: Ulf Hansson
Date: Wed Sep 01 2021 - 18:18:01 EST


On Wed, 1 Sept 2021 at 23:54, Saravana Kannan <saravanak@xxxxxxxxxx> wrote:
>
> On Wed, Sep 1, 2021 at 8:45 AM Ulf Hansson <ulf.hansson@xxxxxxxxxx> wrote:
> >
> > On Wed, 1 Sept 2021 at 00:45, Saravana Kannan <saravanak@xxxxxxxxxx> wrote:
> > >
> > > Devices that are not on a bus will never have a driver bound to it. So,
> > > fw_devlink should not create device links for it as it can cause probe
> > > issues[1] or sync_state() call back issues[2].
> > >
> > > [1] - https://lore.kernel.org/lkml/CAGETcx_xJCqOWtwZ9Ee2+0sPGNLM5=F=djtbdYENkAYZa0ynqQ@xxxxxxxxxxxxxx/
> > > [2] - https://lore.kernel.org/lkml/CAPDyKFo9Bxremkb1dDrr4OcXSpE0keVze94Cm=zrkOVxHHxBmQ@xxxxxxxxxxxxxx/
> >
> > Unfortunately, this doesn't fix my problem in [2].
> >
> > When the "soctest" device is initialized, via of_platform_populate(),
> > it will be attached to the platform bus, hence the check for the bus
> > pointer that you suggest to add below, doesn't have an impact on my
> > use case. I still get the below in the log:
>
> *face palm* Right. I forgot that. I just read "bus" and my mind went
> to busses added as devices. It apparently also didn't help [1] which
> is surprising to me. I'll dig into that separately. I'll look into
> fixing this. The annoying part is that some devices have compatible
> property that's both "simple-bus" and some other string that a driver
> actually matches with.

Yes, that is my view of the problem as well.

So perhaps we should do a more fine grained check for when the
"simple-bus" compatible is present in the node, and then don't create
a fw_devlink if we reach an ascendant with only this compatible?

Would that work, do you think?

Kind regards
Uffe

>
> -Saravana
>
> >
> > "platform soctest: Linked as a sync state only consumer to pm_domain_test"
> >
> > Kind regards
> > Uffe
> >
> > > Fixes: f9aa460672c9 ("driver core: Refactor fw_devlink feature")
> > > Reported-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
> > > Reported-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
> > > Signed-off-by: Saravana Kannan <saravanak@xxxxxxxxxx>
> > > ---
> > > drivers/base/core.c | 16 ++++++++++++++++
> > > 1 file changed, 16 insertions(+)
> > >
> > > diff --git a/drivers/base/core.c b/drivers/base/core.c
> > > index f6360490a4a3..304a06314656 100644
> > > --- a/drivers/base/core.c
> > > +++ b/drivers/base/core.c
> > > @@ -1719,8 +1719,24 @@ static int fw_devlink_create_devlink(struct device *con,
> > > struct device *sup_dev;
> > > int ret = 0;
> > >
> > > + /*
> > > + * If a consumer device is not on a bus (i.e. a driver will never bind
> > > + * to it), it doesn't make sense for fw_devlink to create device links
> > > + * for it.
> > > + */
> > > + if (con->bus == NULL)
> > > + return -EINVAL;
> > > +
> > > sup_dev = get_dev_from_fwnode(sup_handle);
> > > if (sup_dev) {
> > > + /*
> > > + * If a supplier device is not on a bus (i.e. a driver will
> > > + * never bind to it), it doesn't make sense for fw_devlink to
> > > + * create device links for it.
> > > + */
> > > + if (sup_dev->bus == NULL)
> > > + return -EINVAL;
> > > +
> > > /*
> > > * If it's one of those drivers that don't actually bind to
> > > * their device using driver core, then don't wait on this
> > > --
> > > 2.33.0.259.gc128427fd7-goog
> > >