Commit d6bb09ea authored by Nuno Sá's avatar Nuno Sá Committed by Jonathan Cameron
Browse files

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: default avatarNuno Sá <nuno.sa@analog.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220715122903.332535-5-nuno.sa@analog.com


Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent ed5e5ed4
Loading
Loading
Loading
Loading
+65 −47
Original line number Diff line number Diff line
@@ -211,13 +211,10 @@ static struct iio_channel *of_iio_channel_get(struct device_node *np, int index)
	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)
{
	struct iio_channel *chan;

	/* Walk up the tree of devices looking for a matching iio channel */
	while (np) {
	int index = 0;

	/*
@@ -227,8 +224,8 @@ struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
	 * will fail.
	 */
	if (name)
			index = of_property_match_string(np, "io-channel-names",
							 name);
		index = of_property_match_string(np, "io-channel-names", name);

	chan = of_iio_channel_get(np, index);
	if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER)
		return chan;
@@ -260,14 +257,35 @@ struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
		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.
	 * If the parent node has a "io-channel-ranges" property,
	 * then we can try one of its channels.
	 */
	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);

		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);