linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Doug Anderson <dianders@chromium.org>
To: Chen-Yu Tsai <wenst@chromium.org>
Cc: Rob Herring <robh@kernel.org>,
	Saravana Kannan <saravanak@google.com>,
	 Matthias Brugger <matthias.bgg@gmail.com>,
	 AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Wolfram Sang <wsa@kernel.org>,
	 Benson Leung <bleung@chromium.org>,
	Tzung-Bi Shih <tzungbi@kernel.org>,
	 Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	 chrome-platform@lists.linux.dev, devicetree@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	 linux-kernel@vger.kernel.org, Johan Hovold <johan@kernel.org>,
	 Jiri Kosina <jikos@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	 linux-i2c@vger.kernel.org
Subject: Re: [PATCH v7 06/10] i2c: Introduce OF component probe function
Date: Mon, 16 Sep 2024 07:15:45 -0700	[thread overview]
Message-ID: <CAD=FV=UDoaBN4OLZhEB4uvs6vDRVS0ZAsce2=3rJOn5sKEu-hw@mail.gmail.com> (raw)
In-Reply-To: <CAGXv+5FRoiv+TPyeFTcuRanRuSh2-xUo6ttVPkW6o3tktUmcFA@mail.gmail.com>

Hi,

On Sun, Sep 15, 2024 at 4:32 AM Chen-Yu Tsai <wenst@chromium.org> wrote:
>
> > > + * Assumes that across the entire device tree the only instances of nodes
> > > + * prefixed with "type" are the ones that need handling for second source
> > > + * components. In other words, if "type" is "touchscreen", then all device
> > > + * nodes named "touchscreen*" are the ones that need probing. There cannot
> >
> > "touchscreen*" implies that it can have an arbitrary suffix. Can it?
>
> That is the idea. The use case is for components that have conflicting
> addresses and need special probing. Such device nodes obviously can't
> have the same node name. This is planned but not implemented in this
> series.

Maybe "touchscreen@*" instead of "touchscreen*" if I'm understanding correctly.


> > > + * be another "touchscreen" node that is already enabled.
> > > + *
> > > + * Assumes that for each "type" of component, only one actually exists. In
> > > + * other words, only one matching and existing device will be enabled.
> > > + *
> > > + * Context: Process context only. Does non-atomic I2C transfers.
> > > + *          Should only be used from a driver probe function, as the function
> > > + *          can return -EPROBE_DEFER if the I2C adapter or other resources
> > > + *          are unavailable.
> > > + * Return: 0 on success or no-op, error code otherwise.
> > > + *         A no-op can happen when it seems like the device tree already
> > > + *         has components of the type to be probed already enabled. This
> > > + *         can happen when the device tree had not been updated to mark
> > > + *         the status of the to-be-probed components as "fail". Or this
> > > + *         function was already run with the same parameters and succeeded
> > > + *         in enabling a component. The latter could happen if the user
> >
> > s/latter/later
>
> Are you sure?

No. latter looked weird to me and I searched quickly and thought I was
right. With a more full search looks like you're right.


> > > +int i2c_of_probe_component(struct device *dev, const struct i2c_of_probe_cfg *cfg, void *ctx)
> > > +{
> > > +       const struct i2c_of_probe_ops *ops;
> > > +       const char *type;
> > > +       struct device_node *i2c_node;
> > > +       struct i2c_adapter *i2c;
> > > +       int ret;
> > > +
> > > +       if (!cfg)
> > > +               return -EINVAL;
> >
> > Drop extra check of "!cfg". In general kernel conventions don't check
> > for NULL pointers passed by caller unless it's an expected case. You
> > don't check for a NULL "dev" and you shouldn't need to check for a
> > NULL "cfg". They are both simply required parameters.
>
> "dev" is only passed to dev_printk(), and that can handle "dev" being
> NULL. Same can't be said for "cfg".
>
> I don't know what the preference is though. Crashing is probably not the
> nicest thing, even if it only happens to developers.

Honestly as a developer I'd prefer the crash. It points out the exact
line where I had an invalid NULL. Returning an error code means I've
got to compile/boot several more times to track down where the error
code is coming from.

I'm fairly certain that the kernel convention is to only check things
for NULL if it's part of the API to accept NULL or if the value can be
NULL due to untrusted data. If the only way it can be NULL is due to
buggy code elsewhere in the kernel then you should omit the error
checks.

> > > +               if (!of_device_is_available(node))
> > > +                       continue;
> > > +
> > > +               /*
> > > +                * Device tree has component already enabled. Either the
> > > +                * device tree isn't supported or we already probed once.
> > > +                */
> > > +               ret = 0;
> > > +               goto out_put_i2c_node;
> > > +       }
> > > +
> > > +       i2c = of_get_i2c_adapter_by_node(i2c_node);
> > > +       if (!i2c) {
> > > +               ret = dev_err_probe(dev, -EPROBE_DEFER, "Couldn't get I2C adapter\n");
> > > +               goto out_put_i2c_node;
> > > +       }
> > > +
> > > +       /* Grab resources */
> > > +       ret = 0;
> > > +       if (ops->get_resources)
> > > +               ret = ops->get_resources(dev, i2c_node, ctx);
> > > +       if (ret)
> > > +               goto out_put_i2c_adapter;
> > > +
> > > +       /* Enable resources */
> > > +       if (ops->enable)
> > > +               ret = ops->enable(dev, ctx);
> > > +       if (ret)
> > > +               goto out_release_resources;
> >
> > I won't insist, but a part of me wonders whether we should just
> > combine "get_resources" and "enable" and then combine "cleanup" and
> > "free_resources_late". They are always paired one after another and
> > I'm having a hard time seeing why they need to be separate. It's not
> > like you'll ever get the resources and then enable/disable multiple
> > times.
>
> Maybe. The structure was carried over from the original non-callback
> version. I think it's easier to reason about if they are kept separate,
> especially since the outgoing path is slightly different when no working
> component is found and one of the callbacks ends up not getting called.

