summaryrefslogtreecommitdiff
path: root/drivers/of
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-22 17:30:22 +0200
committerNitin Garg <nitin.garg@nxp.com>2016-01-14 11:01:45 -0600
commitf5a95f6da77f624f714f1d2d56fe1c5768c52709 (patch)
treeb178edfef8a3a25983f0c63b70057d5275f07750 /drivers/of
parent2a67a39a84183d33c5a9b9d01a16889c17f43833 (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 5ed97246c2e7..169bbafd1ace 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1884,6 +1884,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
*