From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Chen-Yu Tsai <wenst@chromium.org>, 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>,
Douglas Anderson <dianders@chromium.org>,
Johan Hovold <johan@kernel.org>, Jiri Kosina <jikos@kernel.org>,
<linux-i2c@vger.kernel.org>
Subject: Re: [PATCH v7 06/10] i2c: Introduce OF component probe function
Date: Mon, 16 Sep 2024 11:55:25 +0100 [thread overview]
Message-ID: <20240916115525.000078a3@Huawei.com> (raw)
In-Reply-To: <ZugKHrzs5BWoDr1c@smile.fi.intel.com>
On Mon, 16 Sep 2024 13:36:14 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> On Sun, Sep 15, 2024 at 12:44:13PM +0200, Chen-Yu Tsai wrote:
> > On Fri, Sep 13, 2024 at 12:25 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > > On Wed, Sep 11, 2024 at 03:27:44PM +0800, Chen-Yu Tsai wrote:
>
> ...
>
> > > > +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;
> > > > +
> > > > + ops = cfg->ops ?: &i2c_of_probe_dummy_ops;
> > > > + type = cfg->type;
> > > > +
> > > > + i2c_node = i2c_of_probe_get_i2c_node(dev, type);
> > >
> > >
> > > struct device_node *i2c_node __free(of_node_put) =
> > > i2c_...;
> >
> > cleanup.h says to not mix the two styles (scoped vs goto). I was trying
> > to follow that, though I realize now that with the scoped loops it
> > probably doesn't help.
The problem pattern is (IIUC)
if (x)
goto bob;
struct device_node *i2c_node __free(of_node_put) = i2c_....
bob:
return ret;
So a goto that jumps over registration of a cleanup function.
Jonathan
> >
> > I'll revert back to having __free().
> >
> > > > + if (IS_ERR(i2c_node))
> > > > + return PTR_ERR(i2c_node);
> > > > +
> > > > + for_each_child_of_node_with_prefix(i2c_node, node, type) {
> > > > + 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;
> > >
> > > Shouldn't you drop reference count for "node"? (See also below)
> >
> > This for-each loop the "scoped". It just doesn't have the prefix anymore.
> > I believe you asked if the prefix could be dropped and then Rob agreed.
>
> Hmm... I have looked into the implementation and I haven't found the evidence
> that this is anyhow scoped. Can you point out what I have missed?
>
> > > > + 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;
> > > > +
> > > > + ret = 0;
> > > > + for_each_child_of_node_with_prefix(i2c_node, node, type) {
> > > > + union i2c_smbus_data data;
> > > > + u32 addr;
> > > > +
> > > > + if (of_property_read_u32(node, "reg", &addr))
> > > > + continue;
> > > > + if (i2c_smbus_xfer(i2c, addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data) < 0)
> > > > + continue;
> > > > +
> > > > + /* Found a device that is responding */
> > > > + if (ops->free_resources_early)
> > > > + ops->free_resources_early(ctx);
> > > > + ret = i2c_of_probe_enable_node(dev, node);
> > >
> > > Hmm... Is "node" reference count left bumped up for a reason?
> >
> > Same as above.
>
> Same as above.
>
> > > > + break;
> > > > + }
> > > > +
> > > > + if (ops->cleanup)
> > > > + ops->cleanup(dev, ctx);
> > > > +out_release_resources:
> > > > + if (ops->free_resources_late)
> > > > + ops->free_resources_late(ctx);
> > > > +out_put_i2c_adapter:
> > > > + i2c_put_adapter(i2c);
> > > > +out_put_i2c_node:
> > > > + of_node_put(i2c_node);
> > > > +
> > > > + return ret;
> > > > +}
>
next prev parent reply other threads:[~2024-09-16 10:55 UTC|newest]
Thread overview: 40+ 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 [this message]
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
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 15:36 ` kernel test robot
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 14:24 ` kernel test robot
2024-09-13 15:36 ` kernel test robot
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=20240916115525.000078a3@Huawei.com \
--to=jonathan.cameron@huawei.com \
--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=dianders@chromium.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.