Actually, both of the outgoing callbacks are always called. It's only
the 3rd callback (the "early" one) that's called sometimes.

I won't insist on combining them, but I still feel like combining them
would be better. I'd be interested in other opinions, though.


-Doug

  reply	other threads:[~2024-09-16 14:16 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-11  7:27 [PATCH v7 00/10] platform/chrome: Introduce DT hardware prober Chen-Yu Tsai
2024-09-11  7:27 ` [PATCH v7 01/10] of: dynamic: Add of_changeset_update_prop_string Chen-Yu Tsai
2024-09-11  7:27 ` [PATCH v7 02/10] of: base: Add for_each_child_of_node_with_prefix() Chen-Yu Tsai
2024-09-12 20:31   ` Rob Herring (Arm)
2024-09-11  7:27 ` [PATCH v7 03/10] regulator: Split up _regulator_get() Chen-Yu Tsai
2024-09-13 10:27   ` Andy Shevchenko
2024-09-11  7:27 ` [PATCH v7 04/10] regulator: Add of_regulator_get_optional() for pure DT regulator lookup Chen-Yu Tsai
2024-09-11  7:27 ` [PATCH v7 05/10] i2c: core: Remove extra space in Makefile Chen-Yu Tsai
2024-09-13 14:59   ` Andi Shyti
2024-09-11  7:27 ` [PATCH v7 06/10] i2c: Introduce OF component probe function Chen-Yu Tsai
2024-09-13 10:25   ` Andy Shevchenko
2024-09-15 10:44     ` Chen-Yu Tsai
2024-09-16 10:36       ` Andy Shevchenko
2024-09-16 10:55         ` Jonathan Cameron
2024-09-16 14:59         ` Chen-Yu Tsai
2024-09-16 15:22           ` Andy Shevchenko
2024-09-13 23:43   ` Doug Anderson
2024-09-15 11:32     ` Chen-Yu Tsai
2024-09-16 14:15       ` Doug Anderson [this message]
2024-09-16 14:31         ` Chen-Yu Tsai
2024-09-16 10:13     ` Andy Shevchenko
2024-09-15 10:09   ` Andrey Skvortsov
2024-09-11  7:27 ` [PATCH v7 07/10] i2c: of-prober: Add simple helpers for regulator support Chen-Yu Tsai
2024-09-13 10:46   ` Andy Shevchenko
2024-09-13 23:43   ` Doug Anderson
2024-09-11  7:27 ` [PATCH v7 08/10] i2c: of-prober: Add GPIO support to simple helpers Chen-Yu Tsai
2024-09-13 10:52   ` Andy Shevchenko
2024-09-13 23:43   ` Doug Anderson
2024-09-17 12:41     ` Chen-Yu Tsai
2024-09-23 19:11       ` Doug Anderson
2024-09-15  9:46   ` Andrey Skvortsov
2024-09-11  7:27 ` [PATCH v7 09/10] platform/chrome: Introduce device tree hardware prober Chen-Yu Tsai
2024-09-13 23:43   ` Doug Anderson
2024-09-16 14:58     ` Chen-Yu Tsai
2024-09-16 15:23       ` Andy Shevchenko
2024-09-11  7:27 ` [PATCH v7 10/10] arm64: dts: mediatek: mt8173-elm-hana: Mark touchscreens and trackpads as fail Chen-Yu Tsai
2024-09-13 18:08 ` (subset) [PATCH v7 00/10] platform/chrome: Introduce DT hardware prober Mark Brown

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='CAD=FV=UDoaBN4OLZhEB4uvs6vDRVS0ZAsce2=3rJOn5sKEu-hw@mail.gmail.com' \
    --to=dianders@chromium.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bleung@chromium.org \
    --cc=broonie@kernel.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=devicetree@vger.kernel.org \
    --cc=jikos@kernel.org \
    --cc=johan@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=robh@kernel.org \
    --cc=saravanak@google.com \
    --cc=tzungbi@kernel.org \
    --cc=wenst@chromium.org \
    --cc=wsa@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;
as well as URLs for NNTP newsgroup(s).