[PATCH 23/34] iio: inkern: split of_iio_channel_get_by_name()
Nuno Sá
nuno.sa at analog.com
Fri Jun 10 18:45:34 AEST 2022
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: Nuno Sá <nuno.sa at analog.com>
---
drivers/iio/inkern.c | 69 ++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 25 deletions(-)
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 31d9c122199a..dde47324b826 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -211,44 +211,63 @@ 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,
+ const char *name,
+ bool *parent_lookup)
+{
+ struct iio_channel *chan;
+ int index = 0;
+
+ /*
+ * For named iio channels, first look up the name in the
+ * "io-channel-names" property. If it cannot be found, the
+ * index will be an error code, and of_iio_channel_get()
+ * will fail.
+ */
+ if (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) {
+ *parent_lookup = false;
+ } else if (name && index >= 0) {
+ pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n",
+ np, name ? name : "", index);
+ *parent_lookup = false;
+ }
+
+ return chan;
+}
+
struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
const char *name)
{
struct iio_channel *chan;
+ bool parent_lookup = true;
/* Walk up the tree of devices looking for a matching iio channel */
+ chan = __of_iio_channel_get_by_name(np, name, &parent_lookup);
+ if (!parent_lookup)
+ 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;
while (np) {
- int index = 0;
-
- /*
- * For named iio channels, first look up the name in the
- * "io-channel-names" property. If it cannot be found, the
- * index will be an error code, and of_iio_channel_get()
- * will fail.
- */
- if (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)
+ if (!of_get_property(np, "io-channel-ranges", NULL))
return chan;
- if (name && index >= 0) {
- pr_err("ERROR: could not get IIO channel %pOF:%s(%i)\n",
- np, name ? name : "", index);
+
+ chan = __of_iio_channel_get_by_name(np, name, &parent_lookup);
+ if (!parent_lookup)
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))
- return chan;
}
- return ERR_PTR(-ENODEV);
+ return chan;
}
EXPORT_SYMBOL_GPL(of_iio_channel_get_by_name);
--
2.36.1
More information about the openbmc
mailing list