提交 d6bb09ea 编写于 作者: N Nuno Sá 提交者: Jonathan Cameron

iio: inkern: split of_iio_channel_get_by_name()

This change splits of_iio_channel_get_by_name() so that it decouples
looking for channels in the current node from looking in it's parents
nodes. This will be helpful when moving to fwnode properties where we
need to release the handles when looking for channels in parent's nodes.

No functional change intended...
Signed-off-by: NNuno Sá <nuno.sa@analog.com>
Reviewed-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220715122903.332535-5-nuno.sa@analog.comSigned-off-by: NJonathan Cameron <Jonathan.Cameron@huawei.com>
上级 ed5e5ed4
...@@ -211,13 +211,10 @@ static struct iio_channel *of_iio_channel_get(struct device_node *np, int index) ...@@ -211,13 +211,10 @@ static struct iio_channel *of_iio_channel_get(struct device_node *np, int index)
return ERR_PTR(err); return ERR_PTR(err);
} }
struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, static struct iio_channel *__of_iio_channel_get_by_name(struct device_node *np,
const char *name) const char *name)
{ {
struct iio_channel *chan; struct iio_channel *chan;
/* Walk up the tree of devices looking for a matching iio channel */
while (np) {
int index = 0; int index = 0;
/* /*
...@@ -227,8 +224,8 @@ struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, ...@@ -227,8 +224,8 @@ struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
* will fail. * will fail.
*/ */
if (name) if (name)
index = of_property_match_string(np, "io-channel-names", index = of_property_match_string(np, "io-channel-names", name);
name);
chan = of_iio_channel_get(np, index); chan = of_iio_channel_get(np, index);
if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER)
return chan; return chan;
...@@ -260,14 +257,35 @@ struct iio_channel *of_iio_channel_get_by_name(struct device_node *np, ...@@ -260,14 +257,35 @@ struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
return chan; return chan;
} }
/* so we continue the lookup */
return ERR_PTR(-ENODEV);
}
struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
const char *name)
{
struct iio_channel *chan;
/* Walk up the tree of devices looking for a matching iio channel */
chan = __of_iio_channel_get_by_name(np, name);
if (!IS_ERR(chan) || PTR_ERR(chan) != -ENODEV)
return chan;
/* /*
* No matching IIO channel found on this node. * No matching IIO channel found on this node.
* If the parent node has a "io-channel-ranges" property, * If the parent node has a "io-channel-ranges" property,
* then we can try one of its channels. * then we can try one of its channels.
*/ */
np = np->parent; np = np->parent;
if (np && !of_get_property(np, "io-channel-ranges", NULL)) while (np) {
if (!of_get_property(np, "io-channel-ranges", NULL))
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
chan = __of_iio_channel_get_by_name(np, name);
if (!IS_ERR(chan) || PTR_ERR(chan) != -ENODEV)
return chan;
np = np->parent;
} }
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册