summaryrefslogtreecommitdiff
path: root/drivers/of
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-22 17:30:22 +0200
committerLeonard Crestez <leonard.crestez@nxp.com>2018-08-24 12:20:42 +0300
commit9787bebaa8249a62008b71ddb1592254f9593bfc (patch)
tree3ab4b079de55e50ae95dc81533f310ea148ff358 /drivers/of
parent0b8a6971ced6489ebda85c3b82c621a7c3900cec (diff)
of: Add helper for getting the maximum alias index for a stem
of_alias_max_index will return the maximum number for which an alias of a given stem exists. This is useful for frameworks whishing to reserve a number of device slots from dynamic allocation. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> (cherry picked from commit 5ce2ad39b36fd48b9f77249198655da7cbcc7ee5) Conflicts: include/linux/of.h
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 466b285cef3e..42073482ab64 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2049,6 +2049,35 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
ap->alias, ap->stem, ap->id, of_node_full_name(np));
}
+/*
+ * of_alias_max_index() - get the maximum index for a given alias stem
+ * @stem: The alias stem for which the maximum index is searched for
+ *
+ * Given an alias stem (the alias without the number) this function
+ * returns the maximum number for which an alias exists.
+ *
+ * Return: The maximum existing alias index or -ENODEV if no alias
+ * exists for this stem.
+ */
+int of_alias_max_index(const char *stem)
+{
+ struct alias_prop *app;
+ int max = -ENODEV;
+
+ mutex_lock(&of_mutex);
+
+ list_for_each_entry(app, &aliases_lookup, link) {
+ if (strcmp(app->stem, stem))
+ continue;
+ if (app->id > max)
+ max = app->id;
+ }
+
+ mutex_unlock(&of_mutex);
+
+ return max;
+}
+
/**
* of_alias_scan - Scan all properties of the 'aliases' node
*